blob: 923f32975484ff3abb54c8ff12edf0e2cccb1478 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 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>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060038#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060039#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070040
41#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060042#include <limits.h>
43#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
49//--------------------------------------------------------------------------------------
50// Mesh and VertexFormat Data
51//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070052struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070053 float posX, posY, posZ, posW; // Position data
54 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055};
56
Karl Schultz6addd812016-02-02 17:17:23 -070057#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058
59typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070060 BsoFailNone = 0x00000000,
61 BsoFailLineWidth = 0x00000001,
62 BsoFailDepthBias = 0x00000002,
63 BsoFailViewport = 0x00000004,
64 BsoFailScissor = 0x00000008,
65 BsoFailBlend = 0x00000010,
66 BsoFailDepthBounds = 0x00000020,
67 BsoFailStencilReadMask = 0x00000040,
68 BsoFailStencilWriteMask = 0x00000080,
69 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060070 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060071 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072} BsoFailSelect;
73
74struct vktriangle_vs_uniform {
75 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070076 float mvp[4][4];
77 float position[3][4];
78 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050079};
80
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081static const char bindStateVertShaderText[] =
82 "#version 450\n"
83 "vec2 vertices[3];\n"
84 "out gl_PerVertex {\n"
85 " vec4 gl_Position;\n"
86 "};\n"
87 "void main() {\n"
88 " vertices[0] = vec2(-1.0, -1.0);\n"
89 " vertices[1] = vec2( 1.0, -1.0);\n"
90 " vertices[2] = vec2( 0.0, 1.0);\n"
91 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
92 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static const char bindStateFragShaderText[] =
95 "#version 450\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
103 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
104 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600106// ErrorMonitor Usage:
107//
Dave Houltonfbf52152017-01-06 12:55:29 -0700108// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600109// encountered log messages, or a validation error enum identifying
110// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
111// will match all log messages. logMsg will return true for skipCall
112// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call VerifyFound to determine if all desired failure messages
115// were encountered. Call VerifyNotFound to determine if any unexpected
116// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700119 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700120 test_platform_thread_create_mutex(&mutex_);
121 test_platform_thread_lock_mutex(&mutex_);
122 Reset();
123 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600124 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600125
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600127
Dave Houltonfbf52152017-01-06 12:55:29 -0700128 // Set monitor to pristine state
129 void Reset() {
130 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
131 bailout_ = NULL;
132 message_found_ = VK_FALSE;
133 failure_message_strings_.clear();
134 desired_message_strings_.clear();
135 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700136 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700137 other_messages_.clear();
138 message_outstanding_count_ = 0;
139 }
140
141 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700142 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700143 test_platform_thread_lock_mutex(&mutex_);
144 desired_message_strings_.insert(msgString);
145 message_flags_ |= msgFlags;
146 message_outstanding_count_++;
147 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700150 // ErrorMonitor will look for an error message containing the specified string(s)
151 template <typename Iter>
152 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
153 for (; iter != end; ++iter) {
154 SetDesiredFailureMsg(msgFlags, *iter);
155 }
156 }
157
Dave Houltonfbf52152017-01-06 12:55:29 -0700158 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700159 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700160 test_platform_thread_lock_mutex(&mutex_);
161 desired_message_ids_.insert(msg_id);
162 message_flags_ |= msgFlags;
163 message_outstanding_count_++;
164 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600165 }
166
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700167 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
168 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
169 // function and its definition.
170 void SetUnexpectedError(const char *const msg) {
171 test_platform_thread_lock_mutex(&mutex_);
172
173 ignore_message_strings_.emplace_back(msg);
174
175 test_platform_thread_unlock_mutex(&mutex_);
176 }
177
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700178 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600179 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 test_platform_thread_lock_mutex(&mutex_);
181 if (bailout_ != NULL) {
182 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600183 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700187 if (!IgnoreMessage(errorString)) {
188 for (auto desired_msg : desired_message_strings_) {
189 if (desired_msg.length() == 0) {
190 // An empty desired_msg string "" indicates a positive test - not expecting an error.
191 // Return true to avoid calling layers/driver with this error.
192 // And don't erase the "" string, so it remains if another error is found.
193 result = VK_TRUE;
194 found_expected = true;
195 message_found_ = VK_TRUE;
196 failure_message_strings_.insert(errorString);
197 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600198 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700199 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700200 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700202 result = VK_TRUE;
203 // We only want one match for each expected error so remove from set here
204 // Since we're about the break the loop it's ok to remove from set we're iterating over
205 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 }
208 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700209 for (auto desired_id : desired_message_ids_) {
210 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
211 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
212 // Return true to avoid calling layers/driver with this error.
213 result = VK_TRUE;
214 } else if (desired_id == message_code) {
215 // Double-check that the string matches the error enum
216 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
217 found_expected = true;
218 message_outstanding_count_--;
219 result = VK_TRUE;
220 message_found_ = VK_TRUE;
221 desired_message_ids_.erase(desired_id);
222 break;
223 } else {
224 // Treat this message as a regular unexpected error, but print a warning jic
225 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
226 errorString.c_str(), desired_id, validation_error_map[desired_id]);
227 }
228 }
229 }
230
231 if (!found_expected) {
232 printf("Unexpected: %s\n", msgString);
233 other_messages_.push_back(errorString);
234 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600235 }
236
Dave Houltonfbf52152017-01-06 12:55:29 -0700237 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600238 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700241 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600242
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700243 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700245 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600246
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700247 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700248
249 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600250
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700251 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600252 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600253 if (otherMsgs.size()) {
254 cout << "Other error messages logged for this test were:" << endl;
255 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
256 cout << " " << *iter << endl;
257 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600258 }
259 }
260
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600263 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700264 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600265 // Match ANY message matching specified type
266 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 }
269
270 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700275 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700278 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600279 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700281 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
283
284 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600285 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700286 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200287 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700289 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600290 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200291 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600358
359 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600360 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600361 std::vector<const char *> instance_extension_names;
362 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600363
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700364 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600365 /*
366 * Since CreateDbgMsgCallback is an instance level extension call
367 * any extension / layer that utilizes that feature also needs
368 * to be enabled at create instance time.
369 */
Karl Schultz6addd812016-02-02 17:17:23 -0700370 // Use Threading layer first to protect others from
371 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700372 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600373 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800374 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700375 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800376 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600377 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700378 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600379
Ian Elliott2c1daf52016-05-12 09:41:46 -0600380 if (m_enableWSI) {
381 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
382 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
383#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
384#if defined(VK_USE_PLATFORM_ANDROID_KHR)
385 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700386#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600387#if defined(VK_USE_PLATFORM_MIR_KHR)
388 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700389#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600390#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
391 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700392#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600393#if defined(VK_USE_PLATFORM_WIN32_KHR)
394 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700395#endif // VK_USE_PLATFORM_WIN32_KHR
396#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600397#if defined(VK_USE_PLATFORM_XCB_KHR)
398 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
399#elif defined(VK_USE_PLATFORM_XLIB_KHR)
400 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700401#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600402 }
403
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600404 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600405 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 this->app_info.pApplicationName = "layer_tests";
407 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600408 this->app_info.pEngineName = "unittest";
409 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600410 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600411
Tony Barbour15524c32015-04-29 17:34:29 -0600412 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600413 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600414 }
415
416 virtual void TearDown() {
417 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600418 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600419 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600420 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600421
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600422 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600423};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500424
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600425void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500426 // Create identity matrix
427 int i;
428 struct vktriangle_vs_uniform data;
429
430 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700431 glm::mat4 View = glm::mat4(1.0f);
432 glm::mat4 Model = glm::mat4(1.0f);
433 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500434 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700435 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500436
437 memcpy(&data.mvp, &MVP[0][0], matrixSize);
438
Karl Schultz6addd812016-02-02 17:17:23 -0700439 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600440 {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 -0500441 };
442
Karl Schultz6addd812016-02-02 17:17:23 -0700443 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444 data.position[i][0] = tri_data[i].posX;
445 data.position[i][1] = tri_data[i].posY;
446 data.position[i][2] = tri_data[i].posZ;
447 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700448 data.color[i][0] = tri_data[i].r;
449 data.color[i][1] = tri_data[i].g;
450 data.color[i][2] = tri_data[i].b;
451 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500452 }
453
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500454 ASSERT_NO_FATAL_FAILURE(InitViewport());
455
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200456 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
457 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500458
Karl Schultz6addd812016-02-02 17:17:23 -0700459 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600460 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500461
462 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800463 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464 pipelineobj.AddShader(&vs);
465 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600466 if (failMask & BsoFailLineWidth) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600469 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600470 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
471 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 }
473 if (failMask & BsoFailDepthBias) {
474 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600475 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600476 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600477 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600478 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600479 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600480 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700481 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700482 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600483 if (failMask & BsoFailViewport) {
484 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
485 }
486 if (failMask & BsoFailScissor) {
487 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
488 }
489 if (failMask & BsoFailBlend) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600491 VkPipelineColorBlendAttachmentState att_state = {};
492 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
493 att_state.blendEnable = VK_TRUE;
494 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600495 }
496 if (failMask & BsoFailDepthBounds) {
497 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
498 }
499 if (failMask & BsoFailStencilReadMask) {
500 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
501 }
502 if (failMask & BsoFailStencilWriteMask) {
503 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
504 }
505 if (failMask & BsoFailStencilReference) {
506 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
507 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508
509 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600510 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511
512 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700513 m_commandBuffer->BeginCommandBuffer();
514 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500515
Tony Barbourfe3351b2015-07-28 10:17:20 -0600516 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500517
518 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600519 if (failMask & BsoFailIndexBuffer) {
520 // Use DrawIndexed w/o an index buffer bound
521 DrawIndexed(3, 1, 0, 0, 0);
522 } else {
523 Draw(3, 1, 0, 0);
524 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Mark Muellerd4914412016-06-13 17:52:06 -0600526 if (failMask & BsoFailCmdClearAttachments) {
527 VkClearAttachment color_attachment = {};
528 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700529 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600530 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
531
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600533 }
534
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700536 m_commandBuffer->EndRenderPass();
537 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600538 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500539}
540
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600541void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
542 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500543 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600544 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500545 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600546 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500547 }
548
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800549 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700550 // Make sure depthWriteEnable is set so that Depth fail test will work
551 // correctly
552 // Make sure stencilTestEnable is set so that Stencil fail test will work
553 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600554 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800555 stencil.failOp = VK_STENCIL_OP_KEEP;
556 stencil.passOp = VK_STENCIL_OP_KEEP;
557 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
558 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600559
560 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
561 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600562 ds_ci.pNext = NULL;
563 ds_ci.depthTestEnable = VK_FALSE;
564 ds_ci.depthWriteEnable = VK_TRUE;
565 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
566 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600567 if (failMask & BsoFailDepthBounds) {
568 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600569 ds_ci.maxDepthBounds = 0.0f;
570 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600571 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600572 ds_ci.stencilTestEnable = VK_TRUE;
573 ds_ci.front = stencil;
574 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600575
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600576 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600577 pipelineobj.SetViewport(m_viewports);
578 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800579 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600580 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600581 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800582 commandBuffer->BindPipeline(pipelineobj);
583 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500584}
585
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600586class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700587 public:
588 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600589};
590
Ian Elliott2c1daf52016-05-12 09:41:46 -0600591class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700592 public:
593 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600594 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600595};
596
Mark Muellerdfe37552016-07-07 14:47:42 -0600597class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700598 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600599 enum eTestEnFlags {
600 eDoubleDelete,
601 eInvalidDeviceOffset,
602 eInvalidMemoryOffset,
603 eBindNullBuffer,
604 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600605 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600606 };
607
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600608 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
611 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600612 return true;
613 }
614 VkDeviceSize offset_limit = 0;
615 if (eInvalidMemoryOffset == aTestFlag) {
616 VkBuffer vulkanBuffer;
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(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600623 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600624
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600625 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600626 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
627 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600628 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
629 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600630 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600632 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600634 }
635 if (eOffsetAlignment < offset_limit) {
636 return true;
637 }
638 return false;
639 }
640
641 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
643 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600644 if (eBindNullBuffer == aTestFlag) {
645 VulkanMemory = 0;
646 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
647 } else {
648 VkBufferCreateInfo buffer_create_info = {};
649 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
650 buffer_create_info.size = 32;
651 buffer_create_info.usage = aBufferUsage;
652
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600653 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654
655 CreateCurrent = true;
656
657 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600658 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600659
660 VkMemoryAllocateInfo memory_allocate_info = {};
661 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
662 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600663 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
664 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600665 if (!pass) {
666 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
667 return;
668 }
669
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600670 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600671 AllocateCurrent = true;
672 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600673 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
674 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600675 BoundCurrent = true;
676
677 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
678 }
679 }
680
681 ~VkBufferTest() {
682 if (CreateCurrent) {
683 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
684 }
685 if (AllocateCurrent) {
686 if (InvalidDeleteEn) {
687 union {
688 VkDeviceMemory device_memory;
689 unsigned long long index_access;
690 } bad_index;
691
692 bad_index.device_memory = VulkanMemory;
693 bad_index.index_access++;
694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600696 }
697 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
698 }
699 }
700
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600701 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600702
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600703 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600704
705 void TestDoubleDestroy() {
706 // Destroy the buffer but leave the flag set, which will cause
707 // the buffer to be destroyed again in the destructor.
708 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
709 }
710
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700711 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600712 bool AllocateCurrent;
713 bool BoundCurrent;
714 bool CreateCurrent;
715 bool InvalidDeleteEn;
716
717 VkBuffer VulkanBuffer;
718 VkDevice VulkanDevice;
719 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600720};
721
722class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700723 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600725 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700726 : BoundCurrent(false),
727 AttributeCount(aAttributeCount),
728 BindingCount(aBindingCount),
729 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600730 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600731 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
732 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700733 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600734
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600735 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
736 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600737
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600738 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
739 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
740 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
741 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
742 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600743
744 unsigned i = 0;
745 do {
746 VertexInputAttributeDescription[i].binding = BindId;
747 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600748 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
749 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600750 i++;
751 } while (AttributeCount < i);
752
753 i = 0;
754 do {
755 VertexInputBindingDescription[i].binding = BindId;
756 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600757 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600758 i++;
759 } while (BindingCount < i);
760 }
761
762 ~VkVerticesObj() {
763 if (VertexInputAttributeDescription) {
764 delete[] VertexInputAttributeDescription;
765 }
766 if (VertexInputBindingDescription) {
767 delete[] VertexInputBindingDescription;
768 }
769 }
770
771 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600772 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
773 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600774 return true;
775 }
776
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600777 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600778 VkDeviceSize *offsetList;
779 unsigned offsetCount;
780
781 if (aOffsetCount) {
782 offsetList = aOffsetList;
783 offsetCount = aOffsetCount;
784 } else {
785 offsetList = new VkDeviceSize[1]();
786 offsetCount = 1;
787 }
788
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600789 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600790 BoundCurrent = true;
791
792 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600793 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600794 }
795 }
796
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700797 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600798 static uint32_t BindIdGenerator;
799
800 bool BoundCurrent;
801 unsigned AttributeCount;
802 unsigned BindingCount;
803 uint32_t BindId;
804
805 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
806 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
807 VkVertexInputBindingDescription *VertexInputBindingDescription;
808 VkConstantBufferObj VulkanMemoryBuffer;
809};
810
811uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500812// ********************************************************************************************************************
813// ********************************************************************************************************************
814// ********************************************************************************************************************
815// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600816TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700817 TEST_DESCRIPTION(
818 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
819 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600820
821 ASSERT_NO_FATAL_FAILURE(InitState());
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify NULL for a pointer to a handle
825 // Expected to trigger an error with
826 // parameter_validation::validate_required_pointer
827 vkGetPhysicalDeviceFeatures(gpu(), NULL);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
831 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600832 // Specify NULL for pointer to array count
833 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600834 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600835 m_errorMonitor->VerifyFound();
836
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600838 // Specify 0 for a required array count
839 // Expected to trigger an error with parameter_validation::validate_array
840 VkViewport view_port = {};
841 m_commandBuffer->SetViewport(0, 0, &view_port);
842 m_errorMonitor->VerifyFound();
843
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify NULL for a required array
846 // Expected to trigger an error with parameter_validation::validate_array
847 m_commandBuffer->SetViewport(0, 1, NULL);
848 m_errorMonitor->VerifyFound();
849
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600851 // Specify VK_NULL_HANDLE for a required handle
852 // Expected to trigger an error with
853 // parameter_validation::validate_required_handle
854 vkUnmapMemory(device(), VK_NULL_HANDLE);
855 m_errorMonitor->VerifyFound();
856
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
858 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600859 // Specify VK_NULL_HANDLE for a required handle array entry
860 // Expected to trigger an error with
861 // parameter_validation::validate_required_handle_array
862 VkFence fence = VK_NULL_HANDLE;
863 vkResetFences(device(), 1, &fence);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600867 // Specify NULL for a required struct pointer
868 // Expected to trigger an error with
869 // parameter_validation::validate_struct_type
870 VkDeviceMemory memory = VK_NULL_HANDLE;
871 vkAllocateMemory(device(), NULL, NULL, &memory);
872 m_errorMonitor->VerifyFound();
873
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600875 // Specify 0 for a required VkFlags parameter
876 // Expected to trigger an error with parameter_validation::validate_flags
877 m_commandBuffer->SetStencilReference(0, 0);
878 m_errorMonitor->VerifyFound();
879
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600880 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 -0600881 // Specify 0 for a required VkFlags array entry
882 // Expected to trigger an error with
883 // parameter_validation::validate_flags_array
884 VkSemaphore semaphore = VK_NULL_HANDLE;
885 VkPipelineStageFlags stageFlags = 0;
886 VkSubmitInfo submitInfo = {};
887 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
888 submitInfo.waitSemaphoreCount = 1;
889 submitInfo.pWaitSemaphores = &semaphore;
890 submitInfo.pWaitDstStageMask = &stageFlags;
891 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
892 m_errorMonitor->VerifyFound();
893}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600894
Dustin Gravesfce74c02016-05-10 11:42:58 -0600895TEST_F(VkLayerTest, ReservedParameter) {
896 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
897
898 ASSERT_NO_FATAL_FAILURE(InitState());
899
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600901 // Specify 0 for a reserved VkFlags parameter
902 // Expected to trigger an error with
903 // parameter_validation::validate_reserved_flags
904 VkEvent event_handle = VK_NULL_HANDLE;
905 VkEventCreateInfo event_info = {};
906 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
907 event_info.flags = 1;
908 vkCreateEvent(device(), &event_info, NULL, &event_handle);
909 m_errorMonitor->VerifyFound();
910}
911
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600912TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700913 TEST_DESCRIPTION(
914 "Specify an invalid VkStructureType for a Vulkan "
915 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600916
917 ASSERT_NO_FATAL_FAILURE(InitState());
918
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600920 // Zero struct memory, effectively setting sType to
921 // VK_STRUCTURE_TYPE_APPLICATION_INFO
922 // Expected to trigger an error with
923 // parameter_validation::validate_struct_type
924 VkMemoryAllocateInfo alloc_info = {};
925 VkDeviceMemory memory = VK_NULL_HANDLE;
926 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
927 m_errorMonitor->VerifyFound();
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600930 // Zero struct memory, effectively setting sType to
931 // VK_STRUCTURE_TYPE_APPLICATION_INFO
932 // Expected to trigger an error with
933 // parameter_validation::validate_struct_type_array
934 VkSubmitInfo submit_info = {};
935 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
936 m_errorMonitor->VerifyFound();
937}
938
939TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600940 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600941
942 ASSERT_NO_FATAL_FAILURE(InitState());
943
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600945 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600946 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600948 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600949 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600950 // Zero-initialization will provide the correct sType
951 VkApplicationInfo app_info = {};
952 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
953 event_alloc_info.pNext = &app_info;
954 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
955 m_errorMonitor->VerifyFound();
956
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
958 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600959 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
960 // a function that has allowed pNext structure types and specify
961 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600962 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600963 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600964 VkMemoryAllocateInfo memory_alloc_info = {};
965 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
966 memory_alloc_info.pNext = &app_info;
967 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600969}
Dustin Graves5d33d532016-05-09 16:21:12 -0600970
971TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600972 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600973
974 ASSERT_NO_FATAL_FAILURE(InitState());
975
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
977 "does not fall within the begin..end "
978 "range of the core VkFormat "
979 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 // Specify an invalid VkFormat value
981 // Expected to trigger an error with
982 // parameter_validation::validate_ranged_enum
983 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 m_errorMonitor->VerifyFound();
986
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600987 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 -0600988 // Specify an invalid VkFlags bitmask value
989 // Expected to trigger an error with parameter_validation::validate_flags
990 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600991 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
992 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600993 m_errorMonitor->VerifyFound();
994
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600995 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 -0600996 // Specify an invalid VkFlags array entry
997 // Expected to trigger an error with
998 // parameter_validation::validate_flags_array
999 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001000 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001001 VkSubmitInfo submit_info = {};
1002 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1003 submit_info.waitSemaphoreCount = 1;
1004 submit_info.pWaitSemaphores = &semaphore;
1005 submit_info.pWaitDstStageMask = &stage_flags;
1006 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1007 m_errorMonitor->VerifyFound();
1008
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001010 // Specify an invalid VkBool32 value
1011 // Expected to trigger a warning with
1012 // parameter_validation::validate_bool32
1013 VkSampler sampler = VK_NULL_HANDLE;
1014 VkSamplerCreateInfo sampler_info = {};
1015 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1016 sampler_info.pNext = NULL;
1017 sampler_info.magFilter = VK_FILTER_NEAREST;
1018 sampler_info.minFilter = VK_FILTER_NEAREST;
1019 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1020 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1023 sampler_info.mipLodBias = 1.0;
1024 sampler_info.maxAnisotropy = 1;
1025 sampler_info.compareEnable = VK_FALSE;
1026 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1027 sampler_info.minLod = 1.0;
1028 sampler_info.maxLod = 1.0;
1029 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1030 sampler_info.unnormalizedCoordinates = VK_FALSE;
1031 // Not VK_TRUE or VK_FALSE
1032 sampler_info.anisotropyEnable = 3;
1033 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1034 m_errorMonitor->VerifyFound();
1035}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001036
1037TEST_F(VkLayerTest, FailedReturnValue) {
1038 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1039
1040 ASSERT_NO_FATAL_FAILURE(InitState());
1041
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001042 // Find an unsupported image format
1043 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1044 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1045 VkFormat format = static_cast<VkFormat>(f);
1046 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001047 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001048 unsupported = format;
1049 break;
1050 }
1051 }
1052
1053 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1055 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001056 // Specify an unsupported VkFormat value to generate a
1057 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1058 // Expected to trigger a warning from
1059 // parameter_validation::validate_result
1060 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001061 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1062 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001063 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1064 m_errorMonitor->VerifyFound();
1065 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001066}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001067
1068TEST_F(VkLayerTest, UpdateBufferAlignment) {
1069 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001070 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001071
1072 ASSERT_NO_FATAL_FAILURE(InitState());
1073
1074 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1075 vk_testing::Buffer buffer;
1076 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1077
Tony Barbour552f6c02016-12-21 14:34:07 -07001078 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001081 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1082 m_errorMonitor->VerifyFound();
1083
1084 // Introduce failure by using dataSize 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->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1087 m_errorMonitor->VerifyFound();
1088
1089 // Introduce failure by using dataSize that is < 0
1090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001091 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001092 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1093 m_errorMonitor->VerifyFound();
1094
1095 // Introduce failure by using dataSize that is > 65536
1096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001097 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001098 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1099 m_errorMonitor->VerifyFound();
1100
Tony Barbour552f6c02016-12-21 14:34:07 -07001101 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001102}
1103
1104TEST_F(VkLayerTest, FillBufferAlignment) {
1105 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1106
1107 ASSERT_NO_FATAL_FAILURE(InitState());
1108
1109 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1110 vk_testing::Buffer buffer;
1111 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1112
Tony Barbour552f6c02016-12-21 14:34:07 -07001113 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114
1115 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001117 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1118 m_errorMonitor->VerifyFound();
1119
1120 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001122 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1123 m_errorMonitor->VerifyFound();
1124
1125 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001127 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1128 m_errorMonitor->VerifyFound();
1129
Tony Barbour552f6c02016-12-21 14:34:07 -07001130 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001131}
Dustin Graves40f35822016-06-23 11:12:53 -06001132
Cortd889ff92016-07-27 09:51:27 -07001133TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1134 VkResult err;
1135
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001136 TEST_DESCRIPTION(
1137 "Attempt to use a non-solid polygon fill mode in a "
1138 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001139
1140 ASSERT_NO_FATAL_FAILURE(InitState());
1141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1142
1143 std::vector<const char *> device_extension_names;
1144 auto features = m_device->phy().features();
1145 // Artificially disable support for non-solid fill modes
1146 features.fillModeNonSolid = false;
1147 // The sacrificial device object
1148 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1149
1150 VkRenderpassObj render_pass(&test_device);
1151
1152 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1153 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1154 pipeline_layout_ci.setLayoutCount = 0;
1155 pipeline_layout_ci.pSetLayouts = NULL;
1156
1157 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001158 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001159 ASSERT_VK_SUCCESS(err);
1160
1161 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1162 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1163 rs_ci.pNext = nullptr;
1164 rs_ci.lineWidth = 1.0f;
1165 rs_ci.rasterizerDiscardEnable = true;
1166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001167 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1168 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001169
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001170 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1172 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001173 {
1174 VkPipelineObj pipe(&test_device);
1175 pipe.AddShader(&vs);
1176 pipe.AddShader(&fs);
1177 pipe.AddColorAttachment();
1178 // Introduce failure by setting unsupported polygon mode
1179 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1180 pipe.SetRasterization(&rs_ci);
1181 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1182 }
1183 m_errorMonitor->VerifyFound();
1184
1185 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1187 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001188 {
1189 VkPipelineObj pipe(&test_device);
1190 pipe.AddShader(&vs);
1191 pipe.AddShader(&fs);
1192 pipe.AddColorAttachment();
1193 // Introduce failure by setting unsupported polygon mode
1194 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1195 pipe.SetRasterization(&rs_ci);
1196 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1197 }
1198 m_errorMonitor->VerifyFound();
1199
Cortd889ff92016-07-27 09:51:27 -07001200 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1201}
1202
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001203#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001204TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205{
1206 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001207 VkFenceCreateInfo fenceInfo = {};
1208 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1209 fenceInfo.pNext = NULL;
1210 fenceInfo.flags = 0;
1211
Mike Weiblencce7ec72016-10-17 19:33:05 -06001212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001213
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001214 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001215
1216 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1217 vk_testing::Buffer buffer;
1218 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001219
Tony Barbourfe3351b2015-07-28 10:17:20 -06001220 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001222 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001223
1224 testFence.init(*m_device, fenceInfo);
1225
1226 // Bypass framework since it does the waits automatically
1227 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001228 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001229 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1230 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001231 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001232 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001233 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001234 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001235 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001236 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001237 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001238
1239 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001240 ASSERT_VK_SUCCESS( err );
1241
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001242 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001243 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001245 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001246}
1247
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001248TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001249{
1250 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251 VkFenceCreateInfo fenceInfo = {};
1252 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1253 fenceInfo.pNext = NULL;
1254 fenceInfo.flags = 0;
1255
Mike Weiblencce7ec72016-10-17 19:33:05 -06001256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001257
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001258 ASSERT_NO_FATAL_FAILURE(InitState());
1259 ASSERT_NO_FATAL_FAILURE(InitViewport());
1260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1261
Tony Barbourfe3351b2015-07-28 10:17:20 -06001262 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001264 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001265
1266 testFence.init(*m_device, fenceInfo);
1267
1268 // Bypass framework since it does the waits automatically
1269 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001270 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001271 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1272 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001273 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001274 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001275 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001276 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001277 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001278 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001279 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001280
1281 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001282 ASSERT_VK_SUCCESS( err );
1283
Jon Ashburnf19916e2016-01-11 13:12:43 -07001284 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001285 VkCommandBufferBeginInfo info = {};
1286 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1287 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001288 info.renderPass = VK_NULL_HANDLE;
1289 info.subpass = 0;
1290 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001291 info.occlusionQueryEnable = VK_FALSE;
1292 info.queryFlags = 0;
1293 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001294
1295 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001296 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001297
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001298 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001299}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001300#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001301
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001302TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1303 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1304
1305 ASSERT_NO_FATAL_FAILURE(InitState());
1306
1307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1308 VkBuffer buffer;
1309 VkBufferCreateInfo buf_info = {};
1310 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1311 buf_info.pNext = NULL;
1312 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1313 buf_info.size = 2048;
1314 buf_info.queueFamilyIndexCount = 0;
1315 buf_info.pQueueFamilyIndices = NULL;
1316 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1317 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1318 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1319 m_errorMonitor->VerifyFound();
1320
1321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1322 VkImage image;
1323 VkImageCreateInfo image_create_info = {};
1324 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1325 image_create_info.pNext = NULL;
1326 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1327 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1328 image_create_info.extent.width = 512;
1329 image_create_info.extent.height = 64;
1330 image_create_info.extent.depth = 1;
1331 image_create_info.mipLevels = 1;
1332 image_create_info.arrayLayers = 1;
1333 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1334 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1335 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1336 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1337 image_create_info.queueFamilyIndexCount = 0;
1338 image_create_info.pQueueFamilyIndices = NULL;
1339 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1340 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1341 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1342 m_errorMonitor->VerifyFound();
1343}
1344
Dave Houlton829c0d82017-01-24 15:09:17 -07001345TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1346 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1347
1348 // Determine which device feature are available
1349 VkPhysicalDeviceFeatures available_features;
1350 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1351
1352 // Mask out device features we don't want
1353 VkPhysicalDeviceFeatures desired_features = available_features;
1354 desired_features.sparseResidencyImage2D = VK_FALSE;
1355 desired_features.sparseResidencyImage3D = VK_FALSE;
1356 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1357
1358 VkImage image = VK_NULL_HANDLE;
1359 VkResult result = VK_RESULT_MAX_ENUM;
1360 VkImageCreateInfo image_create_info = {};
1361 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1362 image_create_info.pNext = NULL;
1363 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1364 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1365 image_create_info.extent.width = 512;
1366 image_create_info.extent.height = 1;
1367 image_create_info.extent.depth = 1;
1368 image_create_info.mipLevels = 1;
1369 image_create_info.arrayLayers = 1;
1370 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1371 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1372 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1373 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1374 image_create_info.queueFamilyIndexCount = 0;
1375 image_create_info.pQueueFamilyIndices = NULL;
1376 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1377 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1378
1379 // 1D image w/ sparse residency is an error
1380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1381 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1382 m_errorMonitor->VerifyFound();
1383 if (VK_SUCCESS == result) {
1384 vkDestroyImage(m_device->device(), image, NULL);
1385 image = VK_NULL_HANDLE;
1386 }
1387
1388 // 2D image w/ sparse residency when feature isn't available
1389 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1390 image_create_info.extent.height = 64;
1391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1392 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1393 m_errorMonitor->VerifyFound();
1394 if (VK_SUCCESS == result) {
1395 vkDestroyImage(m_device->device(), image, NULL);
1396 image = VK_NULL_HANDLE;
1397 }
1398
1399 // 3D image w/ sparse residency when feature isn't available
1400 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1401 image_create_info.extent.depth = 8;
1402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1403 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1404 m_errorMonitor->VerifyFound();
1405 if (VK_SUCCESS == result) {
1406 vkDestroyImage(m_device->device(), image, NULL);
1407 image = VK_NULL_HANDLE;
1408 }
1409}
1410
1411TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1412 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1413
1414 // Determine which device feature are available
1415 VkPhysicalDeviceFeatures available_features;
1416 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1417
1418 // These tests all require that the device support sparse residency for 2D images
1419 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1420 return;
1421 }
1422
1423 // Mask out device features we don't want
1424 VkPhysicalDeviceFeatures desired_features = available_features;
1425 desired_features.sparseResidency2Samples = VK_FALSE;
1426 desired_features.sparseResidency4Samples = VK_FALSE;
1427 desired_features.sparseResidency8Samples = VK_FALSE;
1428 desired_features.sparseResidency16Samples = VK_FALSE;
1429 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1430
1431 VkImage image = VK_NULL_HANDLE;
1432 VkResult result = VK_RESULT_MAX_ENUM;
1433 VkImageCreateInfo image_create_info = {};
1434 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1435 image_create_info.pNext = NULL;
1436 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1437 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1438 image_create_info.extent.width = 64;
1439 image_create_info.extent.height = 64;
1440 image_create_info.extent.depth = 1;
1441 image_create_info.mipLevels = 1;
1442 image_create_info.arrayLayers = 1;
1443 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1444 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1445 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1446 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1447 image_create_info.queueFamilyIndexCount = 0;
1448 image_create_info.pQueueFamilyIndices = NULL;
1449 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1450 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1451
1452 // 2D image w/ sparse residency and linear tiling is an error
1453 m_errorMonitor->SetDesiredFailureMsg(
1454 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1455 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1456 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1457 m_errorMonitor->VerifyFound();
1458 if (VK_SUCCESS == result) {
1459 vkDestroyImage(m_device->device(), image, NULL);
1460 image = VK_NULL_HANDLE;
1461 }
1462 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1463
1464 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1465 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1467 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1468 m_errorMonitor->VerifyFound();
1469 if (VK_SUCCESS == result) {
1470 vkDestroyImage(m_device->device(), image, NULL);
1471 image = VK_NULL_HANDLE;
1472 }
1473
1474 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1476 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1477 m_errorMonitor->VerifyFound();
1478 if (VK_SUCCESS == result) {
1479 vkDestroyImage(m_device->device(), image, NULL);
1480 image = VK_NULL_HANDLE;
1481 }
1482
1483 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1485 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1486 m_errorMonitor->VerifyFound();
1487 if (VK_SUCCESS == result) {
1488 vkDestroyImage(m_device->device(), image, NULL);
1489 image = VK_NULL_HANDLE;
1490 }
1491
1492 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1494 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1495 m_errorMonitor->VerifyFound();
1496 if (VK_SUCCESS == result) {
1497 vkDestroyImage(m_device->device(), image, NULL);
1498 image = VK_NULL_HANDLE;
1499 }
1500}
1501
Tobin Ehlisf11be982016-05-11 13:52:53 -06001502TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001503 TEST_DESCRIPTION(
1504 "Create a buffer and image, allocate memory, and bind the "
1505 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001506 VkResult err;
1507 bool pass;
1508 ASSERT_NO_FATAL_FAILURE(InitState());
1509
Tobin Ehlis077ded32016-05-12 17:39:13 -06001510 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001511 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001512 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001513 VkDeviceMemory mem; // buffer will be bound first
1514 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001515 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001516 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001517
1518 VkBufferCreateInfo buf_info = {};
1519 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1520 buf_info.pNext = NULL;
1521 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1522 buf_info.size = 256;
1523 buf_info.queueFamilyIndexCount = 0;
1524 buf_info.pQueueFamilyIndices = NULL;
1525 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1526 buf_info.flags = 0;
1527 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1528 ASSERT_VK_SUCCESS(err);
1529
Tobin Ehlis077ded32016-05-12 17:39:13 -06001530 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001531
1532 VkImageCreateInfo image_create_info = {};
1533 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1534 image_create_info.pNext = NULL;
1535 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1536 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1537 image_create_info.extent.width = 64;
1538 image_create_info.extent.height = 64;
1539 image_create_info.extent.depth = 1;
1540 image_create_info.mipLevels = 1;
1541 image_create_info.arrayLayers = 1;
1542 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001543 // Image tiling must be optimal to trigger error when aliasing linear buffer
1544 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001545 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1546 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1547 image_create_info.queueFamilyIndexCount = 0;
1548 image_create_info.pQueueFamilyIndices = NULL;
1549 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1550 image_create_info.flags = 0;
1551
Tobin Ehlisf11be982016-05-11 13:52:53 -06001552 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1553 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001554 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1555 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001556
Tobin Ehlis077ded32016-05-12 17:39:13 -06001557 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1558
1559 VkMemoryAllocateInfo alloc_info = {};
1560 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1561 alloc_info.pNext = NULL;
1562 alloc_info.memoryTypeIndex = 0;
1563 // Ensure memory is big enough for both bindings
1564 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001565 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1566 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001567 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001568 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001569 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001570 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001571 return;
1572 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001573 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1574 ASSERT_VK_SUCCESS(err);
1575 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1576 ASSERT_VK_SUCCESS(err);
1577
Rene Lindsayd14f5572016-12-16 14:57:18 -07001578 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1579
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001581 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001582 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1583 m_errorMonitor->VerifyFound();
1584
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001585 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001586 // aliasing buffer2
1587 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1588 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001589 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1590 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001591 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001592 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001594 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001595 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001596 m_errorMonitor->VerifyFound();
1597
1598 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001599 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001600 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001601 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001602 vkFreeMemory(m_device->device(), mem, NULL);
1603 vkFreeMemory(m_device->device(), mem_img, NULL);
1604}
1605
Tobin Ehlis35372522016-05-12 08:32:31 -06001606TEST_F(VkLayerTest, InvalidMemoryMapping) {
1607 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1608 VkResult err;
1609 bool pass;
1610 ASSERT_NO_FATAL_FAILURE(InitState());
1611
1612 VkBuffer buffer;
1613 VkDeviceMemory mem;
1614 VkMemoryRequirements mem_reqs;
1615
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001616 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1617
Tobin Ehlis35372522016-05-12 08:32:31 -06001618 VkBufferCreateInfo buf_info = {};
1619 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1620 buf_info.pNext = NULL;
1621 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1622 buf_info.size = 256;
1623 buf_info.queueFamilyIndexCount = 0;
1624 buf_info.pQueueFamilyIndices = NULL;
1625 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1626 buf_info.flags = 0;
1627 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1628 ASSERT_VK_SUCCESS(err);
1629
1630 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1631 VkMemoryAllocateInfo alloc_info = {};
1632 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1633 alloc_info.pNext = NULL;
1634 alloc_info.memoryTypeIndex = 0;
1635
1636 // Ensure memory is big enough for both bindings
1637 static const VkDeviceSize allocation_size = 0x10000;
1638 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001639 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 -06001640 if (!pass) {
1641 vkDestroyBuffer(m_device->device(), buffer, NULL);
1642 return;
1643 }
1644 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1645 ASSERT_VK_SUCCESS(err);
1646
1647 uint8_t *pData;
1648 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001649 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 -06001650 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1651 m_errorMonitor->VerifyFound();
1652 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001653 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001654 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1656 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1657 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001658 m_errorMonitor->VerifyFound();
1659
1660 // Unmap the memory to avoid re-map error
1661 vkUnmapMemory(m_device->device(), mem);
1662 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1664 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1665 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001666 m_errorMonitor->VerifyFound();
1667 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1669 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001670 m_errorMonitor->VerifyFound();
1671 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001673 vkUnmapMemory(m_device->device(), mem);
1674 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001675
Tobin Ehlis35372522016-05-12 08:32:31 -06001676 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001677 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001678 ASSERT_VK_SUCCESS(err);
1679 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001680 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001681 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001682 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001684 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1685 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001686
Tobin Ehlis35372522016-05-12 08:32:31 -06001687 // Now flush range that oversteps mapped range
1688 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001689 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001690 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001691 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001692 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1694 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1695 m_errorMonitor->VerifyFound();
1696
1697 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1698 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001699 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001700 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001701 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001702 mmr.size = VK_WHOLE_SIZE;
1703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001704 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1705 m_errorMonitor->VerifyFound();
1706
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001707#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001708 // Some platforms have an atomsize of 1 which makes the test meaningless
1709 if (atom_size > 3) {
1710 // Now with an offset NOT a multiple of the device limit
1711 vkUnmapMemory(m_device->device(), mem);
1712 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1713 ASSERT_VK_SUCCESS(err);
1714 mmr.offset = 3; // Not a multiple of atom_size
1715 mmr.size = VK_WHOLE_SIZE;
1716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1717 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1718 m_errorMonitor->VerifyFound();
1719
1720 // Now with a size NOT a multiple of the device limit
1721 vkUnmapMemory(m_device->device(), mem);
1722 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1723 ASSERT_VK_SUCCESS(err);
1724 mmr.offset = atom_size;
1725 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1727 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1728 m_errorMonitor->VerifyFound();
1729 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001730#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001731 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1732 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001733 if (!pass) {
1734 vkFreeMemory(m_device->device(), mem, NULL);
1735 vkDestroyBuffer(m_device->device(), buffer, NULL);
1736 return;
1737 }
1738 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1739 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1740
1741 vkDestroyBuffer(m_device->device(), buffer, NULL);
1742 vkFreeMemory(m_device->device(), mem, NULL);
1743}
1744
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001745#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001746TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1747 VkResult err;
1748 bool pass;
1749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001750 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1751 // following declaration (which is temporarily being moved below):
1752 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001753 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001754 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001755 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001756 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001757 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001758 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001759
1760 ASSERT_NO_FATAL_FAILURE(InitState());
1761
Ian Elliott3f06ce52016-04-29 14:46:21 -06001762#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1763#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1764 // Use the functions from the VK_KHR_android_surface extension without
1765 // enabling that extension:
1766
1767 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001768 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_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 = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001771 pass = (err != VK_SUCCESS);
1772 ASSERT_TRUE(pass);
1773 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001774#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001775
Ian Elliott3f06ce52016-04-29 14:46:21 -06001776#if defined(VK_USE_PLATFORM_MIR_KHR)
1777 // Use the functions from the VK_KHR_mir_surface extension without enabling
1778 // that extension:
1779
1780 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001781 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001783 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1784 pass = (err != VK_SUCCESS);
1785 ASSERT_TRUE(pass);
1786 m_errorMonitor->VerifyFound();
1787
1788 // Tell whether an mir_connection supports presentation:
1789 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1791 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001792 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001793#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001794
Ian Elliott3f06ce52016-04-29 14:46:21 -06001795#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1796 // Use the functions from the VK_KHR_wayland_surface extension without
1797 // enabling that extension:
1798
1799 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001800 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1802 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001803 pass = (err != VK_SUCCESS);
1804 ASSERT_TRUE(pass);
1805 m_errorMonitor->VerifyFound();
1806
1807 // Tell whether an wayland_display supports presentation:
1808 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1810 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001811 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001812#endif // VK_USE_PLATFORM_WAYLAND_KHR
1813#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814
Ian Elliott3f06ce52016-04-29 14:46:21 -06001815#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001816 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1817 // TO NON-LINUX PLATFORMS:
1818 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001819 // Use the functions from the VK_KHR_win32_surface extension without
1820 // enabling that extension:
1821
1822 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001823 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1825 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001826 pass = (err != VK_SUCCESS);
1827 ASSERT_TRUE(pass);
1828 m_errorMonitor->VerifyFound();
1829
1830 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001832 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001833 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001834// Set this (for now, until all platforms are supported and tested):
1835#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001836#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001837#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001838 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1839 // TO NON-LINUX PLATFORMS:
1840 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001841#endif
1842#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001843 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1844 // that extension:
1845
1846 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001847 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001849 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1850 pass = (err != VK_SUCCESS);
1851 ASSERT_TRUE(pass);
1852 m_errorMonitor->VerifyFound();
1853
1854 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001855 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001856 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1858 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001859 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001860// Set this (for now, until all platforms are supported and tested):
1861#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001862#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001863
Ian Elliott12630812016-04-29 14:35:43 -06001864#if defined(VK_USE_PLATFORM_XLIB_KHR)
1865 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1866 // that extension:
1867
1868 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001869 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001871 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1872 pass = (err != VK_SUCCESS);
1873 ASSERT_TRUE(pass);
1874 m_errorMonitor->VerifyFound();
1875
1876 // Tell whether an Xlib VisualID supports presentation:
1877 Display *dpy = NULL;
1878 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001880 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1881 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001882// Set this (for now, until all platforms are supported and tested):
1883#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001884#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001885
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001886// Use the functions from the VK_KHR_surface extension without enabling
1887// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001888
Ian Elliott489eec02016-05-05 14:12:44 -06001889#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001890 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001892 vkDestroySurfaceKHR(instance(), surface, NULL);
1893 m_errorMonitor->VerifyFound();
1894
1895 // Check if surface supports presentation:
1896 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001898 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1899 pass = (err != VK_SUCCESS);
1900 ASSERT_TRUE(pass);
1901 m_errorMonitor->VerifyFound();
1902
1903 // Check surface capabilities:
1904 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1906 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001907 pass = (err != VK_SUCCESS);
1908 ASSERT_TRUE(pass);
1909 m_errorMonitor->VerifyFound();
1910
1911 // Check surface formats:
1912 uint32_t format_count = 0;
1913 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1915 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001916 pass = (err != VK_SUCCESS);
1917 ASSERT_TRUE(pass);
1918 m_errorMonitor->VerifyFound();
1919
1920 // Check surface present modes:
1921 uint32_t present_mode_count = 0;
1922 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1924 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001925 pass = (err != VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001928#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001929
Ian Elliott1c32c772016-04-28 14:47:13 -06001930 // Use the functions from the VK_KHR_swapchain extension without enabling
1931 // that extension:
1932
1933 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001935 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1936 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001937 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001938 pass = (err != VK_SUCCESS);
1939 ASSERT_TRUE(pass);
1940 m_errorMonitor->VerifyFound();
1941
1942 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1944 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001945 pass = (err != VK_SUCCESS);
1946 ASSERT_TRUE(pass);
1947 m_errorMonitor->VerifyFound();
1948
Chris Forbeseb7d5502016-09-13 18:19:21 +12001949 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1950 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1951 VkFence fence;
1952 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1953
Ian Elliott1c32c772016-04-28 14:47:13 -06001954 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001956 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001957 pass = (err != VK_SUCCESS);
1958 ASSERT_TRUE(pass);
1959 m_errorMonitor->VerifyFound();
1960
Chris Forbeseb7d5502016-09-13 18:19:21 +12001961 vkDestroyFence(m_device->device(), fence, nullptr);
1962
Ian Elliott1c32c772016-04-28 14:47:13 -06001963 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001964 //
1965 // NOTE: Currently can't test this because a real swapchain is needed (as
1966 // opposed to the fake one we created) in order for the layer to lookup the
1967 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001968
1969 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001971 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1972 m_errorMonitor->VerifyFound();
1973}
Chris Forbes09368e42016-10-13 11:59:22 +13001974#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001975
Karl Schultz6addd812016-02-02 17:17:23 -07001976TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1977 VkResult err;
1978 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1981 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001982
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001983 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001984
1985 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001986 VkImage image;
1987 VkDeviceMemory mem;
1988 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001989
Karl Schultz6addd812016-02-02 17:17:23 -07001990 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1991 const int32_t tex_width = 32;
1992 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001993
Tony Barboureb254902015-07-15 12:50:33 -06001994 VkImageCreateInfo image_create_info = {};
1995 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001996 image_create_info.pNext = NULL;
1997 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1998 image_create_info.format = tex_format;
1999 image_create_info.extent.width = tex_width;
2000 image_create_info.extent.height = tex_height;
2001 image_create_info.extent.depth = 1;
2002 image_create_info.mipLevels = 1;
2003 image_create_info.arrayLayers = 1;
2004 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2005 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2006 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2007 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002008 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002009
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002010 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002011 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002012 mem_alloc.pNext = NULL;
2013 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002014
Chia-I Wuf7458c52015-10-26 21:10:41 +08002015 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002016 ASSERT_VK_SUCCESS(err);
2017
Karl Schultz6addd812016-02-02 17:17:23 -07002018 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002019
Mark Lobodzinski23065352015-05-29 09:32:35 -05002020 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 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 -07002023 if (!pass) { // If we can't find any unmappable memory this test doesn't
2024 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002025 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002026 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002027 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002028
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002029 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002030 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002031 ASSERT_VK_SUCCESS(err);
2032
2033 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002034 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002035 ASSERT_VK_SUCCESS(err);
2036
2037 // Map memory as if to initialize the image
2038 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002040
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002041 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002042
Chia-I Wuf7458c52015-10-26 21:10:41 +08002043 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002044 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002045}
2046
Karl Schultz6addd812016-02-02 17:17:23 -07002047TEST_F(VkLayerTest, RebindMemory) {
2048 VkResult err;
2049 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002052
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002053 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002054
2055 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002056 VkImage image;
2057 VkDeviceMemory mem1;
2058 VkDeviceMemory mem2;
2059 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002060
Karl Schultz6addd812016-02-02 17:17:23 -07002061 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2062 const int32_t tex_width = 32;
2063 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002064
Tony Barboureb254902015-07-15 12:50:33 -06002065 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002066 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2067 image_create_info.pNext = NULL;
2068 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2069 image_create_info.format = tex_format;
2070 image_create_info.extent.width = tex_width;
2071 image_create_info.extent.height = tex_height;
2072 image_create_info.extent.depth = 1;
2073 image_create_info.mipLevels = 1;
2074 image_create_info.arrayLayers = 1;
2075 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2076 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2077 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2078 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002079
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002080 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002081 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2082 mem_alloc.pNext = NULL;
2083 mem_alloc.allocationSize = 0;
2084 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002085
Karl Schultz6addd812016-02-02 17:17:23 -07002086 // Introduce failure, do NOT set memProps to
2087 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002088 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002089 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002090 ASSERT_VK_SUCCESS(err);
2091
Karl Schultz6addd812016-02-02 17:17:23 -07002092 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002093
2094 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002095 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002096 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002097
2098 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002099 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002100 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002101 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102 ASSERT_VK_SUCCESS(err);
2103
2104 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002105 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002106 ASSERT_VK_SUCCESS(err);
2107
Karl Schultz6addd812016-02-02 17:17:23 -07002108 // Introduce validation failure, try to bind a different memory object to
2109 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002110 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002111
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002112 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002113
Chia-I Wuf7458c52015-10-26 21:10:41 +08002114 vkDestroyImage(m_device->device(), image, NULL);
2115 vkFreeMemory(m_device->device(), mem1, NULL);
2116 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002117}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002118
Karl Schultz6addd812016-02-02 17:17:23 -07002119TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002120 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002121
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2123 "submitted in SIGNALED state. Fences "
2124 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002125
2126 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002127 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2128 fenceInfo.pNext = NULL;
2129 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002130
Tony Barbour300a6082015-04-07 13:44:53 -06002131 ASSERT_NO_FATAL_FAILURE(InitState());
2132 ASSERT_NO_FATAL_FAILURE(InitViewport());
2133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2134
Tony Barbour552f6c02016-12-21 14:34:07 -07002135 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002136 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002137 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002138
2139 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002140
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002141 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002142 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2143 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002144 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002145 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002146 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002147 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002148 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002149 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002150 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002151
2152 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002153 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002154
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002155 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002156}
Chris Forbes4e44c912016-06-16 10:20:00 +12002157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002158TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002159 TEST_DESCRIPTION(
2160 "Specify wrong usage for image then create conflicting view of image "
2161 "Initialize buffer with wrong usage then perform copy expecting errors "
2162 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002164
2165 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002166
2167 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2168
Tony Barbourf92621a2016-05-02 14:28:12 -06002169 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002170 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002171 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002172 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002173
Tony Barbourf92621a2016-05-02 14:28:12 -06002174 VkImageView dsv;
2175 VkImageViewCreateInfo dsvci = {};
2176 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2177 dsvci.image = image.handle();
2178 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002179 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002180 dsvci.subresourceRange.layerCount = 1;
2181 dsvci.subresourceRange.baseMipLevel = 0;
2182 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002183 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002184
Tony Barbourf92621a2016-05-02 14:28:12 -06002185 // Create a view with depth / stencil aspect for image with different usage
2186 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002187
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002188 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002189
2190 // Initialize buffer with TRANSFER_DST usage
2191 vk_testing::Buffer buffer;
2192 VkMemoryPropertyFlags reqs = 0;
2193 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2194 VkBufferImageCopy region = {};
2195 region.bufferRowLength = 128;
2196 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002197 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002198 region.imageSubresource.layerCount = 1;
2199 region.imageExtent.height = 16;
2200 region.imageExtent.width = 16;
2201 region.imageExtent.depth = 1;
2202
Mark Lobodzinski80871462017-02-16 10:37:27 -07002203 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002204 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002205
Chris Forbesda581202016-10-06 18:25:26 +13002206 // two separate errors from this call:
2207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002210 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2211 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002212 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002213}
Tony Barbour75d79f02016-08-30 09:39:07 -06002214
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002215TEST_F(VkLayerTest, LeakAnObject) {
2216 VkResult err;
2217
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002218 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002219
2220 // Note that we have to create a new device since destroying the
2221 // framework's device causes Teardown() to fail and just calling Teardown
2222 // will destroy the errorMonitor.
2223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002225
2226 ASSERT_NO_FATAL_FAILURE(InitState());
2227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002228 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002229 std::vector<VkDeviceQueueCreateInfo> queue_info;
2230 queue_info.reserve(queue_props.size());
2231 std::vector<std::vector<float>> queue_priorities;
2232 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2233 VkDeviceQueueCreateInfo qi = {};
2234 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2235 qi.pNext = NULL;
2236 qi.queueFamilyIndex = i;
2237 qi.queueCount = queue_props[i].queueCount;
2238 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2239 qi.pQueuePriorities = queue_priorities[i].data();
2240 queue_info.push_back(qi);
2241 }
2242
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002243 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002244
2245 // The sacrificial device object
2246 VkDevice testDevice;
2247 VkDeviceCreateInfo device_create_info = {};
2248 auto features = m_device->phy().features();
2249 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2250 device_create_info.pNext = NULL;
2251 device_create_info.queueCreateInfoCount = queue_info.size();
2252 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002253 device_create_info.enabledLayerCount = 0;
2254 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002255 device_create_info.pEnabledFeatures = &features;
2256 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2257 ASSERT_VK_SUCCESS(err);
2258
2259 VkFence fence;
2260 VkFenceCreateInfo fence_create_info = {};
2261 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2262 fence_create_info.pNext = NULL;
2263 fence_create_info.flags = 0;
2264 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2265 ASSERT_VK_SUCCESS(err);
2266
2267 // Induce failure by not calling vkDestroyFence
2268 vkDestroyDevice(testDevice, NULL);
2269 m_errorMonitor->VerifyFound();
2270}
2271
2272TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002273 TEST_DESCRIPTION(
2274 "Allocate command buffers from one command pool and "
2275 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002276
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002278
Cody Northropc31a84f2016-08-22 10:41:47 -06002279 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002280 VkCommandPool command_pool_one;
2281 VkCommandPool command_pool_two;
2282
2283 VkCommandPoolCreateInfo pool_create_info{};
2284 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2285 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2286 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002288 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002291
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002292 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002293 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002294 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002295 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002296 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002297 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002298 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002299
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002300 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002301
2302 m_errorMonitor->VerifyFound();
2303
2304 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2305 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2306}
2307
2308TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2309 VkResult err;
2310
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002311 TEST_DESCRIPTION(
2312 "Allocate descriptor sets from one DS pool and "
2313 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002316
2317 ASSERT_NO_FATAL_FAILURE(InitState());
2318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2319
2320 VkDescriptorPoolSize ds_type_count = {};
2321 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2322 ds_type_count.descriptorCount = 1;
2323
2324 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2325 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2326 ds_pool_ci.pNext = NULL;
2327 ds_pool_ci.flags = 0;
2328 ds_pool_ci.maxSets = 1;
2329 ds_pool_ci.poolSizeCount = 1;
2330 ds_pool_ci.pPoolSizes = &ds_type_count;
2331
2332 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002333 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002334 ASSERT_VK_SUCCESS(err);
2335
2336 // Create a second descriptor pool
2337 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002338 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002339 ASSERT_VK_SUCCESS(err);
2340
2341 VkDescriptorSetLayoutBinding dsl_binding = {};
2342 dsl_binding.binding = 0;
2343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2344 dsl_binding.descriptorCount = 1;
2345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2346 dsl_binding.pImmutableSamplers = NULL;
2347
2348 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2349 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2350 ds_layout_ci.pNext = NULL;
2351 ds_layout_ci.bindingCount = 1;
2352 ds_layout_ci.pBindings = &dsl_binding;
2353
2354 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002355 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002356 ASSERT_VK_SUCCESS(err);
2357
2358 VkDescriptorSet descriptorSet;
2359 VkDescriptorSetAllocateInfo alloc_info = {};
2360 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2361 alloc_info.descriptorSetCount = 1;
2362 alloc_info.descriptorPool = ds_pool_one;
2363 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002364 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002365 ASSERT_VK_SUCCESS(err);
2366
2367 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2368
2369 m_errorMonitor->VerifyFound();
2370
2371 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2372 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2373 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2374}
2375
2376TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002378
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002379 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002380
2381 ASSERT_NO_FATAL_FAILURE(InitState());
2382
2383 // Pass bogus handle into GetImageMemoryRequirements
2384 VkMemoryRequirements mem_reqs;
2385 uint64_t fakeImageHandle = 0xCADECADE;
2386 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2387
2388 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2389
2390 m_errorMonitor->VerifyFound();
2391}
2392
Karl Schultz6addd812016-02-02 17:17:23 -07002393TEST_F(VkLayerTest, PipelineNotBound) {
2394 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002395
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002396 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002397
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002399
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002400 ASSERT_NO_FATAL_FAILURE(InitState());
2401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002402
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002403 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002404 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2405 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002406
2407 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002408 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2409 ds_pool_ci.pNext = NULL;
2410 ds_pool_ci.maxSets = 1;
2411 ds_pool_ci.poolSizeCount = 1;
2412 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002413
2414 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002415 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002416 ASSERT_VK_SUCCESS(err);
2417
2418 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002419 dsl_binding.binding = 0;
2420 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2421 dsl_binding.descriptorCount = 1;
2422 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2423 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002424
2425 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002426 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2427 ds_layout_ci.pNext = NULL;
2428 ds_layout_ci.bindingCount = 1;
2429 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002430
2431 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002432 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002433 ASSERT_VK_SUCCESS(err);
2434
2435 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002436 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002437 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002438 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002439 alloc_info.descriptorPool = ds_pool;
2440 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002441 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002442 ASSERT_VK_SUCCESS(err);
2443
2444 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002445 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2446 pipeline_layout_ci.pNext = NULL;
2447 pipeline_layout_ci.setLayoutCount = 1;
2448 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002449
2450 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002452 ASSERT_VK_SUCCESS(err);
2453
Mark Youngad779052016-01-06 14:26:04 -07002454 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002455
Tony Barbour552f6c02016-12-21 14:34:07 -07002456 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002457 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002458
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002459 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002460
Chia-I Wuf7458c52015-10-26 21:10:41 +08002461 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2462 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2463 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002464}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002465
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002466TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2467 VkResult err;
2468
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002469 TEST_DESCRIPTION(
2470 "Test validation check for an invalid memory type index "
2471 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002472
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002473 ASSERT_NO_FATAL_FAILURE(InitState());
2474
2475 // Create an image, allocate memory, set a bad typeIndex and then try to
2476 // bind it
2477 VkImage image;
2478 VkDeviceMemory mem;
2479 VkMemoryRequirements mem_reqs;
2480 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2481 const int32_t tex_width = 32;
2482 const int32_t tex_height = 32;
2483
2484 VkImageCreateInfo image_create_info = {};
2485 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2486 image_create_info.pNext = NULL;
2487 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2488 image_create_info.format = tex_format;
2489 image_create_info.extent.width = tex_width;
2490 image_create_info.extent.height = tex_height;
2491 image_create_info.extent.depth = 1;
2492 image_create_info.mipLevels = 1;
2493 image_create_info.arrayLayers = 1;
2494 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2495 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2496 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2497 image_create_info.flags = 0;
2498
2499 VkMemoryAllocateInfo mem_alloc = {};
2500 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2501 mem_alloc.pNext = NULL;
2502 mem_alloc.allocationSize = 0;
2503 mem_alloc.memoryTypeIndex = 0;
2504
2505 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2506 ASSERT_VK_SUCCESS(err);
2507
2508 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2509 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002510
2511 // Introduce Failure, select invalid TypeIndex
2512 VkPhysicalDeviceMemoryProperties memory_info;
2513
2514 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2515 unsigned int i;
2516 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2517 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2518 mem_alloc.memoryTypeIndex = i;
2519 break;
2520 }
2521 }
2522 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002523 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002524 vkDestroyImage(m_device->device(), image, NULL);
2525 return;
2526 }
2527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002528 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 -06002529
2530 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2531 ASSERT_VK_SUCCESS(err);
2532
2533 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2534 (void)err;
2535
2536 m_errorMonitor->VerifyFound();
2537
2538 vkDestroyImage(m_device->device(), image, NULL);
2539 vkFreeMemory(m_device->device(), mem, NULL);
2540}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002541
Karl Schultz6addd812016-02-02 17:17:23 -07002542TEST_F(VkLayerTest, BindInvalidMemory) {
2543 VkResult err;
2544 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002545
2546 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002547
Cortf801b982017-01-17 18:10:21 -08002548 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -07002549 const int32_t tex_width = 32;
2550 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002551
2552 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002553 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2554 image_create_info.pNext = NULL;
2555 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2556 image_create_info.format = tex_format;
2557 image_create_info.extent.width = tex_width;
2558 image_create_info.extent.height = tex_height;
2559 image_create_info.extent.depth = 1;
2560 image_create_info.mipLevels = 1;
2561 image_create_info.arrayLayers = 1;
2562 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002563 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002564 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2565 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002566
Cortf801b982017-01-17 18:10:21 -08002567 VkBufferCreateInfo buffer_create_info = {};
2568 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2569 buffer_create_info.pNext = NULL;
2570 buffer_create_info.flags = 0;
2571 buffer_create_info.size = tex_width;
2572 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2573 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002574
Cortf801b982017-01-17 18:10:21 -08002575 // Create an image/buffer, allocate memory, free it, and then try to bind it
2576 {
2577 VkImage image = VK_NULL_HANDLE;
2578 VkBuffer buffer = VK_NULL_HANDLE;
2579 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2580 ASSERT_VK_SUCCESS(err);
2581 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2582 ASSERT_VK_SUCCESS(err);
2583 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2584 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2585 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002586
Cortf801b982017-01-17 18:10:21 -08002587 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2588 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2589 image_mem_alloc.allocationSize = image_mem_reqs.size;
2590 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2591 ASSERT_TRUE(pass);
2592 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2593 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2594 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2595 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002596
Cortf801b982017-01-17 18:10:21 -08002597 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2598 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2599 ASSERT_VK_SUCCESS(err);
2600 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2601 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002602
Cortf801b982017-01-17 18:10:21 -08002603 vkFreeMemory(device(), image_mem, NULL);
2604 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002605
Cortf801b982017-01-17 18:10:21 -08002606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2607 err = vkBindImageMemory(device(), image, image_mem, 0);
2608 (void)err; // This may very well return an error.
2609 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002610
Cortf801b982017-01-17 18:10:21 -08002611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2612 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2613 (void)err; // This may very well return an error.
2614 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002615
Cortf801b982017-01-17 18:10:21 -08002616 vkDestroyImage(m_device->device(), image, NULL);
2617 vkDestroyBuffer(m_device->device(), buffer, NULL);
2618 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002619
2620 // Try to bind memory to an object that already has a memory binding
2621 {
2622 VkImage image = VK_NULL_HANDLE;
2623 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2624 ASSERT_VK_SUCCESS(err);
2625 VkBuffer buffer = VK_NULL_HANDLE;
2626 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2627 ASSERT_VK_SUCCESS(err);
2628 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2629 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2630 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2631 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2632 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2633 image_alloc_info.allocationSize = image_mem_reqs.size;
2634 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2635 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2636 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2637 ASSERT_TRUE(pass);
2638 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2639 ASSERT_TRUE(pass);
2640 VkDeviceMemory image_mem, buffer_mem;
2641 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2642 ASSERT_VK_SUCCESS(err);
2643 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2644 ASSERT_VK_SUCCESS(err);
2645
2646 err = vkBindImageMemory(device(), image, image_mem, 0);
2647 ASSERT_VK_SUCCESS(err);
2648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2649 err = vkBindImageMemory(device(), image, image_mem, 0);
2650 (void)err; // This may very well return an error.
2651 m_errorMonitor->VerifyFound();
2652
2653 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2654 ASSERT_VK_SUCCESS(err);
2655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2656 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2657 (void)err; // This may very well return an error.
2658 m_errorMonitor->VerifyFound();
2659
2660 vkFreeMemory(device(), image_mem, NULL);
2661 vkFreeMemory(device(), buffer_mem, NULL);
2662 vkDestroyImage(device(), image, NULL);
2663 vkDestroyBuffer(device(), buffer, NULL);
2664 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002665
Cort6c7dff72017-01-27 18:34:50 -08002666 // Try to bind memory to an object with an out-of-range memoryOffset
2667 {
2668 VkImage image = VK_NULL_HANDLE;
2669 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2670 ASSERT_VK_SUCCESS(err);
2671 VkBuffer buffer = VK_NULL_HANDLE;
2672 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2673 ASSERT_VK_SUCCESS(err);
2674 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2675 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2676 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2677 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2678 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2679 image_alloc_info.allocationSize = image_mem_reqs.size;
2680 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2681 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2682 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2683 ASSERT_TRUE(pass);
2684 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2685 ASSERT_TRUE(pass);
2686 VkDeviceMemory image_mem, buffer_mem;
2687 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2688 ASSERT_VK_SUCCESS(err);
2689 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2690 ASSERT_VK_SUCCESS(err);
2691
2692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2693 VkDeviceSize image_offset = (image_mem_reqs.size + (image_mem_reqs.alignment - 1)) & ~(image_mem_reqs.alignment - 1);
2694 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2695 (void)err; // This may very well return an error.
2696 m_errorMonitor->VerifyFound();
2697
2698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2699 VkDeviceSize buffer_offset = (buffer_mem_reqs.size + (buffer_mem_reqs.alignment - 1)) & ~(buffer_mem_reqs.alignment - 1);
2700 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2701 (void)err; // This may very well return an error.
2702 m_errorMonitor->VerifyFound();
2703
2704 vkFreeMemory(device(), image_mem, NULL);
2705 vkFreeMemory(device(), buffer_mem, NULL);
2706 vkDestroyImage(device(), image, NULL);
2707 vkDestroyBuffer(device(), buffer, NULL);
2708 }
2709
Cort Stratton4c38bb52017-01-28 13:33:10 -08002710 // Try to bind memory to an object with an invalid memory type
2711 {
2712 VkImage image = VK_NULL_HANDLE;
2713 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2714 ASSERT_VK_SUCCESS(err);
2715 VkBuffer buffer = VK_NULL_HANDLE;
2716 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2717 ASSERT_VK_SUCCESS(err);
2718 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2719 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2720 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2721 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2722 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2723 image_alloc_info.allocationSize = image_mem_reqs.size;
2724 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2725 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002726 // Create a mask of available memory types *not* supported by these resources,
2727 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002728 VkPhysicalDeviceMemoryProperties memory_properties = {};
2729 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002730 VkDeviceMemory image_mem, buffer_mem;
2731
Cort Stratton4c38bb52017-01-28 13:33:10 -08002732 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002733 if (image_unsupported_mem_type_bits != 0) {
2734 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2735 ASSERT_TRUE(pass);
2736 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2737 ASSERT_VK_SUCCESS(err);
2738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2739 err = vkBindImageMemory(device(), image, image_mem, 0);
2740 (void)err; // This may very well return an error.
2741 m_errorMonitor->VerifyFound();
2742 vkFreeMemory(device(), image_mem, NULL);
2743 }
2744
Cort Stratton4c38bb52017-01-28 13:33:10 -08002745 uint32_t buffer_unsupported_mem_type_bits =
2746 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002747 if (buffer_unsupported_mem_type_bits != 0) {
2748 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2749 ASSERT_TRUE(pass);
2750 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2751 ASSERT_VK_SUCCESS(err);
2752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2753 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2754 (void)err; // This may very well return an error.
2755 m_errorMonitor->VerifyFound();
2756 vkFreeMemory(device(), buffer_mem, NULL);
2757 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002758
Cort Stratton4c38bb52017-01-28 13:33:10 -08002759 vkDestroyImage(device(), image, NULL);
2760 vkDestroyBuffer(device(), buffer, NULL);
2761 }
2762
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002763 // Try to bind memory to an image created with sparse memory flags
2764 {
2765 VkImageCreateInfo sparse_image_create_info = image_create_info;
2766 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2767 VkImageFormatProperties image_format_properties = {};
2768 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2769 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2770 sparse_image_create_info.usage, sparse_image_create_info.flags,
2771 &image_format_properties);
2772 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2773 // most likely means sparse formats aren't supported here; skip this test.
2774 } else {
2775 ASSERT_VK_SUCCESS(err);
2776 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002777 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002778 return;
2779 } else {
2780 VkImage sparse_image = VK_NULL_HANDLE;
2781 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2782 ASSERT_VK_SUCCESS(err);
2783 VkMemoryRequirements sparse_mem_reqs = {};
2784 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2785 if (sparse_mem_reqs.memoryTypeBits != 0) {
2786 VkMemoryAllocateInfo sparse_mem_alloc = {};
2787 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2788 sparse_mem_alloc.pNext = NULL;
2789 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2790 sparse_mem_alloc.memoryTypeIndex = 0;
2791 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2792 ASSERT_TRUE(pass);
2793 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2794 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2795 ASSERT_VK_SUCCESS(err);
2796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2797 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2798 // This may very well return an error.
2799 (void)err;
2800 m_errorMonitor->VerifyFound();
2801 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2802 }
2803 vkDestroyImage(m_device->device(), sparse_image, NULL);
2804 }
2805 }
2806 }
2807
2808 // Try to bind memory to a buffer created with sparse memory flags
2809 {
2810 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2811 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2812 if (!m_device->phy().features().sparseResidencyBuffer) {
2813 // most likely means sparse formats aren't supported here; skip this test.
2814 } else {
2815 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2816 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2817 ASSERT_VK_SUCCESS(err);
2818 VkMemoryRequirements sparse_mem_reqs = {};
2819 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2820 if (sparse_mem_reqs.memoryTypeBits != 0) {
2821 VkMemoryAllocateInfo sparse_mem_alloc = {};
2822 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2823 sparse_mem_alloc.pNext = NULL;
2824 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2825 sparse_mem_alloc.memoryTypeIndex = 0;
2826 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2827 ASSERT_TRUE(pass);
2828 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2829 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2830 ASSERT_VK_SUCCESS(err);
2831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2832 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2833 // This may very well return an error.
2834 (void)err;
2835 m_errorMonitor->VerifyFound();
2836 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2837 }
2838 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2839 }
2840 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002841}
2842
Karl Schultz6addd812016-02-02 17:17:23 -07002843TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2844 VkResult err;
2845 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002846
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002848
Tobin Ehlisec598302015-09-15 15:02:17 -06002849 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002850
Karl Schultz6addd812016-02-02 17:17:23 -07002851 // Create an image object, allocate memory, destroy the object and then try
2852 // to bind it
2853 VkImage image;
2854 VkDeviceMemory mem;
2855 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002856
Karl Schultz6addd812016-02-02 17:17:23 -07002857 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2858 const int32_t tex_width = 32;
2859 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002860
2861 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002862 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2863 image_create_info.pNext = NULL;
2864 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2865 image_create_info.format = tex_format;
2866 image_create_info.extent.width = tex_width;
2867 image_create_info.extent.height = tex_height;
2868 image_create_info.extent.depth = 1;
2869 image_create_info.mipLevels = 1;
2870 image_create_info.arrayLayers = 1;
2871 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2872 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2873 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2874 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002875
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002876 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002877 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2878 mem_alloc.pNext = NULL;
2879 mem_alloc.allocationSize = 0;
2880 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002881
Chia-I Wuf7458c52015-10-26 21:10:41 +08002882 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002883 ASSERT_VK_SUCCESS(err);
2884
Karl Schultz6addd812016-02-02 17:17:23 -07002885 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002886
2887 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002888 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002889 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002890
2891 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002892 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002893 ASSERT_VK_SUCCESS(err);
2894
2895 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002896 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002897 ASSERT_VK_SUCCESS(err);
2898
2899 // Now Try to bind memory to this destroyed object
2900 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2901 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002902 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002903
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002904 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002905
Chia-I Wuf7458c52015-10-26 21:10:41 +08002906 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002907}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002908
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002909TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2910 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2911
2912 ASSERT_NO_FATAL_FAILURE(InitState());
2913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2914
2915 VkVertexInputBindingDescription input_binding;
2916 memset(&input_binding, 0, sizeof(input_binding));
2917
2918 VkVertexInputAttributeDescription input_attribs;
2919 memset(&input_attribs, 0, sizeof(input_attribs));
2920
2921 // Pick a really bad format for this purpose and make sure it should fail
2922 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2923 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2924 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002925 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002926 return;
2927 }
2928
2929 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002930 char const *vsSource =
2931 "#version 450\n"
2932 "\n"
2933 "out gl_PerVertex {\n"
2934 " vec4 gl_Position;\n"
2935 "};\n"
2936 "void main(){\n"
2937 " gl_Position = vec4(1);\n"
2938 "}\n";
2939 char const *fsSource =
2940 "#version 450\n"
2941 "\n"
2942 "layout(location=0) out vec4 color;\n"
2943 "void main(){\n"
2944 " color = vec4(1);\n"
2945 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002946
2947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2948 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2949 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2950
2951 VkPipelineObj pipe(m_device);
2952 pipe.AddColorAttachment();
2953 pipe.AddShader(&vs);
2954 pipe.AddShader(&fs);
2955
2956 pipe.AddVertexInputBindings(&input_binding, 1);
2957 pipe.AddVertexInputAttribs(&input_attribs, 1);
2958
2959 VkDescriptorSetObj descriptorSet(m_device);
2960 descriptorSet.AppendDummy();
2961 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2962
2963 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2964
2965 m_errorMonitor->VerifyFound();
2966}
2967
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002968TEST_F(VkLayerTest, ImageSampleCounts) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002969 TEST_DESCRIPTION(
2970 "Use bad sample counts in image transfer calls to trigger "
2971 "validation errors.");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002972 ASSERT_NO_FATAL_FAILURE(InitState());
2973
2974 VkMemoryPropertyFlags reqs = 0;
2975 VkImageCreateInfo image_create_info = {};
2976 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2977 image_create_info.pNext = NULL;
2978 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2979 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2980 image_create_info.extent.width = 256;
2981 image_create_info.extent.height = 256;
2982 image_create_info.extent.depth = 1;
2983 image_create_info.mipLevels = 1;
2984 image_create_info.arrayLayers = 1;
2985 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2986 image_create_info.flags = 0;
2987
2988 VkImageBlit blit_region = {};
2989 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2990 blit_region.srcSubresource.baseArrayLayer = 0;
2991 blit_region.srcSubresource.layerCount = 1;
2992 blit_region.srcSubresource.mipLevel = 0;
2993 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2994 blit_region.dstSubresource.baseArrayLayer = 0;
2995 blit_region.dstSubresource.layerCount = 1;
2996 blit_region.dstSubresource.mipLevel = 0;
2997
2998 // Create two images, the source with sampleCount = 2, and attempt to blit
2999 // between them
3000 {
3001 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003002 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003003 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003004 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003005 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003006 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003007 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003008 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003009 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003010 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3012 "was created with a sample count "
3013 "of VK_SAMPLE_COUNT_2_BIT but "
3014 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003015 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3016 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003017 m_errorMonitor->VerifyFound();
3018 m_commandBuffer->EndCommandBuffer();
3019 }
3020
3021 // Create two images, the dest with sampleCount = 4, and attempt to blit
3022 // between them
3023 {
3024 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003025 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003026 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003027 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003028 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003029 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003030 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003031 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003032 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003033 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3035 "was created with a sample count "
3036 "of VK_SAMPLE_COUNT_4_BIT but "
3037 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003038 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3039 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003040 m_errorMonitor->VerifyFound();
3041 m_commandBuffer->EndCommandBuffer();
3042 }
3043
3044 VkBufferImageCopy copy_region = {};
3045 copy_region.bufferRowLength = 128;
3046 copy_region.bufferImageHeight = 128;
3047 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3048 copy_region.imageSubresource.layerCount = 1;
3049 copy_region.imageExtent.height = 64;
3050 copy_region.imageExtent.width = 64;
3051 copy_region.imageExtent.depth = 1;
3052
3053 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3054 // buffer to image
3055 {
3056 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003057 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3058 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003059 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003060 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003061 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003062 m_errorMonitor->SetUnexpectedError(
3063 "If commandBuffer was allocated from a VkCommandPool which did not have the "
3064 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003065 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3067 "was created with a sample count "
3068 "of VK_SAMPLE_COUNT_8_BIT but "
3069 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003070 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3071 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003072 m_errorMonitor->VerifyFound();
3073 m_commandBuffer->EndCommandBuffer();
3074 }
3075
3076 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3077 // image to buffer
3078 {
3079 vk_testing::Buffer dst_buffer;
3080 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3081 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003082 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003083 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003084 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003085 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003086 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3088 "was created with a sample count "
3089 "of VK_SAMPLE_COUNT_2_BIT but "
3090 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003091 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003092 dst_buffer.handle(), 1, &copy_region);
3093 m_errorMonitor->VerifyFound();
3094 m_commandBuffer->EndCommandBuffer();
3095 }
3096}
3097
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003098TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003099 ASSERT_NO_FATAL_FAILURE(InitState());
3100
3101 VkImageObj src_image(m_device);
3102 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3103 VkImageObj dst_image(m_device);
3104 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3105 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003106 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 -06003107
3108 VkImageBlit blitRegion = {};
3109 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3110 blitRegion.srcSubresource.baseArrayLayer = 0;
3111 blitRegion.srcSubresource.layerCount = 1;
3112 blitRegion.srcSubresource.mipLevel = 0;
3113 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3114 blitRegion.dstSubresource.baseArrayLayer = 0;
3115 blitRegion.dstSubresource.layerCount = 1;
3116 blitRegion.dstSubresource.mipLevel = 0;
3117
Dave Houlton34df4cb2016-12-01 16:43:06 -07003118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3119
3120 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3121 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003122
3123 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003124 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003125 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3126 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003127
3128 m_errorMonitor->VerifyFound();
3129
Dave Houlton34df4cb2016-12-01 16:43:06 -07003130 // Test should generate 2 VU failures
3131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003133
3134 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003135 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3136 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003137
Dave Houlton34df4cb2016-12-01 16:43:06 -07003138 // TODO: Note that this only verifies that at least one of the VU enums was found
3139 // 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 -06003140 m_errorMonitor->VerifyFound();
3141
Tony Barbour552f6c02016-12-21 14:34:07 -07003142 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003143}
3144
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003145TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3146 VkResult err;
3147 bool pass;
3148
3149 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3150 ASSERT_NO_FATAL_FAILURE(InitState());
3151
3152 // If w/d/h granularity is 1, test is not meaningful
3153 // TODO: When virtual device limits are available, create a set of limits for this test that
3154 // will always have a granularity of > 1 for w, h, and d
3155 auto index = m_device->graphics_queue_node_index_;
3156 auto queue_family_properties = m_device->phy().queue_properties();
3157
3158 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3159 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3160 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3161 return;
3162 }
3163
3164 // Create two images of different types and try to copy between them
3165 VkImage srcImage;
3166 VkImage dstImage;
3167 VkDeviceMemory srcMem;
3168 VkDeviceMemory destMem;
3169 VkMemoryRequirements memReqs;
3170
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003171 VkImageCreateInfo image_create_info = {};
3172 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3173 image_create_info.pNext = NULL;
3174 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3175 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3176 image_create_info.extent.width = 32;
3177 image_create_info.extent.height = 32;
3178 image_create_info.extent.depth = 1;
3179 image_create_info.mipLevels = 1;
3180 image_create_info.arrayLayers = 4;
3181 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3182 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3183 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3184 image_create_info.flags = 0;
3185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003186 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003187 ASSERT_VK_SUCCESS(err);
3188
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003189 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003190 ASSERT_VK_SUCCESS(err);
3191
3192 // Allocate memory
3193 VkMemoryAllocateInfo memAlloc = {};
3194 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3195 memAlloc.pNext = NULL;
3196 memAlloc.allocationSize = 0;
3197 memAlloc.memoryTypeIndex = 0;
3198
3199 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3200 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003201 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003202 ASSERT_TRUE(pass);
3203 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3204 ASSERT_VK_SUCCESS(err);
3205
3206 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3207 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003208 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003209 ASSERT_VK_SUCCESS(err);
3210 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3211 ASSERT_VK_SUCCESS(err);
3212
3213 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3214 ASSERT_VK_SUCCESS(err);
3215 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3216 ASSERT_VK_SUCCESS(err);
3217
Tony Barbour552f6c02016-12-21 14:34:07 -07003218 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003219 VkImageCopy copyRegion;
3220 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3221 copyRegion.srcSubresource.mipLevel = 0;
3222 copyRegion.srcSubresource.baseArrayLayer = 0;
3223 copyRegion.srcSubresource.layerCount = 1;
3224 copyRegion.srcOffset.x = 0;
3225 copyRegion.srcOffset.y = 0;
3226 copyRegion.srcOffset.z = 0;
3227 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3228 copyRegion.dstSubresource.mipLevel = 0;
3229 copyRegion.dstSubresource.baseArrayLayer = 0;
3230 copyRegion.dstSubresource.layerCount = 1;
3231 copyRegion.dstOffset.x = 0;
3232 copyRegion.dstOffset.y = 0;
3233 copyRegion.dstOffset.z = 0;
3234 copyRegion.extent.width = 1;
3235 copyRegion.extent.height = 1;
3236 copyRegion.extent.depth = 1;
3237
3238 // Introduce failure by setting srcOffset to a bad granularity value
3239 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3241 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003242 m_errorMonitor->VerifyFound();
3243
3244 // Introduce failure by setting extent to a bad granularity value
3245 copyRegion.srcOffset.y = 0;
3246 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3248 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003249 m_errorMonitor->VerifyFound();
3250
3251 // Now do some buffer/image copies
3252 vk_testing::Buffer buffer;
3253 VkMemoryPropertyFlags reqs = 0;
3254 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3255 VkBufferImageCopy region = {};
3256 region.bufferOffset = 0;
3257 region.bufferRowLength = 3;
3258 region.bufferImageHeight = 128;
3259 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3260 region.imageSubresource.layerCount = 1;
3261 region.imageExtent.height = 16;
3262 region.imageExtent.width = 16;
3263 region.imageExtent.depth = 1;
3264 region.imageOffset.x = 0;
3265 region.imageOffset.y = 0;
3266 region.imageOffset.z = 0;
3267
3268 // Introduce failure by setting bufferRowLength to a bad granularity value
3269 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3271 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3272 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003273 m_errorMonitor->VerifyFound();
3274 region.bufferRowLength = 128;
3275
3276 // Introduce failure by setting bufferOffset to a bad granularity value
3277 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3279 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3280 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003281 m_errorMonitor->VerifyFound();
3282 region.bufferOffset = 0;
3283
3284 // Introduce failure by setting bufferImageHeight to a bad granularity value
3285 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3287 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3288 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003289 m_errorMonitor->VerifyFound();
3290 region.bufferImageHeight = 128;
3291
3292 // Introduce failure by setting imageExtent to a bad granularity value
3293 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3295 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3296 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003297 m_errorMonitor->VerifyFound();
3298 region.imageExtent.width = 16;
3299
3300 // Introduce failure by setting imageOffset to a bad granularity value
3301 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3303 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3304 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003305 m_errorMonitor->VerifyFound();
3306
Tony Barbour552f6c02016-12-21 14:34:07 -07003307 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003308
3309 vkDestroyImage(m_device->device(), srcImage, NULL);
3310 vkDestroyImage(m_device->device(), dstImage, NULL);
3311 vkFreeMemory(m_device->device(), srcMem, NULL);
3312 vkFreeMemory(m_device->device(), destMem, NULL);
3313}
3314
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003315TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003316 TEST_DESCRIPTION(
3317 "Submit command buffer created using one queue family and "
3318 "attempt to submit them on a queue created in a different "
3319 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003320
Cody Northropc31a84f2016-08-22 10:41:47 -06003321 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003322
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003323 // This test is meaningless unless we have multiple queue families
3324 auto queue_family_properties = m_device->phy().queue_properties();
3325 if (queue_family_properties.size() < 2) {
3326 return;
3327 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003329 // Get safe index of another queue family
3330 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3331 ASSERT_NO_FATAL_FAILURE(InitState());
3332 // Create a second queue using a different queue family
3333 VkQueue other_queue;
3334 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3335
3336 // Record an empty cmd buffer
3337 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3338 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3339 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3340 vkEndCommandBuffer(m_commandBuffer->handle());
3341
3342 // And submit on the wrong queue
3343 VkSubmitInfo submit_info = {};
3344 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3345 submit_info.commandBufferCount = 1;
3346 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003347 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003348
3349 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003350}
3351
Chris Forbes4c24a922016-11-16 08:59:10 +13003352TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3353 ASSERT_NO_FATAL_FAILURE(InitState());
3354
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003355 // There are no attachments, but refer to attachment 0.
3356 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003357 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003358 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003359 };
3360
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003361 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003362 VkRenderPass rp;
3363
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003364 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003366 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3367 m_errorMonitor->VerifyFound();
3368}
3369
Chris Forbesa58c4522016-09-28 15:19:39 +13003370TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3371 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3372 ASSERT_NO_FATAL_FAILURE(InitState());
3373
3374 // A renderpass with two subpasses, both writing the same attachment.
3375 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003376 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3377 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3378 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003379 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003380 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003381 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003382 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3383 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003384 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003385 VkSubpassDependency dep = {0,
3386 1,
3387 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3388 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3389 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3390 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3391 VK_DEPENDENCY_BY_REGION_BIT};
3392 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003393 VkRenderPass rp;
3394 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3395 ASSERT_VK_SUCCESS(err);
3396
3397 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003398 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 +13003399 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3400
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003401 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003402 VkFramebuffer fb;
3403 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3404 ASSERT_VK_SUCCESS(err);
3405
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003406 char const *vsSource =
3407 "#version 450\n"
3408 "void main() { gl_Position = vec4(1); }\n";
3409 char const *fsSource =
3410 "#version 450\n"
3411 "layout(location=0) out vec4 color;\n"
3412 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003413
3414 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3415 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3416 VkPipelineObj pipe(m_device);
3417 pipe.AddColorAttachment();
3418 pipe.AddShader(&vs);
3419 pipe.AddShader(&fs);
3420 VkViewport view_port = {};
3421 m_viewports.push_back(view_port);
3422 pipe.SetViewport(m_viewports);
3423 VkRect2D rect = {};
3424 m_scissors.push_back(rect);
3425 pipe.SetScissor(m_scissors);
3426
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003427 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003428 VkPipelineLayout pl;
3429 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3430 ASSERT_VK_SUCCESS(err);
3431 pipe.CreateVKPipeline(pl, rp);
3432
Tony Barbour552f6c02016-12-21 14:34:07 -07003433 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003434
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003435 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3436 nullptr,
3437 rp,
3438 fb,
3439 {{
3440 0, 0,
3441 },
3442 {32, 32}},
3443 0,
3444 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003445
3446 // subtest 1: bind in the wrong subpass
3447 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3448 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003449 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 +13003450 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3451 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3452 m_errorMonitor->VerifyFound();
3453
3454 vkCmdEndRenderPass(m_commandBuffer->handle());
3455
3456 // subtest 2: bind in correct subpass, then transition to next subpass
3457 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3458 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3459 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003460 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 +13003461 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3462 m_errorMonitor->VerifyFound();
3463
3464 vkCmdEndRenderPass(m_commandBuffer->handle());
3465
Tony Barbour552f6c02016-12-21 14:34:07 -07003466 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003467
3468 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3469 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3470 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3471}
3472
Tony Barbour4e919972016-08-09 13:27:40 -06003473TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003474 TEST_DESCRIPTION(
3475 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3476 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003477 ASSERT_NO_FATAL_FAILURE(InitState());
3478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3479
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3481 "Cannot execute a render pass with renderArea "
3482 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003483
3484 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3485 m_renderPassBeginInfo.renderArea.extent.width = 257;
3486 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003487 m_commandBuffer->BeginCommandBuffer();
3488 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003489 m_errorMonitor->VerifyFound();
3490}
3491
3492TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003493 TEST_DESCRIPTION(
3494 "Generate INDEPENDENT_BLEND by disabling independent "
3495 "blend and then specifying different blend states for two "
3496 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003497 VkPhysicalDeviceFeatures features = {};
3498 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003499 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003500
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3502 "Invalid Pipeline CreateInfo: If independent blend feature not "
3503 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003504
Cody Northropc31a84f2016-08-22 10:41:47 -06003505 VkDescriptorSetObj descriptorSet(m_device);
3506 descriptorSet.AppendDummy();
3507 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003508
Cody Northropc31a84f2016-08-22 10:41:47 -06003509 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003510 // Create a renderPass with two color attachments
3511 VkAttachmentReference attachments[2] = {};
3512 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3513 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3514
3515 VkSubpassDescription subpass = {};
3516 subpass.pColorAttachments = attachments;
3517 subpass.colorAttachmentCount = 2;
3518
3519 VkRenderPassCreateInfo rpci = {};
3520 rpci.subpassCount = 1;
3521 rpci.pSubpasses = &subpass;
3522 rpci.attachmentCount = 1;
3523
3524 VkAttachmentDescription attach_desc = {};
3525 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3526 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3527 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3528 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3529
3530 rpci.pAttachments = &attach_desc;
3531 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3532
3533 VkRenderPass renderpass;
3534 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003535 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003536 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003537
Cody Northropc31a84f2016-08-22 10:41:47 -06003538 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3539 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3540 att_state1.blendEnable = VK_TRUE;
3541 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3542 att_state2.blendEnable = VK_FALSE;
3543 pipeline.AddColorAttachment(0, &att_state1);
3544 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003545 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003546 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003547 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003548}
3549
Mike Weiblen40b160e2017-02-06 19:21:52 -07003550// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3551TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3552 TEST_DESCRIPTION(
3553 "Create a graphics pipeline that is incompatible with the requirements "
3554 "of its contained Renderpass/subpasses.");
3555 ASSERT_NO_FATAL_FAILURE(InitState());
3556
3557 VkDescriptorSetObj ds_obj(m_device);
3558 ds_obj.AppendDummy();
3559 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3560
3561 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3562
3563 VkPipelineColorBlendAttachmentState att_state1 = {};
3564 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3565 att_state1.blendEnable = VK_TRUE;
3566
3567 VkRenderpassObj rp_obj(m_device);
3568
3569 {
3570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3571 VkPipelineObj pipeline(m_device);
3572 pipeline.AddShader(&vs_obj);
3573 pipeline.AddColorAttachment(0, &att_state1);
3574
3575 VkGraphicsPipelineCreateInfo info = {};
3576 pipeline.InitGraphicsPipelineCreateInfo(&info);
3577 info.pColorBlendState = nullptr;
3578
3579 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3580 m_errorMonitor->VerifyFound();
3581 }
3582}
3583
Chris Forbes26ec2122016-11-29 08:58:33 +13003584#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003585TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3586 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3587 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003588 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003589
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3591 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003592
3593 // Create a renderPass with a single color attachment
3594 VkAttachmentReference attach = {};
3595 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3596 VkSubpassDescription subpass = {};
3597 VkRenderPassCreateInfo rpci = {};
3598 rpci.subpassCount = 1;
3599 rpci.pSubpasses = &subpass;
3600 rpci.attachmentCount = 1;
3601 VkAttachmentDescription attach_desc = {};
3602 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3603 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3604 rpci.pAttachments = &attach_desc;
3605 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3606 VkRenderPass rp;
3607 subpass.pDepthStencilAttachment = &attach;
3608 subpass.pColorAttachments = NULL;
3609 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3610 m_errorMonitor->VerifyFound();
3611}
Chris Forbes26ec2122016-11-29 08:58:33 +13003612#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003613
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003614TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003615 TEST_DESCRIPTION(
3616 "Create a framebuffer where a subpass has a preserve "
3617 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003618
3619 ASSERT_NO_FATAL_FAILURE(InitState());
3620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3621
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003623
3624 VkAttachmentReference color_attach = {};
3625 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3626 color_attach.attachment = 0;
3627 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3628 VkSubpassDescription subpass = {};
3629 subpass.colorAttachmentCount = 1;
3630 subpass.pColorAttachments = &color_attach;
3631 subpass.preserveAttachmentCount = 1;
3632 subpass.pPreserveAttachments = &preserve_attachment;
3633
3634 VkRenderPassCreateInfo rpci = {};
3635 rpci.subpassCount = 1;
3636 rpci.pSubpasses = &subpass;
3637 rpci.attachmentCount = 1;
3638 VkAttachmentDescription attach_desc = {};
3639 attach_desc.format = VK_FORMAT_UNDEFINED;
3640 rpci.pAttachments = &attach_desc;
3641 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3642 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003643 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003644
3645 m_errorMonitor->VerifyFound();
3646
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003647 if (result == VK_SUCCESS) {
3648 vkDestroyRenderPass(m_device->device(), rp, NULL);
3649 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003650}
3651
Chris Forbesc5389742016-06-29 11:49:23 +12003652TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003653 TEST_DESCRIPTION(
3654 "Ensure that CreateRenderPass produces a validation error "
3655 "when the source of a subpass multisample resolve "
3656 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003657
Chris Forbesc5389742016-06-29 11:49:23 +12003658 ASSERT_NO_FATAL_FAILURE(InitState());
3659
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3661 "Subpass 0 requests multisample resolve from attachment 0 which has "
3662 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003663
3664 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003665 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3666 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3667 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3668 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3669 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3670 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003671 };
3672
3673 VkAttachmentReference color = {
3674 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3675 };
3676
3677 VkAttachmentReference resolve = {
3678 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3679 };
3680
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003681 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003682
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003683 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003684
3685 VkRenderPass rp;
3686 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3687
3688 m_errorMonitor->VerifyFound();
3689
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003690 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003691}
3692
3693TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003694 TEST_DESCRIPTION(
3695 "Ensure CreateRenderPass produces a validation error "
3696 "when a subpass multisample resolve operation is "
3697 "requested, and the destination of that resolve has "
3698 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003699
Chris Forbesc5389742016-06-29 11:49:23 +12003700 ASSERT_NO_FATAL_FAILURE(InitState());
3701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3703 "Subpass 0 requests multisample resolve into attachment 1, which "
3704 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003705
3706 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003707 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3708 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3709 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3710 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3711 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3712 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003713 };
3714
3715 VkAttachmentReference color = {
3716 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3717 };
3718
3719 VkAttachmentReference resolve = {
3720 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3721 };
3722
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003723 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003724
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003725 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003726
3727 VkRenderPass rp;
3728 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3729
3730 m_errorMonitor->VerifyFound();
3731
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003732 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003733}
3734
Chris Forbes3f128ef2016-06-29 14:58:53 +12003735TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003736 TEST_DESCRIPTION(
3737 "Ensure CreateRenderPass produces a validation error "
3738 "when the color and depth attachments used by a subpass "
3739 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003740
Chris Forbes3f128ef2016-06-29 14:58:53 +12003741 ASSERT_NO_FATAL_FAILURE(InitState());
3742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3744 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003745
3746 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003747 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3748 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3749 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3750 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3751 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3752 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003753 };
3754
3755 VkAttachmentReference color[] = {
3756 {
3757 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3758 },
3759 {
3760 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3761 },
3762 };
3763
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003764 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003765
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003766 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003767
3768 VkRenderPass rp;
3769 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3770
3771 m_errorMonitor->VerifyFound();
3772
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003773 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003774}
3775
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003776TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003777 TEST_DESCRIPTION(
3778 "Hit errors when attempting to create a framebuffer :\n"
3779 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3780 " 2. Use a color image as depthStencil attachment\n"
3781 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3782 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3783 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3784 " 6. Framebuffer attachment where dimensions don't match\n"
3785 " 7. Framebuffer attachment w/o identity swizzle\n"
3786 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003787
3788 ASSERT_NO_FATAL_FAILURE(InitState());
3789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3792 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3793 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003794
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003795 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003796 VkAttachmentReference attach = {};
3797 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3798 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003799 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003800 VkRenderPassCreateInfo rpci = {};
3801 rpci.subpassCount = 1;
3802 rpci.pSubpasses = &subpass;
3803 rpci.attachmentCount = 1;
3804 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003805 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003806 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003807 rpci.pAttachments = &attach_desc;
3808 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3809 VkRenderPass rp;
3810 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3811 ASSERT_VK_SUCCESS(err);
3812
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003813 VkImageView ivs[2];
3814 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3815 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003816 VkFramebufferCreateInfo fb_info = {};
3817 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3818 fb_info.pNext = NULL;
3819 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003820 // Set mis-matching attachmentCount
3821 fb_info.attachmentCount = 2;
3822 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003823 fb_info.width = 100;
3824 fb_info.height = 100;
3825 fb_info.layers = 1;
3826
3827 VkFramebuffer fb;
3828 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3829
3830 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003831 if (err == VK_SUCCESS) {
3832 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3833 }
3834 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003835
3836 // Create a renderPass with a depth-stencil attachment created with
3837 // IMAGE_USAGE_COLOR_ATTACHMENT
3838 // Add our color attachment to pDepthStencilAttachment
3839 subpass.pDepthStencilAttachment = &attach;
3840 subpass.pColorAttachments = NULL;
3841 VkRenderPass rp_ds;
3842 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3843 ASSERT_VK_SUCCESS(err);
3844 // Set correct attachment count, but attachment has COLOR usage bit set
3845 fb_info.attachmentCount = 1;
3846 fb_info.renderPass = rp_ds;
3847
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003849 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3850
3851 m_errorMonitor->VerifyFound();
3852 if (err == VK_SUCCESS) {
3853 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3854 }
3855 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003856
3857 // Create new renderpass with alternate attachment format from fb
3858 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3859 subpass.pDepthStencilAttachment = NULL;
3860 subpass.pColorAttachments = &attach;
3861 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3862 ASSERT_VK_SUCCESS(err);
3863
3864 // Cause error due to mis-matched formats between rp & fb
3865 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3866 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3868 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003869 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3870
3871 m_errorMonitor->VerifyFound();
3872 if (err == VK_SUCCESS) {
3873 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3874 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003875 vkDestroyRenderPass(m_device->device(), rp, NULL);
3876
3877 // Create new renderpass with alternate sample count from fb
3878 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3879 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3880 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3881 ASSERT_VK_SUCCESS(err);
3882
3883 // Cause error due to mis-matched sample count between rp & fb
3884 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3886 " has VK_SAMPLE_COUNT_1_BIT samples "
3887 "that do not match the "
3888 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003889 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3890
3891 m_errorMonitor->VerifyFound();
3892 if (err == VK_SUCCESS) {
3893 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3894 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003895
3896 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003897
3898 // Create a custom imageView with non-1 mip levels
3899 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003900 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 -06003901 ASSERT_TRUE(image.initialized());
3902
3903 VkImageView view;
3904 VkImageViewCreateInfo ivci = {};
3905 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3906 ivci.image = image.handle();
3907 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3908 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3909 ivci.subresourceRange.layerCount = 1;
3910 ivci.subresourceRange.baseMipLevel = 0;
3911 // Set level count 2 (only 1 is allowed for FB attachment)
3912 ivci.subresourceRange.levelCount = 2;
3913 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3914 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3915 ASSERT_VK_SUCCESS(err);
3916 // Re-create renderpass to have matching sample count
3917 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3918 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3919 ASSERT_VK_SUCCESS(err);
3920
3921 fb_info.renderPass = rp;
3922 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003924 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3925
3926 m_errorMonitor->VerifyFound();
3927 if (err == VK_SUCCESS) {
3928 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3929 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003930 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003931 // Update view to original color buffer and grow FB dimensions too big
3932 fb_info.pAttachments = ivs;
3933 fb_info.height = 1024;
3934 fb_info.width = 1024;
3935 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3937 " Attachment dimensions must be at "
3938 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003939 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3940
3941 m_errorMonitor->VerifyFound();
3942 if (err == VK_SUCCESS) {
3943 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3944 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003945 // Create view attachment with non-identity swizzle
3946 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3947 ivci.image = image.handle();
3948 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3949 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3950 ivci.subresourceRange.layerCount = 1;
3951 ivci.subresourceRange.baseMipLevel = 0;
3952 ivci.subresourceRange.levelCount = 1;
3953 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3954 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3955 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3956 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3957 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3958 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3959 ASSERT_VK_SUCCESS(err);
3960
3961 fb_info.pAttachments = &view;
3962 fb_info.height = 100;
3963 fb_info.width = 100;
3964 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3966 " has non-identy swizzle. All "
3967 "framebuffer attachments must have "
3968 "been created with the identity "
3969 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003970 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3971
3972 m_errorMonitor->VerifyFound();
3973 if (err == VK_SUCCESS) {
3974 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3975 }
3976 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003977 // reset attachment to color attachment
3978 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003979
3980 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003981 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003982 fb_info.height = 100;
3983 fb_info.layers = 1;
3984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003985 m_errorMonitor->SetUnexpectedError(
3986 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
3987 "Here are the respective dimensions for attachment");
3988
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003989 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3990
3991 m_errorMonitor->VerifyFound();
3992 if (err == VK_SUCCESS) {
3993 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3994 }
3995
3996 // Request fb that exceeds max height
3997 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003998 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003999 fb_info.layers = 1;
4000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004001 m_errorMonitor->SetUnexpectedError(
4002 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4003 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004004 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4005
4006 m_errorMonitor->VerifyFound();
4007 if (err == VK_SUCCESS) {
4008 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4009 }
4010
4011 // Request fb that exceeds max layers
4012 fb_info.width = 100;
4013 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004014 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004016 m_errorMonitor->SetUnexpectedError(
4017 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4018 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004019 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4020
4021 m_errorMonitor->VerifyFound();
4022 if (err == VK_SUCCESS) {
4023 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4024 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004025
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004026 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004027}
4028
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004029TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004030 TEST_DESCRIPTION(
4031 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4032 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004033
Cody Northropc31a84f2016-08-22 10:41:47 -06004034 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004035 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4037 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004038 m_errorMonitor->VerifyFound();
4039}
4040
4041TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004042 TEST_DESCRIPTION(
4043 "Run a simple draw calls to validate failure when Line Width dynamic "
4044 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004045
Cody Northropc31a84f2016-08-22 10:41:47 -06004046 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004047 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4049 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004050 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004051}
4052
4053TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004054 TEST_DESCRIPTION(
4055 "Run a simple draw calls to validate failure when Viewport dynamic "
4056 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004057
Cody Northropc31a84f2016-08-22 10:41:47 -06004058 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004059 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4061 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004062 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004063 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004064}
4065
4066TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004067 TEST_DESCRIPTION(
4068 "Run a simple draw calls to validate failure when Scissor dynamic "
4069 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004070
Cody Northropc31a84f2016-08-22 10:41:47 -06004071 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004072 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4074 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004075 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004076 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004077}
4078
Cortd713fe82016-07-27 09:51:27 -07004079TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004080 TEST_DESCRIPTION(
4081 "Run a simple draw calls to validate failure when Blend Constants "
4082 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004083
4084 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004085 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4087 "Dynamic blend constants state not set for this command buffer");
4088 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004089 m_errorMonitor->VerifyFound();
4090}
4091
4092TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004093 TEST_DESCRIPTION(
4094 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4095 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004096
4097 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004098 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004099 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004100 return;
4101 }
4102 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4104 "Dynamic depth bounds state not set for this command buffer");
4105 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004106 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004107}
4108
4109TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004110 TEST_DESCRIPTION(
4111 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4112 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004113
4114 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004115 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4117 "Dynamic stencil read mask state not set for this command buffer");
4118 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004119 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004120}
4121
4122TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004123 TEST_DESCRIPTION(
4124 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4125 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004126
4127 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004128 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4130 "Dynamic stencil write mask state not set for this command buffer");
4131 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004132 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004133}
4134
4135TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004136 TEST_DESCRIPTION(
4137 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4138 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004139
4140 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004141 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4143 "Dynamic stencil reference state not set for this command buffer");
4144 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004145 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004146}
4147
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004148TEST_F(VkLayerTest, IndexBufferNotBound) {
4149 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004150
4151 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4153 "Index buffer object not bound to this command buffer when Indexed ");
4154 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004155 m_errorMonitor->VerifyFound();
4156}
4157
Karl Schultz6addd812016-02-02 17:17:23 -07004158TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4160 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4161 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004162
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004163 ASSERT_NO_FATAL_FAILURE(InitState());
4164 ASSERT_NO_FATAL_FAILURE(InitViewport());
4165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4166
Karl Schultz6addd812016-02-02 17:17:23 -07004167 // We luck out b/c by default the framework creates CB w/ the
4168 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004169 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004170 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004171 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004172
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004173 // Bypass framework since it does the waits automatically
4174 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004175 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004176 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4177 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004178 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004179 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004180 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004181 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004182 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004183 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004184 submit_info.pSignalSemaphores = NULL;
4185
Chris Forbes40028e22016-06-13 09:59:34 +12004186 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004187 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004188 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004189
Karl Schultz6addd812016-02-02 17:17:23 -07004190 // Cause validation error by re-submitting cmd buffer that should only be
4191 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004192 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004193 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004194
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004195 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004196}
4197
Karl Schultz6addd812016-02-02 17:17:23 -07004198TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004199 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004200 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004201
4202 ASSERT_NO_FATAL_FAILURE(InitState());
4203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004204
Karl Schultz6addd812016-02-02 17:17:23 -07004205 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4206 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004207 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004208 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004209 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004210
4211 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004212 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4213 ds_pool_ci.pNext = NULL;
4214 ds_pool_ci.flags = 0;
4215 ds_pool_ci.maxSets = 1;
4216 ds_pool_ci.poolSizeCount = 1;
4217 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004218
4219 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004220 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004221 ASSERT_VK_SUCCESS(err);
4222
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004223 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4224 dsl_binding_samp.binding = 0;
4225 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4226 dsl_binding_samp.descriptorCount = 1;
4227 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4228 dsl_binding_samp.pImmutableSamplers = NULL;
4229
4230 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4231 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4232 ds_layout_ci.pNext = NULL;
4233 ds_layout_ci.bindingCount = 1;
4234 ds_layout_ci.pBindings = &dsl_binding_samp;
4235
4236 VkDescriptorSetLayout ds_layout_samp;
4237 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4238 ASSERT_VK_SUCCESS(err);
4239
4240 // Try to allocate 2 sets when pool only has 1 set
4241 VkDescriptorSet descriptor_sets[2];
4242 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4243 VkDescriptorSetAllocateInfo alloc_info = {};
4244 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4245 alloc_info.descriptorSetCount = 2;
4246 alloc_info.descriptorPool = ds_pool;
4247 alloc_info.pSetLayouts = set_layouts;
4248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4249 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4250 m_errorMonitor->VerifyFound();
4251
4252 alloc_info.descriptorSetCount = 1;
4253 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004254 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004255 dsl_binding.binding = 0;
4256 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4257 dsl_binding.descriptorCount = 1;
4258 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4259 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004260
Karl Schultz6addd812016-02-02 17:17:23 -07004261 ds_layout_ci.bindingCount = 1;
4262 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004263
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004264 VkDescriptorSetLayout ds_layout_ub;
4265 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004266 ASSERT_VK_SUCCESS(err);
4267
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004268 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004269 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004270 alloc_info.pSetLayouts = &ds_layout_ub;
4271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4272 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004273
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004274 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004275
Karl Schultz2825ab92016-12-02 08:23:14 -07004276 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004277 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004278 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004279}
4280
Karl Schultz6addd812016-02-02 17:17:23 -07004281TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4282 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004283
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004285
Tobin Ehlise735c692015-10-08 13:13:50 -06004286 ASSERT_NO_FATAL_FAILURE(InitState());
4287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004288
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004289 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004290 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4291 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004292
4293 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004294 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4295 ds_pool_ci.pNext = NULL;
4296 ds_pool_ci.maxSets = 1;
4297 ds_pool_ci.poolSizeCount = 1;
4298 ds_pool_ci.flags = 0;
4299 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4300 // app can only call vkResetDescriptorPool on this pool.;
4301 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004302
4303 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004304 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004305 ASSERT_VK_SUCCESS(err);
4306
4307 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004308 dsl_binding.binding = 0;
4309 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4310 dsl_binding.descriptorCount = 1;
4311 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4312 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004313
4314 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004315 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4316 ds_layout_ci.pNext = NULL;
4317 ds_layout_ci.bindingCount = 1;
4318 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004319
4320 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004321 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004322 ASSERT_VK_SUCCESS(err);
4323
4324 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004325 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004326 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004327 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004328 alloc_info.descriptorPool = ds_pool;
4329 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004330 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004331 ASSERT_VK_SUCCESS(err);
4332
4333 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004334 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004335
Chia-I Wuf7458c52015-10-26 21:10:41 +08004336 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4337 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004338}
4339
Karl Schultz6addd812016-02-02 17:17:23 -07004340TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004341 // Attempt to clear Descriptor Pool with bad object.
4342 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004343
4344 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004346 uint64_t fake_pool_handle = 0xbaad6001;
4347 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4348 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004349 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004350}
4351
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004352TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004353 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4354 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004355 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004356 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004357
4358 uint64_t fake_set_handle = 0xbaad6001;
4359 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004360 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004362
4363 ASSERT_NO_FATAL_FAILURE(InitState());
4364
4365 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4366 layout_bindings[0].binding = 0;
4367 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4368 layout_bindings[0].descriptorCount = 1;
4369 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4370 layout_bindings[0].pImmutableSamplers = NULL;
4371
4372 VkDescriptorSetLayout descriptor_set_layout;
4373 VkDescriptorSetLayoutCreateInfo dslci = {};
4374 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4375 dslci.pNext = NULL;
4376 dslci.bindingCount = 1;
4377 dslci.pBindings = layout_bindings;
4378 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004379 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004380
4381 VkPipelineLayout pipeline_layout;
4382 VkPipelineLayoutCreateInfo plci = {};
4383 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4384 plci.pNext = NULL;
4385 plci.setLayoutCount = 1;
4386 plci.pSetLayouts = &descriptor_set_layout;
4387 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004388 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004389
Tony Barbour552f6c02016-12-21 14:34:07 -07004390 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004391 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4392 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004393 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004394 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004395 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4396 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004397}
4398
Karl Schultz6addd812016-02-02 17:17:23 -07004399TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004400 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4401 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004402 uint64_t fake_layout_handle = 0xbaad6001;
4403 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004405 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004406 VkPipelineLayout pipeline_layout;
4407 VkPipelineLayoutCreateInfo plci = {};
4408 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4409 plci.pNext = NULL;
4410 plci.setLayoutCount = 1;
4411 plci.pSetLayouts = &bad_layout;
4412 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4413
4414 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004415}
4416
Mark Muellerd4914412016-06-13 17:52:06 -06004417TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004418 TEST_DESCRIPTION(
4419 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4420 "1) A uniform buffer update must have a valid buffer index."
4421 "2) When using an array of descriptors in a single WriteDescriptor,"
4422 " the descriptor types and stageflags must all be the same."
4423 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004424
Mike Weiblena6666382017-01-05 15:16:11 -07004425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004426
4427 ASSERT_NO_FATAL_FAILURE(InitState());
4428 VkDescriptorPoolSize ds_type_count[4] = {};
4429 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4430 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004431 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004432 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004433 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004434 ds_type_count[2].descriptorCount = 1;
4435 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4436 ds_type_count[3].descriptorCount = 1;
4437
4438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4440 ds_pool_ci.maxSets = 1;
4441 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4442 ds_pool_ci.pPoolSizes = ds_type_count;
4443
4444 VkDescriptorPool ds_pool;
4445 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4446 ASSERT_VK_SUCCESS(err);
4447
Mark Muellerb9896722016-06-16 09:54:29 -06004448 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004449 layout_binding[0].binding = 0;
4450 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4451 layout_binding[0].descriptorCount = 1;
4452 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4453 layout_binding[0].pImmutableSamplers = NULL;
4454
4455 layout_binding[1].binding = 1;
4456 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4457 layout_binding[1].descriptorCount = 1;
4458 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4459 layout_binding[1].pImmutableSamplers = NULL;
4460
4461 VkSamplerCreateInfo sampler_ci = {};
4462 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4463 sampler_ci.pNext = NULL;
4464 sampler_ci.magFilter = VK_FILTER_NEAREST;
4465 sampler_ci.minFilter = VK_FILTER_NEAREST;
4466 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4467 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4468 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4469 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4470 sampler_ci.mipLodBias = 1.0;
4471 sampler_ci.anisotropyEnable = VK_FALSE;
4472 sampler_ci.maxAnisotropy = 1;
4473 sampler_ci.compareEnable = VK_FALSE;
4474 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4475 sampler_ci.minLod = 1.0;
4476 sampler_ci.maxLod = 1.0;
4477 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4478 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4479 VkSampler sampler;
4480
4481 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4482 ASSERT_VK_SUCCESS(err);
4483
4484 layout_binding[2].binding = 2;
4485 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4486 layout_binding[2].descriptorCount = 1;
4487 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4488 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4489
Mark Muellerd4914412016-06-13 17:52:06 -06004490 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4491 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4492 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4493 ds_layout_ci.pBindings = layout_binding;
4494 VkDescriptorSetLayout ds_layout;
4495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4496 ASSERT_VK_SUCCESS(err);
4497
4498 VkDescriptorSetAllocateInfo alloc_info = {};
4499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4500 alloc_info.descriptorSetCount = 1;
4501 alloc_info.descriptorPool = ds_pool;
4502 alloc_info.pSetLayouts = &ds_layout;
4503 VkDescriptorSet descriptorSet;
4504 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4505 ASSERT_VK_SUCCESS(err);
4506
4507 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4508 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4509 pipeline_layout_ci.pNext = NULL;
4510 pipeline_layout_ci.setLayoutCount = 1;
4511 pipeline_layout_ci.pSetLayouts = &ds_layout;
4512
4513 VkPipelineLayout pipeline_layout;
4514 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4515 ASSERT_VK_SUCCESS(err);
4516
Mark Mueller5c838ce2016-06-16 09:54:29 -06004517 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004518 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4519 descriptor_write.dstSet = descriptorSet;
4520 descriptor_write.dstBinding = 0;
4521 descriptor_write.descriptorCount = 1;
4522 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4523
Mark Mueller5c838ce2016-06-16 09:54:29 -06004524 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004525 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4526 m_errorMonitor->VerifyFound();
4527
4528 // Create a buffer to update the descriptor with
4529 uint32_t qfi = 0;
4530 VkBufferCreateInfo buffCI = {};
4531 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4532 buffCI.size = 1024;
4533 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4534 buffCI.queueFamilyIndexCount = 1;
4535 buffCI.pQueueFamilyIndices = &qfi;
4536
4537 VkBuffer dyub;
4538 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4539 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004540
Tony Barboure132c5f2016-12-12 11:50:20 -07004541 VkDeviceMemory mem;
4542 VkMemoryRequirements mem_reqs;
4543 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4544
4545 VkMemoryAllocateInfo mem_alloc_info = {};
4546 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4547 mem_alloc_info.allocationSize = mem_reqs.size;
4548 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4549 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4550 ASSERT_VK_SUCCESS(err);
4551
4552 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4553 ASSERT_VK_SUCCESS(err);
4554
4555 VkDescriptorBufferInfo buffInfo[2] = {};
4556 buffInfo[0].buffer = dyub;
4557 buffInfo[0].offset = 0;
4558 buffInfo[0].range = 1024;
4559 buffInfo[1].buffer = dyub;
4560 buffInfo[1].offset = 0;
4561 buffInfo[1].range = 1024;
4562 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004563 descriptor_write.descriptorCount = 2;
4564
Mark Mueller5c838ce2016-06-16 09:54:29 -06004565 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004567 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4568 m_errorMonitor->VerifyFound();
4569
Mark Mueller5c838ce2016-06-16 09:54:29 -06004570 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4571 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004572 descriptor_write.dstBinding = 1;
4573 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004574
Mark Mueller5c838ce2016-06-16 09:54:29 -06004575 // Make pImageInfo index non-null to avoid complaints of it missing
4576 VkDescriptorImageInfo imageInfo = {};
4577 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4578 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004580 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4581 m_errorMonitor->VerifyFound();
4582
Mark Muellerd4914412016-06-13 17:52:06 -06004583 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004584 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004585 vkDestroySampler(m_device->device(), sampler, NULL);
4586 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4587 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4588 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4589}
4590
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004591TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004592 TEST_DESCRIPTION(
4593 "Attempt to draw with a command buffer that is invalid "
4594 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004595 ASSERT_NO_FATAL_FAILURE(InitState());
4596
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004597 VkBuffer buffer;
4598 VkDeviceMemory mem;
4599 VkMemoryRequirements mem_reqs;
4600
4601 VkBufferCreateInfo buf_info = {};
4602 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004603 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004604 buf_info.size = 256;
4605 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4606 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4607 ASSERT_VK_SUCCESS(err);
4608
4609 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4610
4611 VkMemoryAllocateInfo alloc_info = {};
4612 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4613 alloc_info.allocationSize = 256;
4614 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004615 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 -06004616 if (!pass) {
4617 vkDestroyBuffer(m_device->device(), buffer, NULL);
4618 return;
4619 }
4620 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4621 ASSERT_VK_SUCCESS(err);
4622
4623 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4624 ASSERT_VK_SUCCESS(err);
4625
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004626 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004627 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004628 m_commandBuffer->EndCommandBuffer();
4629
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004631 // Destroy buffer dependency prior to submit to cause ERROR
4632 vkDestroyBuffer(m_device->device(), buffer, NULL);
4633
4634 VkSubmitInfo submit_info = {};
4635 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4636 submit_info.commandBufferCount = 1;
4637 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004638 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004639 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4640
4641 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004642 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004643 vkFreeMemory(m_device->handle(), mem, NULL);
4644}
4645
Tobin Ehlisea413442016-09-28 10:23:59 -06004646TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4647 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4648
4649 ASSERT_NO_FATAL_FAILURE(InitState());
4650 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4651
4652 VkDescriptorPoolSize ds_type_count;
4653 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4654 ds_type_count.descriptorCount = 1;
4655
4656 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4657 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4658 ds_pool_ci.maxSets = 1;
4659 ds_pool_ci.poolSizeCount = 1;
4660 ds_pool_ci.pPoolSizes = &ds_type_count;
4661
4662 VkDescriptorPool ds_pool;
4663 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4664 ASSERT_VK_SUCCESS(err);
4665
4666 VkDescriptorSetLayoutBinding layout_binding;
4667 layout_binding.binding = 0;
4668 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4669 layout_binding.descriptorCount = 1;
4670 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4671 layout_binding.pImmutableSamplers = NULL;
4672
4673 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4674 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4675 ds_layout_ci.bindingCount = 1;
4676 ds_layout_ci.pBindings = &layout_binding;
4677 VkDescriptorSetLayout ds_layout;
4678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4679 ASSERT_VK_SUCCESS(err);
4680
4681 VkDescriptorSetAllocateInfo alloc_info = {};
4682 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4683 alloc_info.descriptorSetCount = 1;
4684 alloc_info.descriptorPool = ds_pool;
4685 alloc_info.pSetLayouts = &ds_layout;
4686 VkDescriptorSet descriptor_set;
4687 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4688 ASSERT_VK_SUCCESS(err);
4689
4690 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4691 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4692 pipeline_layout_ci.pNext = NULL;
4693 pipeline_layout_ci.setLayoutCount = 1;
4694 pipeline_layout_ci.pSetLayouts = &ds_layout;
4695
4696 VkPipelineLayout pipeline_layout;
4697 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4698 ASSERT_VK_SUCCESS(err);
4699
4700 VkBuffer buffer;
4701 uint32_t queue_family_index = 0;
4702 VkBufferCreateInfo buffer_create_info = {};
4703 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4704 buffer_create_info.size = 1024;
4705 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4706 buffer_create_info.queueFamilyIndexCount = 1;
4707 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4708
4709 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4710 ASSERT_VK_SUCCESS(err);
4711
4712 VkMemoryRequirements memory_reqs;
4713 VkDeviceMemory buffer_memory;
4714
4715 VkMemoryAllocateInfo memory_info = {};
4716 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4717 memory_info.allocationSize = 0;
4718 memory_info.memoryTypeIndex = 0;
4719
4720 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4721 memory_info.allocationSize = memory_reqs.size;
4722 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4723 ASSERT_TRUE(pass);
4724
4725 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4726 ASSERT_VK_SUCCESS(err);
4727 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4728 ASSERT_VK_SUCCESS(err);
4729
4730 VkBufferView view;
4731 VkBufferViewCreateInfo bvci = {};
4732 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4733 bvci.buffer = buffer;
4734 bvci.format = VK_FORMAT_R8_UNORM;
4735 bvci.range = VK_WHOLE_SIZE;
4736
4737 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4738 ASSERT_VK_SUCCESS(err);
4739
4740 VkWriteDescriptorSet descriptor_write = {};
4741 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4742 descriptor_write.dstSet = descriptor_set;
4743 descriptor_write.dstBinding = 0;
4744 descriptor_write.descriptorCount = 1;
4745 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4746 descriptor_write.pTexelBufferView = &view;
4747
4748 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4749
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004750 char const *vsSource =
4751 "#version 450\n"
4752 "\n"
4753 "out gl_PerVertex { \n"
4754 " vec4 gl_Position;\n"
4755 "};\n"
4756 "void main(){\n"
4757 " gl_Position = vec4(1);\n"
4758 "}\n";
4759 char const *fsSource =
4760 "#version 450\n"
4761 "\n"
4762 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4763 "layout(location=0) out vec4 x;\n"
4764 "void main(){\n"
4765 " x = imageLoad(s, 0);\n"
4766 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004767 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4769 VkPipelineObj pipe(m_device);
4770 pipe.AddShader(&vs);
4771 pipe.AddShader(&fs);
4772 pipe.AddColorAttachment();
4773 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4774
4775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4777
Tony Barbour552f6c02016-12-21 14:34:07 -07004778 m_commandBuffer->BeginCommandBuffer();
4779 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4780
Tobin Ehlisea413442016-09-28 10:23:59 -06004781 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4782 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4783 VkRect2D scissor = {{0, 0}, {16, 16}};
4784 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4785 // Bind pipeline to cmd buffer
4786 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4787 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4788 &descriptor_set, 0, nullptr);
4789 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004790 m_commandBuffer->EndRenderPass();
4791 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004792
4793 // Delete BufferView in order to invalidate cmd buffer
4794 vkDestroyBufferView(m_device->device(), view, NULL);
4795 // Now attempt submit of cmd buffer
4796 VkSubmitInfo submit_info = {};
4797 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4798 submit_info.commandBufferCount = 1;
4799 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4800 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4801 m_errorMonitor->VerifyFound();
4802
4803 // Clean-up
4804 vkDestroyBuffer(m_device->device(), buffer, NULL);
4805 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4806 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4807 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4808 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4809}
4810
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004811TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004812 TEST_DESCRIPTION(
4813 "Attempt to draw with a command buffer that is invalid "
4814 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004815 ASSERT_NO_FATAL_FAILURE(InitState());
4816
4817 VkImage image;
4818 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4819 VkImageCreateInfo image_create_info = {};
4820 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4821 image_create_info.pNext = NULL;
4822 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4823 image_create_info.format = tex_format;
4824 image_create_info.extent.width = 32;
4825 image_create_info.extent.height = 32;
4826 image_create_info.extent.depth = 1;
4827 image_create_info.mipLevels = 1;
4828 image_create_info.arrayLayers = 1;
4829 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4830 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004831 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004832 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004833 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004834 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004835 // Have to bind memory to image before recording cmd in cmd buffer using it
4836 VkMemoryRequirements mem_reqs;
4837 VkDeviceMemory image_mem;
4838 bool pass;
4839 VkMemoryAllocateInfo mem_alloc = {};
4840 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4841 mem_alloc.pNext = NULL;
4842 mem_alloc.memoryTypeIndex = 0;
4843 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4844 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004845 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004846 ASSERT_TRUE(pass);
4847 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4848 ASSERT_VK_SUCCESS(err);
4849 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4850 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004851
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004852 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004853 VkClearColorValue ccv;
4854 ccv.float32[0] = 1.0f;
4855 ccv.float32[1] = 1.0f;
4856 ccv.float32[2] = 1.0f;
4857 ccv.float32[3] = 1.0f;
4858 VkImageSubresourceRange isr = {};
4859 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004860 isr.baseArrayLayer = 0;
4861 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004862 isr.layerCount = 1;
4863 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004864 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004865 m_commandBuffer->EndCommandBuffer();
4866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004868 // Destroy image dependency prior to submit to cause ERROR
4869 vkDestroyImage(m_device->device(), image, NULL);
4870
4871 VkSubmitInfo submit_info = {};
4872 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4873 submit_info.commandBufferCount = 1;
4874 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004875 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004876 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4877
4878 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004879 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004880}
4881
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004882TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004883 TEST_DESCRIPTION(
4884 "Attempt to draw with a command buffer that is invalid "
4885 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004886 VkFormatProperties format_properties;
4887 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004888 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4889 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004890 return;
4891 }
4892
4893 ASSERT_NO_FATAL_FAILURE(InitState());
4894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4895
4896 VkImageCreateInfo image_ci = {};
4897 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4898 image_ci.pNext = NULL;
4899 image_ci.imageType = VK_IMAGE_TYPE_2D;
4900 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4901 image_ci.extent.width = 32;
4902 image_ci.extent.height = 32;
4903 image_ci.extent.depth = 1;
4904 image_ci.mipLevels = 1;
4905 image_ci.arrayLayers = 1;
4906 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4907 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004908 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004909 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4910 image_ci.flags = 0;
4911 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004912 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004913
4914 VkMemoryRequirements memory_reqs;
4915 VkDeviceMemory image_memory;
4916 bool pass;
4917 VkMemoryAllocateInfo memory_info = {};
4918 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4919 memory_info.pNext = NULL;
4920 memory_info.allocationSize = 0;
4921 memory_info.memoryTypeIndex = 0;
4922 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4923 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004924 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004925 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004926 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004927 ASSERT_VK_SUCCESS(err);
4928 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4929 ASSERT_VK_SUCCESS(err);
4930
4931 VkImageViewCreateInfo ivci = {
4932 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4933 nullptr,
4934 0,
4935 image,
4936 VK_IMAGE_VIEW_TYPE_2D,
4937 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004938 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004939 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4940 };
4941 VkImageView view;
4942 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4943 ASSERT_VK_SUCCESS(err);
4944
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004945 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004946 VkFramebuffer fb;
4947 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4948 ASSERT_VK_SUCCESS(err);
4949
4950 // Just use default renderpass with our framebuffer
4951 m_renderPassBeginInfo.framebuffer = fb;
4952 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004953 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004954 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07004955 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4956 m_commandBuffer->EndRenderPass();
4957 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004958 // Destroy image attached to framebuffer to invalidate cmd buffer
4959 vkDestroyImage(m_device->device(), image, NULL);
4960 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004962 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004963 QueueCommandBuffer(false);
4964 m_errorMonitor->VerifyFound();
4965
4966 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4967 vkDestroyImageView(m_device->device(), view, nullptr);
4968 vkFreeMemory(m_device->device(), image_memory, nullptr);
4969}
4970
Tobin Ehlisb329f992016-10-12 13:20:29 -06004971TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4972 TEST_DESCRIPTION("Delete in-use framebuffer.");
4973 VkFormatProperties format_properties;
4974 VkResult err = VK_SUCCESS;
4975 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4976
4977 ASSERT_NO_FATAL_FAILURE(InitState());
4978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4979
4980 VkImageObj image(m_device);
4981 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4982 ASSERT_TRUE(image.initialized());
4983 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4984
4985 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4986 VkFramebuffer fb;
4987 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4988 ASSERT_VK_SUCCESS(err);
4989
4990 // Just use default renderpass with our framebuffer
4991 m_renderPassBeginInfo.framebuffer = fb;
4992 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004993 m_commandBuffer->BeginCommandBuffer();
4994 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4995 m_commandBuffer->EndRenderPass();
4996 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004997 // Submit cmd buffer to put it in-flight
4998 VkSubmitInfo submit_info = {};
4999 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5000 submit_info.commandBufferCount = 1;
5001 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5002 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5003 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005005 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5006 m_errorMonitor->VerifyFound();
5007 // Wait for queue to complete so we can safely destroy everything
5008 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005009 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5010 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005011 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5012}
5013
Tobin Ehlis88becd72016-09-21 14:33:41 -06005014TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5015 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5016 VkFormatProperties format_properties;
5017 VkResult err = VK_SUCCESS;
5018 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005019
5020 ASSERT_NO_FATAL_FAILURE(InitState());
5021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5022
5023 VkImageCreateInfo image_ci = {};
5024 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5025 image_ci.pNext = NULL;
5026 image_ci.imageType = VK_IMAGE_TYPE_2D;
5027 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5028 image_ci.extent.width = 256;
5029 image_ci.extent.height = 256;
5030 image_ci.extent.depth = 1;
5031 image_ci.mipLevels = 1;
5032 image_ci.arrayLayers = 1;
5033 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5034 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005035 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005036 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5037 image_ci.flags = 0;
5038 VkImage image;
5039 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5040
5041 VkMemoryRequirements memory_reqs;
5042 VkDeviceMemory image_memory;
5043 bool pass;
5044 VkMemoryAllocateInfo memory_info = {};
5045 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5046 memory_info.pNext = NULL;
5047 memory_info.allocationSize = 0;
5048 memory_info.memoryTypeIndex = 0;
5049 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5050 memory_info.allocationSize = memory_reqs.size;
5051 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5052 ASSERT_TRUE(pass);
5053 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5054 ASSERT_VK_SUCCESS(err);
5055 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5056 ASSERT_VK_SUCCESS(err);
5057
5058 VkImageViewCreateInfo ivci = {
5059 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5060 nullptr,
5061 0,
5062 image,
5063 VK_IMAGE_VIEW_TYPE_2D,
5064 VK_FORMAT_B8G8R8A8_UNORM,
5065 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5066 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5067 };
5068 VkImageView view;
5069 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5070 ASSERT_VK_SUCCESS(err);
5071
5072 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5073 VkFramebuffer fb;
5074 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5075 ASSERT_VK_SUCCESS(err);
5076
5077 // Just use default renderpass with our framebuffer
5078 m_renderPassBeginInfo.framebuffer = fb;
5079 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005080 m_commandBuffer->BeginCommandBuffer();
5081 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5082 m_commandBuffer->EndRenderPass();
5083 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005084 // Submit cmd buffer to put it (and attached imageView) in-flight
5085 VkSubmitInfo submit_info = {};
5086 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5087 submit_info.commandBufferCount = 1;
5088 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5089 // Submit cmd buffer to put framebuffer and children in-flight
5090 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5091 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005093 vkDestroyImage(m_device->device(), image, NULL);
5094 m_errorMonitor->VerifyFound();
5095 // Wait for queue to complete so we can safely destroy image and other objects
5096 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005097 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5098 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005099 vkDestroyImage(m_device->device(), image, NULL);
5100 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5101 vkDestroyImageView(m_device->device(), view, nullptr);
5102 vkFreeMemory(m_device->device(), image_memory, nullptr);
5103}
5104
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005105TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5106 TEST_DESCRIPTION("Delete in-use renderPass.");
5107
5108 ASSERT_NO_FATAL_FAILURE(InitState());
5109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5110
5111 // Create simple renderpass
5112 VkAttachmentReference attach = {};
5113 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5114 VkSubpassDescription subpass = {};
5115 subpass.pColorAttachments = &attach;
5116 VkRenderPassCreateInfo rpci = {};
5117 rpci.subpassCount = 1;
5118 rpci.pSubpasses = &subpass;
5119 rpci.attachmentCount = 1;
5120 VkAttachmentDescription attach_desc = {};
5121 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5122 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5123 rpci.pAttachments = &attach_desc;
5124 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5125 VkRenderPass rp;
5126 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5127 ASSERT_VK_SUCCESS(err);
5128
5129 // Create a pipeline that uses the given renderpass
5130 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5131 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5132
5133 VkPipelineLayout pipeline_layout;
5134 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5135 ASSERT_VK_SUCCESS(err);
5136
5137 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5138 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5139 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005140 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005141 vp_state_ci.pViewports = &vp;
5142 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005143 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005144 vp_state_ci.pScissors = &scissors;
5145
5146 VkPipelineShaderStageCreateInfo shaderStages[2];
5147 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5148
5149 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005150 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 -06005151 // but add it to be able to run on more devices
5152 shaderStages[0] = vs.GetStageCreateInfo();
5153 shaderStages[1] = fs.GetStageCreateInfo();
5154
5155 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5156 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5157
5158 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5159 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5160 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5161
5162 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5163 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5164 rs_ci.rasterizerDiscardEnable = true;
5165 rs_ci.lineWidth = 1.0f;
5166
5167 VkPipelineColorBlendAttachmentState att = {};
5168 att.blendEnable = VK_FALSE;
5169 att.colorWriteMask = 0xf;
5170
5171 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5172 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5173 cb_ci.attachmentCount = 1;
5174 cb_ci.pAttachments = &att;
5175
5176 VkGraphicsPipelineCreateInfo gp_ci = {};
5177 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5178 gp_ci.stageCount = 2;
5179 gp_ci.pStages = shaderStages;
5180 gp_ci.pVertexInputState = &vi_ci;
5181 gp_ci.pInputAssemblyState = &ia_ci;
5182 gp_ci.pViewportState = &vp_state_ci;
5183 gp_ci.pRasterizationState = &rs_ci;
5184 gp_ci.pColorBlendState = &cb_ci;
5185 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5186 gp_ci.layout = pipeline_layout;
5187 gp_ci.renderPass = rp;
5188
5189 VkPipelineCacheCreateInfo pc_ci = {};
5190 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5191
5192 VkPipeline pipeline;
5193 VkPipelineCache pipe_cache;
5194 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5195 ASSERT_VK_SUCCESS(err);
5196
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005197 m_errorMonitor->SetUnexpectedError(
5198 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5199 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005200 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5201 ASSERT_VK_SUCCESS(err);
5202 // Bind pipeline to cmd buffer, will also bind renderpass
5203 m_commandBuffer->BeginCommandBuffer();
5204 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5205 m_commandBuffer->EndCommandBuffer();
5206
5207 VkSubmitInfo submit_info = {};
5208 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5209 submit_info.commandBufferCount = 1;
5210 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5211 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5212
5213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5214 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5215 m_errorMonitor->VerifyFound();
5216
5217 // Wait for queue to complete so we can safely destroy everything
5218 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005219 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5220 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005221 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5222 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5223 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5224 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5225}
5226
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005227TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005228 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005229 ASSERT_NO_FATAL_FAILURE(InitState());
5230
5231 VkImage image;
5232 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5233 VkImageCreateInfo image_create_info = {};
5234 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5235 image_create_info.pNext = NULL;
5236 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5237 image_create_info.format = tex_format;
5238 image_create_info.extent.width = 32;
5239 image_create_info.extent.height = 32;
5240 image_create_info.extent.depth = 1;
5241 image_create_info.mipLevels = 1;
5242 image_create_info.arrayLayers = 1;
5243 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5244 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005245 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005246 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005247 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005248 ASSERT_VK_SUCCESS(err);
5249 // Have to bind memory to image before recording cmd in cmd buffer using it
5250 VkMemoryRequirements mem_reqs;
5251 VkDeviceMemory image_mem;
5252 bool pass;
5253 VkMemoryAllocateInfo mem_alloc = {};
5254 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5255 mem_alloc.pNext = NULL;
5256 mem_alloc.memoryTypeIndex = 0;
5257 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5258 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005259 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005260 ASSERT_TRUE(pass);
5261 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5262 ASSERT_VK_SUCCESS(err);
5263
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005264 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005266 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005267
5268 m_commandBuffer->BeginCommandBuffer();
5269 VkClearColorValue ccv;
5270 ccv.float32[0] = 1.0f;
5271 ccv.float32[1] = 1.0f;
5272 ccv.float32[2] = 1.0f;
5273 ccv.float32[3] = 1.0f;
5274 VkImageSubresourceRange isr = {};
5275 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5276 isr.baseArrayLayer = 0;
5277 isr.baseMipLevel = 0;
5278 isr.layerCount = 1;
5279 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005280 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005281 m_commandBuffer->EndCommandBuffer();
5282
5283 m_errorMonitor->VerifyFound();
5284 vkDestroyImage(m_device->device(), image, NULL);
5285 vkFreeMemory(m_device->device(), image_mem, nullptr);
5286}
5287
5288TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005289 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005290 ASSERT_NO_FATAL_FAILURE(InitState());
5291
5292 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005293 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 -06005294 VK_IMAGE_TILING_OPTIMAL, 0);
5295 ASSERT_TRUE(image.initialized());
5296
5297 VkBuffer buffer;
5298 VkDeviceMemory mem;
5299 VkMemoryRequirements mem_reqs;
5300
5301 VkBufferCreateInfo buf_info = {};
5302 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005303 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005304 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005305 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5306 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5307 ASSERT_VK_SUCCESS(err);
5308
5309 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5310
5311 VkMemoryAllocateInfo alloc_info = {};
5312 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005313 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005314 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005315 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 -06005316 if (!pass) {
5317 vkDestroyBuffer(m_device->device(), buffer, NULL);
5318 return;
5319 }
5320 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5321 ASSERT_VK_SUCCESS(err);
5322
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005323 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005325 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005326 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005327 region.bufferRowLength = 16;
5328 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005329 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5330
5331 region.imageSubresource.layerCount = 1;
5332 region.imageExtent.height = 4;
5333 region.imageExtent.width = 4;
5334 region.imageExtent.depth = 1;
5335 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005336 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5337 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005338 m_commandBuffer->EndCommandBuffer();
5339
5340 m_errorMonitor->VerifyFound();
5341
5342 vkDestroyBuffer(m_device->device(), buffer, NULL);
5343 vkFreeMemory(m_device->handle(), mem, NULL);
5344}
5345
Tobin Ehlis85940f52016-07-07 16:57:21 -06005346TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005347 TEST_DESCRIPTION(
5348 "Attempt to draw with a command buffer that is invalid "
5349 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005350 ASSERT_NO_FATAL_FAILURE(InitState());
5351
5352 VkEvent event;
5353 VkEventCreateInfo evci = {};
5354 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5355 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5356 ASSERT_VK_SUCCESS(result);
5357
5358 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005359 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005360 m_commandBuffer->EndCommandBuffer();
5361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005363 // Destroy event dependency prior to submit to cause ERROR
5364 vkDestroyEvent(m_device->device(), event, NULL);
5365
5366 VkSubmitInfo submit_info = {};
5367 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5368 submit_info.commandBufferCount = 1;
5369 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005370 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted event");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005371 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5372
5373 m_errorMonitor->VerifyFound();
5374}
5375
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005376TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005377 TEST_DESCRIPTION(
5378 "Attempt to draw with a command buffer that is invalid "
5379 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005380 ASSERT_NO_FATAL_FAILURE(InitState());
5381
5382 VkQueryPool query_pool;
5383 VkQueryPoolCreateInfo qpci{};
5384 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5385 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5386 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005387 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005388 ASSERT_VK_SUCCESS(result);
5389
5390 m_commandBuffer->BeginCommandBuffer();
5391 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5392 m_commandBuffer->EndCommandBuffer();
5393
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005395 // Destroy query pool dependency prior to submit to cause ERROR
5396 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5397
5398 VkSubmitInfo submit_info = {};
5399 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5400 submit_info.commandBufferCount = 1;
5401 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005402 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted query pool");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005403 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5404
5405 m_errorMonitor->VerifyFound();
5406}
5407
Tobin Ehlis24130d92016-07-08 15:50:53 -06005408TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005409 TEST_DESCRIPTION(
5410 "Attempt to draw with a command buffer that is invalid "
5411 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005412 ASSERT_NO_FATAL_FAILURE(InitState());
5413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5414
5415 VkResult err;
5416
5417 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5418 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5419
5420 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005421 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005422 ASSERT_VK_SUCCESS(err);
5423
5424 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5425 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5426 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005427 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005428 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005429 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005430 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005431 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005432
5433 VkPipelineShaderStageCreateInfo shaderStages[2];
5434 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5435
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005436 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005437 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 -06005438 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005439 shaderStages[0] = vs.GetStageCreateInfo();
5440 shaderStages[1] = fs.GetStageCreateInfo();
5441
5442 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5443 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5444
5445 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5446 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5447 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5448
5449 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5450 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005451 rs_ci.rasterizerDiscardEnable = true;
5452 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005453
5454 VkPipelineColorBlendAttachmentState att = {};
5455 att.blendEnable = VK_FALSE;
5456 att.colorWriteMask = 0xf;
5457
5458 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5459 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5460 cb_ci.attachmentCount = 1;
5461 cb_ci.pAttachments = &att;
5462
5463 VkGraphicsPipelineCreateInfo gp_ci = {};
5464 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5465 gp_ci.stageCount = 2;
5466 gp_ci.pStages = shaderStages;
5467 gp_ci.pVertexInputState = &vi_ci;
5468 gp_ci.pInputAssemblyState = &ia_ci;
5469 gp_ci.pViewportState = &vp_state_ci;
5470 gp_ci.pRasterizationState = &rs_ci;
5471 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005472 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5473 gp_ci.layout = pipeline_layout;
5474 gp_ci.renderPass = renderPass();
5475
5476 VkPipelineCacheCreateInfo pc_ci = {};
5477 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5478
5479 VkPipeline pipeline;
5480 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005481 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005482 ASSERT_VK_SUCCESS(err);
5483
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005484 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005485 ASSERT_VK_SUCCESS(err);
5486
5487 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005488 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005489 m_commandBuffer->EndCommandBuffer();
5490 // Now destroy pipeline in order to cause error when submitting
5491 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5492
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005494
5495 VkSubmitInfo submit_info = {};
5496 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5497 submit_info.commandBufferCount = 1;
5498 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005499 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted pipeline");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005500 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5501
5502 m_errorMonitor->VerifyFound();
5503 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5504 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5505}
5506
Tobin Ehlis31289162016-08-17 14:57:58 -06005507TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005508 TEST_DESCRIPTION(
5509 "Attempt to draw with a command buffer that is invalid "
5510 "due to a bound descriptor set with a buffer dependency "
5511 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005512 ASSERT_NO_FATAL_FAILURE(InitState());
5513 ASSERT_NO_FATAL_FAILURE(InitViewport());
5514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5515
5516 VkDescriptorPoolSize ds_type_count = {};
5517 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5518 ds_type_count.descriptorCount = 1;
5519
5520 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5521 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5522 ds_pool_ci.pNext = NULL;
5523 ds_pool_ci.maxSets = 1;
5524 ds_pool_ci.poolSizeCount = 1;
5525 ds_pool_ci.pPoolSizes = &ds_type_count;
5526
5527 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005528 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005529 ASSERT_VK_SUCCESS(err);
5530
5531 VkDescriptorSetLayoutBinding dsl_binding = {};
5532 dsl_binding.binding = 0;
5533 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5534 dsl_binding.descriptorCount = 1;
5535 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5536 dsl_binding.pImmutableSamplers = NULL;
5537
5538 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5539 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5540 ds_layout_ci.pNext = NULL;
5541 ds_layout_ci.bindingCount = 1;
5542 ds_layout_ci.pBindings = &dsl_binding;
5543 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005544 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005545 ASSERT_VK_SUCCESS(err);
5546
5547 VkDescriptorSet descriptorSet;
5548 VkDescriptorSetAllocateInfo alloc_info = {};
5549 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5550 alloc_info.descriptorSetCount = 1;
5551 alloc_info.descriptorPool = ds_pool;
5552 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005553 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005554 ASSERT_VK_SUCCESS(err);
5555
5556 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5557 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5558 pipeline_layout_ci.pNext = NULL;
5559 pipeline_layout_ci.setLayoutCount = 1;
5560 pipeline_layout_ci.pSetLayouts = &ds_layout;
5561
5562 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005563 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005564 ASSERT_VK_SUCCESS(err);
5565
5566 // Create a buffer to update the descriptor with
5567 uint32_t qfi = 0;
5568 VkBufferCreateInfo buffCI = {};
5569 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5570 buffCI.size = 1024;
5571 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5572 buffCI.queueFamilyIndexCount = 1;
5573 buffCI.pQueueFamilyIndices = &qfi;
5574
5575 VkBuffer buffer;
5576 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5577 ASSERT_VK_SUCCESS(err);
5578 // Allocate memory and bind to buffer so we can make it to the appropriate
5579 // error
5580 VkMemoryAllocateInfo mem_alloc = {};
5581 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5582 mem_alloc.pNext = NULL;
5583 mem_alloc.allocationSize = 1024;
5584 mem_alloc.memoryTypeIndex = 0;
5585
5586 VkMemoryRequirements memReqs;
5587 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005588 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005589 if (!pass) {
5590 vkDestroyBuffer(m_device->device(), buffer, NULL);
5591 return;
5592 }
5593
5594 VkDeviceMemory mem;
5595 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5596 ASSERT_VK_SUCCESS(err);
5597 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5598 ASSERT_VK_SUCCESS(err);
5599 // Correctly update descriptor to avoid "NOT_UPDATED" error
5600 VkDescriptorBufferInfo buffInfo = {};
5601 buffInfo.buffer = buffer;
5602 buffInfo.offset = 0;
5603 buffInfo.range = 1024;
5604
5605 VkWriteDescriptorSet descriptor_write;
5606 memset(&descriptor_write, 0, sizeof(descriptor_write));
5607 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5608 descriptor_write.dstSet = descriptorSet;
5609 descriptor_write.dstBinding = 0;
5610 descriptor_write.descriptorCount = 1;
5611 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5612 descriptor_write.pBufferInfo = &buffInfo;
5613
5614 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5615
5616 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005617 char const *vsSource =
5618 "#version 450\n"
5619 "\n"
5620 "out gl_PerVertex { \n"
5621 " vec4 gl_Position;\n"
5622 "};\n"
5623 "void main(){\n"
5624 " gl_Position = vec4(1);\n"
5625 "}\n";
5626 char const *fsSource =
5627 "#version 450\n"
5628 "\n"
5629 "layout(location=0) out vec4 x;\n"
5630 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5631 "void main(){\n"
5632 " x = vec4(bar.y);\n"
5633 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005634 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5635 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5636 VkPipelineObj pipe(m_device);
5637 pipe.AddShader(&vs);
5638 pipe.AddShader(&fs);
5639 pipe.AddColorAttachment();
5640 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5641
Tony Barbour552f6c02016-12-21 14:34:07 -07005642 m_commandBuffer->BeginCommandBuffer();
5643 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5645 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5646 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005647
5648 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5649 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5650
Tobin Ehlis31289162016-08-17 14:57:58 -06005651 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005652 m_commandBuffer->EndRenderPass();
5653 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005655 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5656 vkDestroyBuffer(m_device->device(), buffer, NULL);
5657 // Attempt to submit cmd buffer
5658 VkSubmitInfo submit_info = {};
5659 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5660 submit_info.commandBufferCount = 1;
5661 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005662 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis31289162016-08-17 14:57:58 -06005663 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5664 m_errorMonitor->VerifyFound();
5665 // Cleanup
5666 vkFreeMemory(m_device->device(), mem, NULL);
5667
5668 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5669 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5670 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5671}
5672
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005673TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005674 TEST_DESCRIPTION(
5675 "Attempt to draw with a command buffer that is invalid "
5676 "due to a bound descriptor sets with a combined image "
5677 "sampler having their image, sampler, and descriptor set "
5678 "each respectively destroyed and then attempting to "
5679 "submit associated cmd buffers. Attempt to destroy a "
5680 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005681 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005682 ASSERT_NO_FATAL_FAILURE(InitViewport());
5683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5684
5685 VkDescriptorPoolSize ds_type_count = {};
5686 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5687 ds_type_count.descriptorCount = 1;
5688
5689 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5690 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5691 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005692 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005693 ds_pool_ci.maxSets = 1;
5694 ds_pool_ci.poolSizeCount = 1;
5695 ds_pool_ci.pPoolSizes = &ds_type_count;
5696
5697 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005698 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005699 ASSERT_VK_SUCCESS(err);
5700
5701 VkDescriptorSetLayoutBinding dsl_binding = {};
5702 dsl_binding.binding = 0;
5703 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5704 dsl_binding.descriptorCount = 1;
5705 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5706 dsl_binding.pImmutableSamplers = NULL;
5707
5708 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5709 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5710 ds_layout_ci.pNext = NULL;
5711 ds_layout_ci.bindingCount = 1;
5712 ds_layout_ci.pBindings = &dsl_binding;
5713 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005714 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005715 ASSERT_VK_SUCCESS(err);
5716
5717 VkDescriptorSet descriptorSet;
5718 VkDescriptorSetAllocateInfo alloc_info = {};
5719 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5720 alloc_info.descriptorSetCount = 1;
5721 alloc_info.descriptorPool = ds_pool;
5722 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005723 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005724 ASSERT_VK_SUCCESS(err);
5725
5726 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5727 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5728 pipeline_layout_ci.pNext = NULL;
5729 pipeline_layout_ci.setLayoutCount = 1;
5730 pipeline_layout_ci.pSetLayouts = &ds_layout;
5731
5732 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005733 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005734 ASSERT_VK_SUCCESS(err);
5735
5736 // Create images to update the descriptor with
5737 VkImage image;
5738 VkImage image2;
5739 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5740 const int32_t tex_width = 32;
5741 const int32_t tex_height = 32;
5742 VkImageCreateInfo image_create_info = {};
5743 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5744 image_create_info.pNext = NULL;
5745 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5746 image_create_info.format = tex_format;
5747 image_create_info.extent.width = tex_width;
5748 image_create_info.extent.height = tex_height;
5749 image_create_info.extent.depth = 1;
5750 image_create_info.mipLevels = 1;
5751 image_create_info.arrayLayers = 1;
5752 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5753 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5754 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5755 image_create_info.flags = 0;
5756 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5757 ASSERT_VK_SUCCESS(err);
5758 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5759 ASSERT_VK_SUCCESS(err);
5760
5761 VkMemoryRequirements memory_reqs;
5762 VkDeviceMemory image_memory;
5763 bool pass;
5764 VkMemoryAllocateInfo memory_info = {};
5765 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5766 memory_info.pNext = NULL;
5767 memory_info.allocationSize = 0;
5768 memory_info.memoryTypeIndex = 0;
5769 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5770 // Allocate enough memory for both images
5771 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005772 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005773 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005774 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005775 ASSERT_VK_SUCCESS(err);
5776 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5777 ASSERT_VK_SUCCESS(err);
5778 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005779 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005780 ASSERT_VK_SUCCESS(err);
5781
5782 VkImageViewCreateInfo image_view_create_info = {};
5783 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5784 image_view_create_info.image = image;
5785 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5786 image_view_create_info.format = tex_format;
5787 image_view_create_info.subresourceRange.layerCount = 1;
5788 image_view_create_info.subresourceRange.baseMipLevel = 0;
5789 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005790 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005791
5792 VkImageView view;
5793 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005795 ASSERT_VK_SUCCESS(err);
5796 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005797 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005798 ASSERT_VK_SUCCESS(err);
5799 // Create Samplers
5800 VkSamplerCreateInfo sampler_ci = {};
5801 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5802 sampler_ci.pNext = NULL;
5803 sampler_ci.magFilter = VK_FILTER_NEAREST;
5804 sampler_ci.minFilter = VK_FILTER_NEAREST;
5805 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5806 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5807 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5808 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5809 sampler_ci.mipLodBias = 1.0;
5810 sampler_ci.anisotropyEnable = VK_FALSE;
5811 sampler_ci.maxAnisotropy = 1;
5812 sampler_ci.compareEnable = VK_FALSE;
5813 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5814 sampler_ci.minLod = 1.0;
5815 sampler_ci.maxLod = 1.0;
5816 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5817 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5818 VkSampler sampler;
5819 VkSampler sampler2;
5820 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5821 ASSERT_VK_SUCCESS(err);
5822 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5823 ASSERT_VK_SUCCESS(err);
5824 // Update descriptor with image and sampler
5825 VkDescriptorImageInfo img_info = {};
5826 img_info.sampler = sampler;
5827 img_info.imageView = view;
5828 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5829
5830 VkWriteDescriptorSet descriptor_write;
5831 memset(&descriptor_write, 0, sizeof(descriptor_write));
5832 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5833 descriptor_write.dstSet = descriptorSet;
5834 descriptor_write.dstBinding = 0;
5835 descriptor_write.descriptorCount = 1;
5836 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5837 descriptor_write.pImageInfo = &img_info;
5838
5839 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5840
5841 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005842 char const *vsSource =
5843 "#version 450\n"
5844 "\n"
5845 "out gl_PerVertex { \n"
5846 " vec4 gl_Position;\n"
5847 "};\n"
5848 "void main(){\n"
5849 " gl_Position = vec4(1);\n"
5850 "}\n";
5851 char const *fsSource =
5852 "#version 450\n"
5853 "\n"
5854 "layout(set=0, binding=0) uniform sampler2D s;\n"
5855 "layout(location=0) out vec4 x;\n"
5856 "void main(){\n"
5857 " x = texture(s, vec2(1));\n"
5858 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005859 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5860 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5861 VkPipelineObj pipe(m_device);
5862 pipe.AddShader(&vs);
5863 pipe.AddShader(&fs);
5864 pipe.AddColorAttachment();
5865 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5866
5867 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005869 m_commandBuffer->BeginCommandBuffer();
5870 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005871 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5872 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5873 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005874 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5875 VkRect2D scissor = {{0, 0}, {16, 16}};
5876 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5877 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005878 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005879 m_commandBuffer->EndRenderPass();
5880 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005881 // Destroy sampler invalidates the cmd buffer, causing error on submit
5882 vkDestroySampler(m_device->device(), sampler, NULL);
5883 // Attempt to submit cmd buffer
5884 VkSubmitInfo submit_info = {};
5885 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5886 submit_info.commandBufferCount = 1;
5887 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005888 m_errorMonitor->SetUnexpectedError("that is invalid because bound sampler");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005889 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5890 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005891
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005892 // Now re-update descriptor with valid sampler and delete image
5893 img_info.sampler = sampler2;
5894 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005895
5896 VkCommandBufferBeginInfo info = {};
5897 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5898 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5899
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005901 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005902 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005903 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5904 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5905 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005906 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5907 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005908 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005909 m_commandBuffer->EndRenderPass();
5910 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005911 // Destroy image invalidates the cmd buffer, causing error on submit
5912 vkDestroyImage(m_device->device(), image, NULL);
5913 // Attempt to submit cmd buffer
5914 submit_info = {};
5915 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5916 submit_info.commandBufferCount = 1;
5917 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005918 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005919 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5920 m_errorMonitor->VerifyFound();
5921 // Now update descriptor to be valid, but then free descriptor
5922 img_info.imageView = view2;
5923 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005924 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005925 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005926 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5927 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5928 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005929 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5930 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005931 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005932 m_commandBuffer->EndRenderPass();
5933 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005935
5936 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005938 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005939 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005940
5941 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005942 // 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 -07005943 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005944 m_errorMonitor->SetUnexpectedError(
5945 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
5946 "either be a valid handle or VK_NULL_HANDLE");
5947 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07005948 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5949
5950 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005951 submit_info = {};
5952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5953 submit_info.commandBufferCount = 1;
5954 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005956 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted descriptor set");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005957 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5958 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005959
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005960 // Cleanup
5961 vkFreeMemory(m_device->device(), image_memory, NULL);
5962 vkDestroySampler(m_device->device(), sampler2, NULL);
5963 vkDestroyImage(m_device->device(), image2, NULL);
5964 vkDestroyImageView(m_device->device(), view, NULL);
5965 vkDestroyImageView(m_device->device(), view2, NULL);
5966 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5967 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5968 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5969}
5970
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005971TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5972 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5973 ASSERT_NO_FATAL_FAILURE(InitState());
5974 ASSERT_NO_FATAL_FAILURE(InitViewport());
5975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5976
5977 VkDescriptorPoolSize ds_type_count = {};
5978 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5979 ds_type_count.descriptorCount = 1;
5980
5981 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5982 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5983 ds_pool_ci.pNext = NULL;
5984 ds_pool_ci.maxSets = 1;
5985 ds_pool_ci.poolSizeCount = 1;
5986 ds_pool_ci.pPoolSizes = &ds_type_count;
5987
5988 VkDescriptorPool ds_pool;
5989 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5990 ASSERT_VK_SUCCESS(err);
5991
5992 VkDescriptorSetLayoutBinding dsl_binding = {};
5993 dsl_binding.binding = 0;
5994 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5995 dsl_binding.descriptorCount = 1;
5996 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5997 dsl_binding.pImmutableSamplers = NULL;
5998
5999 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6000 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6001 ds_layout_ci.pNext = NULL;
6002 ds_layout_ci.bindingCount = 1;
6003 ds_layout_ci.pBindings = &dsl_binding;
6004 VkDescriptorSetLayout ds_layout;
6005 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6006 ASSERT_VK_SUCCESS(err);
6007
6008 VkDescriptorSet descriptor_set;
6009 VkDescriptorSetAllocateInfo alloc_info = {};
6010 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6011 alloc_info.descriptorSetCount = 1;
6012 alloc_info.descriptorPool = ds_pool;
6013 alloc_info.pSetLayouts = &ds_layout;
6014 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6015 ASSERT_VK_SUCCESS(err);
6016
6017 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6018 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6019 pipeline_layout_ci.pNext = NULL;
6020 pipeline_layout_ci.setLayoutCount = 1;
6021 pipeline_layout_ci.pSetLayouts = &ds_layout;
6022
6023 VkPipelineLayout pipeline_layout;
6024 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6025 ASSERT_VK_SUCCESS(err);
6026
6027 // Create image to update the descriptor with
6028 VkImageObj image(m_device);
6029 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6030 ASSERT_TRUE(image.initialized());
6031
6032 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6033 // Create Sampler
6034 VkSamplerCreateInfo sampler_ci = {};
6035 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6036 sampler_ci.pNext = NULL;
6037 sampler_ci.magFilter = VK_FILTER_NEAREST;
6038 sampler_ci.minFilter = VK_FILTER_NEAREST;
6039 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6040 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6041 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6042 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6043 sampler_ci.mipLodBias = 1.0;
6044 sampler_ci.anisotropyEnable = VK_FALSE;
6045 sampler_ci.maxAnisotropy = 1;
6046 sampler_ci.compareEnable = VK_FALSE;
6047 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6048 sampler_ci.minLod = 1.0;
6049 sampler_ci.maxLod = 1.0;
6050 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6051 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6052 VkSampler sampler;
6053 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6054 ASSERT_VK_SUCCESS(err);
6055 // Update descriptor with image and sampler
6056 VkDescriptorImageInfo img_info = {};
6057 img_info.sampler = sampler;
6058 img_info.imageView = view;
6059 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6060
6061 VkWriteDescriptorSet descriptor_write;
6062 memset(&descriptor_write, 0, sizeof(descriptor_write));
6063 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6064 descriptor_write.dstSet = descriptor_set;
6065 descriptor_write.dstBinding = 0;
6066 descriptor_write.descriptorCount = 1;
6067 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6068 descriptor_write.pImageInfo = &img_info;
6069
6070 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6071
6072 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006073 char const *vsSource =
6074 "#version 450\n"
6075 "\n"
6076 "out gl_PerVertex { \n"
6077 " vec4 gl_Position;\n"
6078 "};\n"
6079 "void main(){\n"
6080 " gl_Position = vec4(1);\n"
6081 "}\n";
6082 char const *fsSource =
6083 "#version 450\n"
6084 "\n"
6085 "layout(set=0, binding=0) uniform sampler2D s;\n"
6086 "layout(location=0) out vec4 x;\n"
6087 "void main(){\n"
6088 " x = texture(s, vec2(1));\n"
6089 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006090 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6091 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6092 VkPipelineObj pipe(m_device);
6093 pipe.AddShader(&vs);
6094 pipe.AddShader(&fs);
6095 pipe.AddColorAttachment();
6096 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6097
Tony Barbour552f6c02016-12-21 14:34:07 -07006098 m_commandBuffer->BeginCommandBuffer();
6099 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006100 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6101 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6102 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006103
6104 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6105 VkRect2D scissor = {{0, 0}, {16, 16}};
6106 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6107 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6108
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006109 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006110 m_commandBuffer->EndRenderPass();
6111 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006112 // Submit cmd buffer to put pool in-flight
6113 VkSubmitInfo submit_info = {};
6114 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6115 submit_info.commandBufferCount = 1;
6116 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6117 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6118 // Destroy pool while in-flight, causing error
6119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6120 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6121 m_errorMonitor->VerifyFound();
6122 vkQueueWaitIdle(m_device->m_queue);
6123 // Cleanup
6124 vkDestroySampler(m_device->device(), sampler, NULL);
6125 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006127 m_errorMonitor->SetUnexpectedError(
6128 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6129 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006130 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006131 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006132}
6133
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006134TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6135 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6136 ASSERT_NO_FATAL_FAILURE(InitState());
6137 ASSERT_NO_FATAL_FAILURE(InitViewport());
6138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6139
6140 VkDescriptorPoolSize ds_type_count = {};
6141 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6142 ds_type_count.descriptorCount = 1;
6143
6144 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6145 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6146 ds_pool_ci.pNext = NULL;
6147 ds_pool_ci.maxSets = 1;
6148 ds_pool_ci.poolSizeCount = 1;
6149 ds_pool_ci.pPoolSizes = &ds_type_count;
6150
6151 VkDescriptorPool ds_pool;
6152 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6153 ASSERT_VK_SUCCESS(err);
6154
6155 VkDescriptorSetLayoutBinding dsl_binding = {};
6156 dsl_binding.binding = 0;
6157 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6158 dsl_binding.descriptorCount = 1;
6159 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6160 dsl_binding.pImmutableSamplers = NULL;
6161
6162 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6163 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6164 ds_layout_ci.pNext = NULL;
6165 ds_layout_ci.bindingCount = 1;
6166 ds_layout_ci.pBindings = &dsl_binding;
6167 VkDescriptorSetLayout ds_layout;
6168 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6169 ASSERT_VK_SUCCESS(err);
6170
6171 VkDescriptorSet descriptorSet;
6172 VkDescriptorSetAllocateInfo alloc_info = {};
6173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6174 alloc_info.descriptorSetCount = 1;
6175 alloc_info.descriptorPool = ds_pool;
6176 alloc_info.pSetLayouts = &ds_layout;
6177 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6178 ASSERT_VK_SUCCESS(err);
6179
6180 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6181 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6182 pipeline_layout_ci.pNext = NULL;
6183 pipeline_layout_ci.setLayoutCount = 1;
6184 pipeline_layout_ci.pSetLayouts = &ds_layout;
6185
6186 VkPipelineLayout pipeline_layout;
6187 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6188 ASSERT_VK_SUCCESS(err);
6189
6190 // Create images to update the descriptor with
6191 VkImage image;
6192 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6193 const int32_t tex_width = 32;
6194 const int32_t tex_height = 32;
6195 VkImageCreateInfo image_create_info = {};
6196 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6197 image_create_info.pNext = NULL;
6198 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6199 image_create_info.format = tex_format;
6200 image_create_info.extent.width = tex_width;
6201 image_create_info.extent.height = tex_height;
6202 image_create_info.extent.depth = 1;
6203 image_create_info.mipLevels = 1;
6204 image_create_info.arrayLayers = 1;
6205 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6206 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6207 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6208 image_create_info.flags = 0;
6209 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6210 ASSERT_VK_SUCCESS(err);
6211 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6212 VkMemoryRequirements memory_reqs;
6213 VkDeviceMemory image_memory;
6214 bool pass;
6215 VkMemoryAllocateInfo memory_info = {};
6216 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6217 memory_info.pNext = NULL;
6218 memory_info.allocationSize = 0;
6219 memory_info.memoryTypeIndex = 0;
6220 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6221 // Allocate enough memory for image
6222 memory_info.allocationSize = memory_reqs.size;
6223 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6224 ASSERT_TRUE(pass);
6225 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6226 ASSERT_VK_SUCCESS(err);
6227 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6228 ASSERT_VK_SUCCESS(err);
6229
6230 VkImageViewCreateInfo image_view_create_info = {};
6231 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6232 image_view_create_info.image = image;
6233 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6234 image_view_create_info.format = tex_format;
6235 image_view_create_info.subresourceRange.layerCount = 1;
6236 image_view_create_info.subresourceRange.baseMipLevel = 0;
6237 image_view_create_info.subresourceRange.levelCount = 1;
6238 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6239
6240 VkImageView view;
6241 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6242 ASSERT_VK_SUCCESS(err);
6243 // Create Samplers
6244 VkSamplerCreateInfo sampler_ci = {};
6245 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6246 sampler_ci.pNext = NULL;
6247 sampler_ci.magFilter = VK_FILTER_NEAREST;
6248 sampler_ci.minFilter = VK_FILTER_NEAREST;
6249 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6250 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6251 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6252 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6253 sampler_ci.mipLodBias = 1.0;
6254 sampler_ci.anisotropyEnable = VK_FALSE;
6255 sampler_ci.maxAnisotropy = 1;
6256 sampler_ci.compareEnable = VK_FALSE;
6257 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6258 sampler_ci.minLod = 1.0;
6259 sampler_ci.maxLod = 1.0;
6260 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6261 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6262 VkSampler sampler;
6263 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6264 ASSERT_VK_SUCCESS(err);
6265 // Update descriptor with image and sampler
6266 VkDescriptorImageInfo img_info = {};
6267 img_info.sampler = sampler;
6268 img_info.imageView = view;
6269 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6270
6271 VkWriteDescriptorSet descriptor_write;
6272 memset(&descriptor_write, 0, sizeof(descriptor_write));
6273 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6274 descriptor_write.dstSet = descriptorSet;
6275 descriptor_write.dstBinding = 0;
6276 descriptor_write.descriptorCount = 1;
6277 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6278 descriptor_write.pImageInfo = &img_info;
6279 // Break memory binding and attempt update
6280 vkFreeMemory(m_device->device(), image_memory, nullptr);
6281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006282 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6284 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6285 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6286 m_errorMonitor->VerifyFound();
6287 // Cleanup
6288 vkDestroyImage(m_device->device(), image, NULL);
6289 vkDestroySampler(m_device->device(), sampler, NULL);
6290 vkDestroyImageView(m_device->device(), view, NULL);
6291 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6294}
6295
Karl Schultz6addd812016-02-02 17:17:23 -07006296TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006297 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6298 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006299 // Create a valid cmd buffer
6300 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006301 uint64_t fake_pipeline_handle = 0xbaad6001;
6302 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006303 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6305
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006307 m_commandBuffer->BeginCommandBuffer();
6308 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006309 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006310 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006311
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006312 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006313 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 -06006314 Draw(1, 0, 0, 0);
6315 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006316
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006317 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006318 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 -07006319 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006320 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6321 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006322}
6323
Karl Schultz6addd812016-02-02 17:17:23 -07006324TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006325 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006326 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006329
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006330 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006331 ASSERT_NO_FATAL_FAILURE(InitViewport());
6332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006333 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006334 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6335 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006336
6337 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006338 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6339 ds_pool_ci.pNext = NULL;
6340 ds_pool_ci.maxSets = 1;
6341 ds_pool_ci.poolSizeCount = 1;
6342 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006343
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006344 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006345 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006346 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006347
Tony Barboureb254902015-07-15 12:50:33 -06006348 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006349 dsl_binding.binding = 0;
6350 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6351 dsl_binding.descriptorCount = 1;
6352 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6353 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006354
Tony Barboureb254902015-07-15 12:50:33 -06006355 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006356 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6357 ds_layout_ci.pNext = NULL;
6358 ds_layout_ci.bindingCount = 1;
6359 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006360 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006361 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006362 ASSERT_VK_SUCCESS(err);
6363
6364 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006365 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006366 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006367 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006368 alloc_info.descriptorPool = ds_pool;
6369 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006371 ASSERT_VK_SUCCESS(err);
6372
Tony Barboureb254902015-07-15 12:50:33 -06006373 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006374 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6375 pipeline_layout_ci.pNext = NULL;
6376 pipeline_layout_ci.setLayoutCount = 1;
6377 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006378
6379 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006380 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006381 ASSERT_VK_SUCCESS(err);
6382
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006383 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006384 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006385 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006387
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006388 VkPipelineObj pipe(m_device);
6389 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006390 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006391 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006392 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006393
Tony Barbour552f6c02016-12-21 14:34:07 -07006394 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6396 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6397 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006398
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006399 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006400
Chia-I Wuf7458c52015-10-26 21:10:41 +08006401 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6402 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6403 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006404}
6405
Karl Schultz6addd812016-02-02 17:17:23 -07006406TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006407 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006408 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006409
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006411
6412 ASSERT_NO_FATAL_FAILURE(InitState());
6413 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006414 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6415 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006416
6417 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006418 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6419 ds_pool_ci.pNext = NULL;
6420 ds_pool_ci.maxSets = 1;
6421 ds_pool_ci.poolSizeCount = 1;
6422 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006423
6424 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006425 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006426 ASSERT_VK_SUCCESS(err);
6427
6428 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006429 dsl_binding.binding = 0;
6430 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6431 dsl_binding.descriptorCount = 1;
6432 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6433 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006434
6435 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006436 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6437 ds_layout_ci.pNext = NULL;
6438 ds_layout_ci.bindingCount = 1;
6439 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006440 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006441 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006442 ASSERT_VK_SUCCESS(err);
6443
6444 VkDescriptorSet descriptorSet;
6445 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006446 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006447 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006448 alloc_info.descriptorPool = ds_pool;
6449 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006450 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006451 ASSERT_VK_SUCCESS(err);
6452
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006453 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006454 VkWriteDescriptorSet descriptor_write;
6455 memset(&descriptor_write, 0, sizeof(descriptor_write));
6456 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6457 descriptor_write.dstSet = descriptorSet;
6458 descriptor_write.dstBinding = 0;
6459 descriptor_write.descriptorCount = 1;
6460 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6461 descriptor_write.pTexelBufferView = &view;
6462
6463 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6464
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006465 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006466
6467 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6468 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6469}
6470
Mark Youngd339ba32016-05-30 13:28:35 -06006471TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006472 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 -06006473
6474 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006476 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006477
6478 ASSERT_NO_FATAL_FAILURE(InitState());
6479
6480 // Create a buffer with no bound memory and then attempt to create
6481 // a buffer view.
6482 VkBufferCreateInfo buff_ci = {};
6483 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006484 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006485 buff_ci.size = 256;
6486 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6487 VkBuffer buffer;
6488 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6489 ASSERT_VK_SUCCESS(err);
6490
6491 VkBufferViewCreateInfo buff_view_ci = {};
6492 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6493 buff_view_ci.buffer = buffer;
6494 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6495 buff_view_ci.range = VK_WHOLE_SIZE;
6496 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006497 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006498
6499 m_errorMonitor->VerifyFound();
6500 vkDestroyBuffer(m_device->device(), buffer, NULL);
6501 // If last error is success, it still created the view, so delete it.
6502 if (err == VK_SUCCESS) {
6503 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6504 }
6505}
6506
Karl Schultz6addd812016-02-02 17:17:23 -07006507TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6508 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6509 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006510 // 1. No dynamicOffset supplied
6511 // 2. Too many dynamicOffsets supplied
6512 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006513 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6515 " requires 1 dynamicOffsets, but only "
6516 "0 dynamicOffsets are left in "
6517 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006518
6519 ASSERT_NO_FATAL_FAILURE(InitState());
6520 ASSERT_NO_FATAL_FAILURE(InitViewport());
6521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6522
6523 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006524 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6525 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006526
6527 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006528 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6529 ds_pool_ci.pNext = NULL;
6530 ds_pool_ci.maxSets = 1;
6531 ds_pool_ci.poolSizeCount = 1;
6532 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006533
6534 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006535 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006536 ASSERT_VK_SUCCESS(err);
6537
6538 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006539 dsl_binding.binding = 0;
6540 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6541 dsl_binding.descriptorCount = 1;
6542 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6543 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006544
6545 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006546 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6547 ds_layout_ci.pNext = NULL;
6548 ds_layout_ci.bindingCount = 1;
6549 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006550 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006551 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006552 ASSERT_VK_SUCCESS(err);
6553
6554 VkDescriptorSet descriptorSet;
6555 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006556 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006557 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006558 alloc_info.descriptorPool = ds_pool;
6559 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006560 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006561 ASSERT_VK_SUCCESS(err);
6562
6563 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006564 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6565 pipeline_layout_ci.pNext = NULL;
6566 pipeline_layout_ci.setLayoutCount = 1;
6567 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006568
6569 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006570 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006571 ASSERT_VK_SUCCESS(err);
6572
6573 // Create a buffer to update the descriptor with
6574 uint32_t qfi = 0;
6575 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006576 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6577 buffCI.size = 1024;
6578 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6579 buffCI.queueFamilyIndexCount = 1;
6580 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006581
6582 VkBuffer dyub;
6583 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6584 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006585 // Allocate memory and bind to buffer so we can make it to the appropriate
6586 // error
6587 VkMemoryAllocateInfo mem_alloc = {};
6588 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6589 mem_alloc.pNext = NULL;
6590 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006591 mem_alloc.memoryTypeIndex = 0;
6592
6593 VkMemoryRequirements memReqs;
6594 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006595 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006596 if (!pass) {
6597 vkDestroyBuffer(m_device->device(), dyub, NULL);
6598 return;
6599 }
6600
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006601 VkDeviceMemory mem;
6602 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6603 ASSERT_VK_SUCCESS(err);
6604 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6605 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006606 // Correctly update descriptor to avoid "NOT_UPDATED" error
6607 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006608 buffInfo.buffer = dyub;
6609 buffInfo.offset = 0;
6610 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006611
6612 VkWriteDescriptorSet descriptor_write;
6613 memset(&descriptor_write, 0, sizeof(descriptor_write));
6614 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6615 descriptor_write.dstSet = descriptorSet;
6616 descriptor_write.dstBinding = 0;
6617 descriptor_write.descriptorCount = 1;
6618 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6619 descriptor_write.pBufferInfo = &buffInfo;
6620
6621 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6622
Tony Barbour552f6c02016-12-21 14:34:07 -07006623 m_commandBuffer->BeginCommandBuffer();
6624 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006625 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6626 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006627 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006628 uint32_t pDynOff[2] = {512, 756};
6629 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6631 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6632 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6633 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006634 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006635 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6637 " dynamic offset 512 combined with "
6638 "offset 0 and range 1024 that "
6639 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006640 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006641 char const *vsSource =
6642 "#version 450\n"
6643 "\n"
6644 "out gl_PerVertex { \n"
6645 " vec4 gl_Position;\n"
6646 "};\n"
6647 "void main(){\n"
6648 " gl_Position = vec4(1);\n"
6649 "}\n";
6650 char const *fsSource =
6651 "#version 450\n"
6652 "\n"
6653 "layout(location=0) out vec4 x;\n"
6654 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6655 "void main(){\n"
6656 " x = vec4(bar.y);\n"
6657 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006658 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6659 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6660 VkPipelineObj pipe(m_device);
6661 pipe.AddShader(&vs);
6662 pipe.AddShader(&fs);
6663 pipe.AddColorAttachment();
6664 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6665
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006666 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6667 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6668 VkRect2D scissor = {{0, 0}, {16, 16}};
6669 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6670
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006671 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006672 // This update should succeed, but offset size of 512 will overstep buffer
6673 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006674 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6675 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006676 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006677 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006678
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006679 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006680 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006681
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006682 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006683 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006684 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6685}
6686
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006687TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006688 TEST_DESCRIPTION(
6689 "Attempt to update a descriptor with a non-sparse buffer "
6690 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006691 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006693 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6695 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006696
6697 ASSERT_NO_FATAL_FAILURE(InitState());
6698 ASSERT_NO_FATAL_FAILURE(InitViewport());
6699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6700
6701 VkDescriptorPoolSize ds_type_count = {};
6702 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6703 ds_type_count.descriptorCount = 1;
6704
6705 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6706 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6707 ds_pool_ci.pNext = NULL;
6708 ds_pool_ci.maxSets = 1;
6709 ds_pool_ci.poolSizeCount = 1;
6710 ds_pool_ci.pPoolSizes = &ds_type_count;
6711
6712 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006713 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006714 ASSERT_VK_SUCCESS(err);
6715
6716 VkDescriptorSetLayoutBinding dsl_binding = {};
6717 dsl_binding.binding = 0;
6718 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6719 dsl_binding.descriptorCount = 1;
6720 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6721 dsl_binding.pImmutableSamplers = NULL;
6722
6723 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6724 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6725 ds_layout_ci.pNext = NULL;
6726 ds_layout_ci.bindingCount = 1;
6727 ds_layout_ci.pBindings = &dsl_binding;
6728 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006729 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006730 ASSERT_VK_SUCCESS(err);
6731
6732 VkDescriptorSet descriptorSet;
6733 VkDescriptorSetAllocateInfo alloc_info = {};
6734 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6735 alloc_info.descriptorSetCount = 1;
6736 alloc_info.descriptorPool = ds_pool;
6737 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006739 ASSERT_VK_SUCCESS(err);
6740
6741 // Create a buffer to update the descriptor with
6742 uint32_t qfi = 0;
6743 VkBufferCreateInfo buffCI = {};
6744 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6745 buffCI.size = 1024;
6746 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6747 buffCI.queueFamilyIndexCount = 1;
6748 buffCI.pQueueFamilyIndices = &qfi;
6749
6750 VkBuffer dyub;
6751 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6752 ASSERT_VK_SUCCESS(err);
6753
6754 // Attempt to update descriptor without binding memory to it
6755 VkDescriptorBufferInfo buffInfo = {};
6756 buffInfo.buffer = dyub;
6757 buffInfo.offset = 0;
6758 buffInfo.range = 1024;
6759
6760 VkWriteDescriptorSet descriptor_write;
6761 memset(&descriptor_write, 0, sizeof(descriptor_write));
6762 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6763 descriptor_write.dstSet = descriptorSet;
6764 descriptor_write.dstBinding = 0;
6765 descriptor_write.descriptorCount = 1;
6766 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6767 descriptor_write.pBufferInfo = &buffInfo;
6768
6769 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6770 m_errorMonitor->VerifyFound();
6771
6772 vkDestroyBuffer(m_device->device(), dyub, NULL);
6773 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6774 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6775}
6776
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006777TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006778 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006779 ASSERT_NO_FATAL_FAILURE(InitState());
6780 ASSERT_NO_FATAL_FAILURE(InitViewport());
6781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6782
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006783 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006784 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006785 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6786 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6787 pipeline_layout_ci.pushConstantRangeCount = 1;
6788 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6789
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006790 //
6791 // Check for invalid push constant ranges in pipeline layouts.
6792 //
6793 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006794 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006795 char const *msg;
6796 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006797
Karl Schultzc81037d2016-05-12 08:11:23 -06006798 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6799 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6800 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6801 "vkCreatePipelineLayout() call has push constants index 0 with "
6802 "size 0."},
6803 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6804 "vkCreatePipelineLayout() call has push constants index 0 with "
6805 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006806 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006807 "vkCreatePipelineLayout() call has push constants index 0 with "
6808 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006809 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006810 "vkCreatePipelineLayout() call has push constants index 0 with "
6811 "size 0."},
6812 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6813 "vkCreatePipelineLayout() call has push constants index 0 with "
6814 "offset 1. Offset must"},
6815 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6816 "vkCreatePipelineLayout() call has push constants index 0 "
6817 "with offset "},
6818 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6819 "vkCreatePipelineLayout() call has push constants "
6820 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006821 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006822 "vkCreatePipelineLayout() call has push constants index 0 "
6823 "with offset "},
6824 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6825 "vkCreatePipelineLayout() call has push "
6826 "constants index 0 with offset "},
6827 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6828 "vkCreatePipelineLayout() call has push "
6829 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006830 }};
6831
6832 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006833 for (const auto &iter : range_tests) {
6834 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6836 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006837 m_errorMonitor->VerifyFound();
6838 if (VK_SUCCESS == err) {
6839 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6840 }
6841 }
6842
6843 // Check for invalid stage flag
6844 pc_range.offset = 0;
6845 pc_range.size = 16;
6846 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006847 m_errorMonitor->SetDesiredFailureMsg(
6848 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6849 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006850 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006851 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006852 if (VK_SUCCESS == err) {
6853 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6854 }
6855
6856 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006857 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006858 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006859 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006860 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006861 };
6862
Karl Schultzc81037d2016-05-12 08:11:23 -06006863 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006864 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6865 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6866 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6867 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6868 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006869 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6870 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6871 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6872 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6873 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6874 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6875 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6876 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6877 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6878 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006879 {
6880 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6881 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6882 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6883 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6884 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006885 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006886 },
6887 {
6888 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6889 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6890 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6891 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6892 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006893 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006894 },
6895 {
6896 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6897 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6898 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6899 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6900 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006901 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006902 },
6903 {
6904 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6905 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6906 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6907 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6908 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006909 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6910 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6911 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6912 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006913 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006914
Karl Schultzc81037d2016-05-12 08:11:23 -06006915 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006916 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006917 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006919 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006920 m_errorMonitor->VerifyFound();
6921 if (VK_SUCCESS == err) {
6922 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6923 }
6924 }
6925
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006926 //
6927 // CmdPushConstants tests
6928 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006929 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006930
6931 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006932 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6933 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006934 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006935 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6936 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006937 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006938 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6939 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006940 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006941 "vkCmdPushConstants() call has push constants with offset 1. "
6942 "Offset must be a multiple of 4."},
6943 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6944 "vkCmdPushConstants() call has push constants with offset 1. "
6945 "Offset must be a multiple of 4."},
6946 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6947 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6948 "0x1 not within flag-matching ranges in pipeline layout"},
6949 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6950 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6951 "0x1 not within flag-matching ranges in pipeline layout"},
6952 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6953 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6954 "0x1 not within flag-matching ranges in pipeline layout"},
6955 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6956 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6957 "0x1 not within flag-matching ranges in pipeline layout"},
6958 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6959 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6960 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006961 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006962 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6963 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006964 }};
6965
Tony Barbour552f6c02016-12-21 14:34:07 -07006966 m_commandBuffer->BeginCommandBuffer();
6967 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006968
6969 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006970 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006971 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006972 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006973 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006974 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006975 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006976 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006977 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6979 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006980 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006981 m_errorMonitor->VerifyFound();
6982 }
6983
6984 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006986 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006987 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006988 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006989
Karl Schultzc81037d2016-05-12 08:11:23 -06006990 // overlapping range tests with cmd
6991 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6992 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6993 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6994 "0x1 not within flag-matching ranges in pipeline layout"},
6995 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6996 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6997 "0x1 not within flag-matching ranges in pipeline layout"},
6998 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6999 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
7000 "0x1 not within flag-matching ranges in pipeline layout"},
7001 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007002 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06007003 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007004 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
7005 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06007006 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007007 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06007008 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007009 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06007010 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007011 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7013 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007014 iter.range.size, dummy_values);
7015 m_errorMonitor->VerifyFound();
7016 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007017 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7018
Tony Barbour552f6c02016-12-21 14:34:07 -07007019 m_commandBuffer->EndRenderPass();
7020 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007021}
7022
Karl Schultz6addd812016-02-02 17:17:23 -07007023TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007024 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007025 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007026
7027 ASSERT_NO_FATAL_FAILURE(InitState());
7028 ASSERT_NO_FATAL_FAILURE(InitViewport());
7029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7030
7031 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7032 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007033 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7034 ds_type_count[0].descriptorCount = 10;
7035 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7036 ds_type_count[1].descriptorCount = 2;
7037 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7038 ds_type_count[2].descriptorCount = 2;
7039 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7040 ds_type_count[3].descriptorCount = 5;
7041 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7042 // type
7043 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7044 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7045 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007046
7047 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007048 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7049 ds_pool_ci.pNext = NULL;
7050 ds_pool_ci.maxSets = 5;
7051 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7052 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007053
7054 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007055 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007056 ASSERT_VK_SUCCESS(err);
7057
7058 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7059 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007060 dsl_binding[0].binding = 0;
7061 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7062 dsl_binding[0].descriptorCount = 5;
7063 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7064 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007065
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007066 // Create layout identical to set0 layout but w/ different stageFlags
7067 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007068 dsl_fs_stage_only.binding = 0;
7069 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7070 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007071 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7072 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007073 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007074 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007075 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7076 ds_layout_ci.pNext = NULL;
7077 ds_layout_ci.bindingCount = 1;
7078 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007079 static const uint32_t NUM_LAYOUTS = 4;
7080 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007081 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007082 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7083 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007084 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007085 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007086 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007087 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007088 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007089 dsl_binding[0].binding = 0;
7090 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007091 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007092 dsl_binding[1].binding = 1;
7093 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7094 dsl_binding[1].descriptorCount = 2;
7095 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7096 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007097 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007098 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007099 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007100 ASSERT_VK_SUCCESS(err);
7101 dsl_binding[0].binding = 0;
7102 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007103 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007104 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007105 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007106 ASSERT_VK_SUCCESS(err);
7107 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007108 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007109 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007110 ASSERT_VK_SUCCESS(err);
7111
7112 static const uint32_t NUM_SETS = 4;
7113 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7114 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007115 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007116 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007117 alloc_info.descriptorPool = ds_pool;
7118 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007119 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007120 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007121 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007122 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007123 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007124 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007125 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007126
7127 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007128 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7129 pipeline_layout_ci.pNext = NULL;
7130 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7131 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007132
7133 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007134 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007135 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007136 // Create pipelineLayout with only one setLayout
7137 pipeline_layout_ci.setLayoutCount = 1;
7138 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007139 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007140 ASSERT_VK_SUCCESS(err);
7141 // Create pipelineLayout with 2 descriptor setLayout at index 0
7142 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7143 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007144 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007145 ASSERT_VK_SUCCESS(err);
7146 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7147 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7148 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007150 ASSERT_VK_SUCCESS(err);
7151 // Create pipelineLayout with UB type, but stageFlags for FS only
7152 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7153 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007154 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007155 ASSERT_VK_SUCCESS(err);
7156 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7157 VkDescriptorSetLayout pl_bad_s0[2] = {};
7158 pl_bad_s0[0] = ds_layout_fs_only;
7159 pl_bad_s0[1] = ds_layout[1];
7160 pipeline_layout_ci.setLayoutCount = 2;
7161 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7162 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007164 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007165
Tobin Ehlis88452832015-12-03 09:40:56 -07007166 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007167 char const *vsSource =
7168 "#version 450\n"
7169 "\n"
7170 "out gl_PerVertex {\n"
7171 " vec4 gl_Position;\n"
7172 "};\n"
7173 "void main(){\n"
7174 " gl_Position = vec4(1);\n"
7175 "}\n";
7176 char const *fsSource =
7177 "#version 450\n"
7178 "\n"
7179 "layout(location=0) out vec4 x;\n"
7180 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7181 "void main(){\n"
7182 " x = vec4(bar.y);\n"
7183 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007184 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7185 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007186 VkPipelineObj pipe(m_device);
7187 pipe.AddShader(&vs);
7188 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007189 pipe.AddColorAttachment();
7190 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007191
Tony Barbour552f6c02016-12-21 14:34:07 -07007192 m_commandBuffer->BeginCommandBuffer();
7193 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007195 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007196 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7197 // of PSO
7198 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7199 // cmd_pipeline.c
7200 // due to the fact that cmd_alloc_dset_data() has not been called in
7201 // cmd_bind_graphics_pipeline()
7202 // TODO : Want to cause various binding incompatibility issues here to test
7203 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007204 // First cause various verify_layout_compatibility() fails
7205 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007206 // verify_set_layout_compatibility fail cases:
7207 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007209 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7210 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007211 m_errorMonitor->VerifyFound();
7212
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007213 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7215 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7216 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007217 m_errorMonitor->VerifyFound();
7218
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007219 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007220 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7221 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7223 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7224 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007225 m_errorMonitor->VerifyFound();
7226
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007227 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7228 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7230 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7231 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007232 m_errorMonitor->VerifyFound();
7233
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007234 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7235 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7237 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7238 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7239 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007240 m_errorMonitor->VerifyFound();
7241
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007242 // Cause INFO messages due to disturbing previously bound Sets
7243 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007244 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7245 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007246 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7248 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7249 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007250 m_errorMonitor->VerifyFound();
7251
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007252 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7253 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007254 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7256 " newly bound as set #0 so set #1 and "
7257 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007258 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7259 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007260 m_errorMonitor->VerifyFound();
7261
Tobin Ehlis10fad692016-07-07 12:00:36 -06007262 // Now that we're done actively using the pipelineLayout that gfx pipeline
7263 // was created with, we should be able to delete it. Do that now to verify
7264 // that validation obeys pipelineLayout lifetime
7265 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7266
Tobin Ehlis88452832015-12-03 09:40:56 -07007267 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007268 // 1. Error due to not binding required set (we actually use same code as
7269 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007270 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7271 &descriptorSet[0], 0, NULL);
7272 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7273 &descriptorSet[1], 0, NULL);
7274 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 -07007275
7276 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7277 VkRect2D scissor = {{0, 0}, {16, 16}};
7278 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7279 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7280
Tobin Ehlis88452832015-12-03 09:40:56 -07007281 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007282 m_errorMonitor->VerifyFound();
7283
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007284 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007285 // 2. Error due to bound set not being compatible with PSO's
7286 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007287 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7288 &descriptorSet[0], 0, NULL);
7289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007290 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007291 m_errorMonitor->VerifyFound();
7292
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007293 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007294 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007295 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7296 }
7297 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007298 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7299 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7300}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007301
Karl Schultz6addd812016-02-02 17:17:23 -07007302TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7304 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007305
7306 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007307 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007308 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007309 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007310
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007311 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007312}
7313
Karl Schultz6addd812016-02-02 17:17:23 -07007314TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7315 VkResult err;
7316 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007317
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007319
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007320 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007321
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007322 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007323 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007324 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007325 cmd.commandPool = m_commandPool;
7326 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007327 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007328
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007329 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007330 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007331
7332 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007333 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007334 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7335
7336 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007337 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007338 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007339 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 -07007340 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007341
7342 // The error should be caught by validation of the BeginCommandBuffer call
7343 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7344
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007345 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007346 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007347}
7348
Karl Schultz6addd812016-02-02 17:17:23 -07007349TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007350 // Cause error due to Begin while recording CB
7351 // Then cause 2 errors for attempting to reset CB w/o having
7352 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7353 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007355
7356 ASSERT_NO_FATAL_FAILURE(InitState());
7357
7358 // Calls AllocateCommandBuffers
7359 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7360
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007361 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007362 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007363 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7364 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007365 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7366 cmd_buf_info.pNext = NULL;
7367 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007368 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007369
7370 // Begin CB to transition to recording state
7371 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7372 // Can't re-begin. This should trigger error
7373 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007374 m_errorMonitor->VerifyFound();
7375
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007377 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007378 // Reset attempt will trigger error due to incorrect CommandPool state
7379 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007380 m_errorMonitor->VerifyFound();
7381
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007383 // Transition CB to RECORDED state
7384 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7385 // Now attempting to Begin will implicitly reset, which triggers error
7386 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007387 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007388}
7389
Karl Schultz6addd812016-02-02 17:17:23 -07007390TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007391 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007392 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007393
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7395 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007396
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007397 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007399
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007400 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007401 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7402 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007403
7404 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007405 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7406 ds_pool_ci.pNext = NULL;
7407 ds_pool_ci.maxSets = 1;
7408 ds_pool_ci.poolSizeCount = 1;
7409 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007410
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007411 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007412 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007413 ASSERT_VK_SUCCESS(err);
7414
Tony Barboureb254902015-07-15 12:50:33 -06007415 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007416 dsl_binding.binding = 0;
7417 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7418 dsl_binding.descriptorCount = 1;
7419 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7420 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007421
Tony Barboureb254902015-07-15 12:50:33 -06007422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7424 ds_layout_ci.pNext = NULL;
7425 ds_layout_ci.bindingCount = 1;
7426 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007427
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007428 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007429 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007430 ASSERT_VK_SUCCESS(err);
7431
7432 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007433 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007434 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007435 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007436 alloc_info.descriptorPool = ds_pool;
7437 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007438 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007439 ASSERT_VK_SUCCESS(err);
7440
Tony Barboureb254902015-07-15 12:50:33 -06007441 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007442 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7443 pipeline_layout_ci.setLayoutCount = 1;
7444 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007445
7446 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007447 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007448 ASSERT_VK_SUCCESS(err);
7449
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007450 VkViewport vp = {}; // Just need dummy vp to point to
7451 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007452
7453 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007454 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7455 vp_state_ci.scissorCount = 1;
7456 vp_state_ci.pScissors = &sc;
7457 vp_state_ci.viewportCount = 1;
7458 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007459
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007460 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7461 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7462 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7463 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7464 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7465 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007466 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007467 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007468 rs_state_ci.lineWidth = 1.0f;
7469
7470 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7471 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7472 vi_ci.pNext = nullptr;
7473 vi_ci.vertexBindingDescriptionCount = 0;
7474 vi_ci.pVertexBindingDescriptions = nullptr;
7475 vi_ci.vertexAttributeDescriptionCount = 0;
7476 vi_ci.pVertexAttributeDescriptions = nullptr;
7477
7478 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7479 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7480 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7481
7482 VkPipelineShaderStageCreateInfo shaderStages[2];
7483 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7484
7485 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7486 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007487 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007488 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007489
Tony Barboureb254902015-07-15 12:50:33 -06007490 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007491 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7492 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007493 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007494 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7495 gp_ci.layout = pipeline_layout;
7496 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007497 gp_ci.pVertexInputState = &vi_ci;
7498 gp_ci.pInputAssemblyState = &ia_ci;
7499
7500 gp_ci.stageCount = 1;
7501 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007502
7503 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007504 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7505 pc_ci.initialDataSize = 0;
7506 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007507
7508 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007509 VkPipelineCache pipelineCache;
7510
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007511 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007512 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007513 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007514 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007515
Chia-I Wuf7458c52015-10-26 21:10:41 +08007516 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7517 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7518 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7519 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007520}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007521
Tobin Ehlis912df022015-09-17 08:46:18 -06007522/*// TODO : This test should be good, but needs Tess support in compiler to run
7523TEST_F(VkLayerTest, InvalidPatchControlPoints)
7524{
7525 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007526 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007527
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007529 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7530primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007531
Tobin Ehlis912df022015-09-17 08:46:18 -06007532 ASSERT_NO_FATAL_FAILURE(InitState());
7533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007534
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007535 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007536 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007537 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007538
7539 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7540 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7541 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007542 ds_pool_ci.poolSizeCount = 1;
7543 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007544
7545 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007546 err = vkCreateDescriptorPool(m_device->device(),
7547VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007548 ASSERT_VK_SUCCESS(err);
7549
7550 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007551 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007552 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007553 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007554 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7555 dsl_binding.pImmutableSamplers = NULL;
7556
7557 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007558 ds_layout_ci.sType =
7559VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007560 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007561 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007562 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007563
7564 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007565 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7566&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007567 ASSERT_VK_SUCCESS(err);
7568
7569 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007570 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7571VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007572 ASSERT_VK_SUCCESS(err);
7573
7574 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007575 pipeline_layout_ci.sType =
7576VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007577 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007578 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007579 pipeline_layout_ci.pSetLayouts = &ds_layout;
7580
7581 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007582 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7583&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007584 ASSERT_VK_SUCCESS(err);
7585
7586 VkPipelineShaderStageCreateInfo shaderStages[3];
7587 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7588
Karl Schultz6addd812016-02-02 17:17:23 -07007589 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7590this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007591 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007592 VkShaderObj
7593tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7594this);
7595 VkShaderObj
7596te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7597this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007598
Karl Schultz6addd812016-02-02 17:17:23 -07007599 shaderStages[0].sType =
7600VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007601 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007602 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007603 shaderStages[1].sType =
7604VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007605 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007606 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007607 shaderStages[2].sType =
7608VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007609 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007610 shaderStages[2].shader = te.handle();
7611
7612 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007613 iaCI.sType =
7614VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007615 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007616
7617 VkPipelineTessellationStateCreateInfo tsCI = {};
7618 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7619 tsCI.patchControlPoints = 0; // This will cause an error
7620
7621 VkGraphicsPipelineCreateInfo gp_ci = {};
7622 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7623 gp_ci.pNext = NULL;
7624 gp_ci.stageCount = 3;
7625 gp_ci.pStages = shaderStages;
7626 gp_ci.pVertexInputState = NULL;
7627 gp_ci.pInputAssemblyState = &iaCI;
7628 gp_ci.pTessellationState = &tsCI;
7629 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007630 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007631 gp_ci.pMultisampleState = NULL;
7632 gp_ci.pDepthStencilState = NULL;
7633 gp_ci.pColorBlendState = NULL;
7634 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7635 gp_ci.layout = pipeline_layout;
7636 gp_ci.renderPass = renderPass();
7637
7638 VkPipelineCacheCreateInfo pc_ci = {};
7639 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7640 pc_ci.pNext = NULL;
7641 pc_ci.initialSize = 0;
7642 pc_ci.initialData = 0;
7643 pc_ci.maxSize = 0;
7644
7645 VkPipeline pipeline;
7646 VkPipelineCache pipelineCache;
7647
Karl Schultz6addd812016-02-02 17:17:23 -07007648 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7649&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007650 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007651 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7652&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007653
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007654 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007655
Chia-I Wuf7458c52015-10-26 21:10:41 +08007656 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7657 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7658 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7659 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007660}
7661*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007662
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007663TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007664 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007665
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007666 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007667
Tobin Ehlise68360f2015-10-01 11:15:13 -06007668 ASSERT_NO_FATAL_FAILURE(InitState());
7669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007670
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007671 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007672 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7673 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007674
7675 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007676 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7677 ds_pool_ci.maxSets = 1;
7678 ds_pool_ci.poolSizeCount = 1;
7679 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007680
7681 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007682 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007683 ASSERT_VK_SUCCESS(err);
7684
7685 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007686 dsl_binding.binding = 0;
7687 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7688 dsl_binding.descriptorCount = 1;
7689 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007690
7691 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007692 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7693 ds_layout_ci.bindingCount = 1;
7694 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007695
7696 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007697 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007698 ASSERT_VK_SUCCESS(err);
7699
7700 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007701 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007702 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007703 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007704 alloc_info.descriptorPool = ds_pool;
7705 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007706 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007707 ASSERT_VK_SUCCESS(err);
7708
7709 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007710 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7711 pipeline_layout_ci.setLayoutCount = 1;
7712 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007713
7714 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007715 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007716 ASSERT_VK_SUCCESS(err);
7717
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007718 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007719 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007720 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007721 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007722 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007723 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007724
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007725 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7726 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7727 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7728 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7729 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7730 rs_state_ci.depthClampEnable = VK_FALSE;
7731 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7732 rs_state_ci.depthBiasEnable = VK_FALSE;
7733
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007734 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7735 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7736 vi_ci.pNext = nullptr;
7737 vi_ci.vertexBindingDescriptionCount = 0;
7738 vi_ci.pVertexBindingDescriptions = nullptr;
7739 vi_ci.vertexAttributeDescriptionCount = 0;
7740 vi_ci.pVertexAttributeDescriptions = nullptr;
7741
7742 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7743 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7744 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7745
7746 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7747 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7748 pipe_ms_state_ci.pNext = NULL;
7749 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7750 pipe_ms_state_ci.sampleShadingEnable = 0;
7751 pipe_ms_state_ci.minSampleShading = 1.0;
7752 pipe_ms_state_ci.pSampleMask = NULL;
7753
Cody Northropeb3a6c12015-10-05 14:44:45 -06007754 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007755 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007756
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007757 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007758 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007759 shaderStages[0] = vs.GetStageCreateInfo();
7760 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007761
7762 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007763 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7764 gp_ci.stageCount = 2;
7765 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007766 gp_ci.pVertexInputState = &vi_ci;
7767 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007768 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007769 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007770 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007771 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7772 gp_ci.layout = pipeline_layout;
7773 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007774
7775 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007776 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007777
7778 VkPipeline pipeline;
7779 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007780 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007781 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007783 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007784 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007785
7786 // Check case where multiViewport is disabled and viewport count is not 1
7787 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7790 vp_state_ci.scissorCount = 0;
7791 vp_state_ci.viewportCount = 0;
7792 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7793 m_errorMonitor->VerifyFound();
7794 } else {
7795 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007796 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007797 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007798 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007799
7800 // Check is that viewportcount and scissorcount match
7801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7802 vp_state_ci.scissorCount = 1;
7803 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7804 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7805 m_errorMonitor->VerifyFound();
7806
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007807 // Check case where multiViewport is enabled and viewport count is greater than max
7808 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7811 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7812 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7813 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7814 m_errorMonitor->VerifyFound();
7815 }
7816 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007817
Chia-I Wuf7458c52015-10-26 21:10:41 +08007818 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7819 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7820 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7821 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007822}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007823
7824// 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
7825// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007826TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007827 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007828
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007829 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7830
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007832
Tobin Ehlise68360f2015-10-01 11:15:13 -06007833 ASSERT_NO_FATAL_FAILURE(InitState());
7834 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007835
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007836 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007837 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7838 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007839
7840 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007841 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7842 ds_pool_ci.maxSets = 1;
7843 ds_pool_ci.poolSizeCount = 1;
7844 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007845
7846 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007847 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007848 ASSERT_VK_SUCCESS(err);
7849
7850 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007851 dsl_binding.binding = 0;
7852 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7853 dsl_binding.descriptorCount = 1;
7854 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007855
7856 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007857 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7858 ds_layout_ci.bindingCount = 1;
7859 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007860
7861 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007862 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007863 ASSERT_VK_SUCCESS(err);
7864
7865 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007866 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007867 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007868 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007869 alloc_info.descriptorPool = ds_pool;
7870 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007871 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007872 ASSERT_VK_SUCCESS(err);
7873
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007874 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7875 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7876 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7877
7878 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7879 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7880 vi_ci.pNext = nullptr;
7881 vi_ci.vertexBindingDescriptionCount = 0;
7882 vi_ci.pVertexBindingDescriptions = nullptr;
7883 vi_ci.vertexAttributeDescriptionCount = 0;
7884 vi_ci.pVertexAttributeDescriptions = nullptr;
7885
7886 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7887 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7888 pipe_ms_state_ci.pNext = NULL;
7889 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7890 pipe_ms_state_ci.sampleShadingEnable = 0;
7891 pipe_ms_state_ci.minSampleShading = 1.0;
7892 pipe_ms_state_ci.pSampleMask = NULL;
7893
Tobin Ehlise68360f2015-10-01 11:15:13 -06007894 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007895 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7896 pipeline_layout_ci.setLayoutCount = 1;
7897 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007898
7899 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007900 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007901 ASSERT_VK_SUCCESS(err);
7902
7903 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7904 // Set scissor as dynamic to avoid second error
7905 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007906 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7907 dyn_state_ci.dynamicStateCount = 1;
7908 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007909
Cody Northropeb3a6c12015-10-05 14:44:45 -06007910 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007911 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007912
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007913 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007914 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7915 // 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 +08007916 shaderStages[0] = vs.GetStageCreateInfo();
7917 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007918
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007919 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7920 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7921 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7922 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7923 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7924 rs_state_ci.depthClampEnable = VK_FALSE;
7925 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7926 rs_state_ci.depthBiasEnable = VK_FALSE;
7927
Tobin Ehlise68360f2015-10-01 11:15:13 -06007928 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007929 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7930 gp_ci.stageCount = 2;
7931 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007932 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007933 // Not setting VP state w/o dynamic vp state should cause validation error
7934 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007935 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007936 gp_ci.pVertexInputState = &vi_ci;
7937 gp_ci.pInputAssemblyState = &ia_ci;
7938 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007939 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7940 gp_ci.layout = pipeline_layout;
7941 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007942
7943 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007944 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007945
7946 VkPipeline pipeline;
7947 VkPipelineCache pipelineCache;
7948
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007949 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007950 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007952
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007953 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007954
Chia-I Wuf7458c52015-10-26 21:10:41 +08007955 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7956 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7957 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7958 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007959}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007960
7961// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7962// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007963TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7964 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007965
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007967
Tobin Ehlise68360f2015-10-01 11:15:13 -06007968 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007969
7970 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007971 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007972 return;
7973 }
7974
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007976
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007977 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007978 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7979 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007980
7981 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007982 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7983 ds_pool_ci.maxSets = 1;
7984 ds_pool_ci.poolSizeCount = 1;
7985 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007986
7987 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007988 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007989 ASSERT_VK_SUCCESS(err);
7990
7991 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007992 dsl_binding.binding = 0;
7993 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7994 dsl_binding.descriptorCount = 1;
7995 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007996
7997 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007998 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7999 ds_layout_ci.bindingCount = 1;
8000 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008001
8002 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008003 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008004 ASSERT_VK_SUCCESS(err);
8005
8006 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008007 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008008 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008009 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008010 alloc_info.descriptorPool = ds_pool;
8011 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008012 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008013 ASSERT_VK_SUCCESS(err);
8014
8015 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008016 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8017 pipeline_layout_ci.setLayoutCount = 1;
8018 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008019
8020 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008021 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008022 ASSERT_VK_SUCCESS(err);
8023
8024 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008025 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8026 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008027 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008028 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008029 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008030
8031 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8032 // Set scissor as dynamic to avoid that error
8033 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008034 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8035 dyn_state_ci.dynamicStateCount = 1;
8036 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008037
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008038 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8039 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8040 pipe_ms_state_ci.pNext = NULL;
8041 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8042 pipe_ms_state_ci.sampleShadingEnable = 0;
8043 pipe_ms_state_ci.minSampleShading = 1.0;
8044 pipe_ms_state_ci.pSampleMask = NULL;
8045
Cody Northropeb3a6c12015-10-05 14:44:45 -06008046 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008047 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008048
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008049 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008050 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8051 // 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 +08008052 shaderStages[0] = vs.GetStageCreateInfo();
8053 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008054
Cody Northropf6622dc2015-10-06 10:33:21 -06008055 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8056 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8057 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008058 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008059 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008060 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008061 vi_ci.pVertexAttributeDescriptions = nullptr;
8062
8063 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8064 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8065 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8066
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008067 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008068 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008069 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008070 rs_ci.pNext = nullptr;
8071
Mark Youngc89c6312016-03-31 16:03:20 -06008072 VkPipelineColorBlendAttachmentState att = {};
8073 att.blendEnable = VK_FALSE;
8074 att.colorWriteMask = 0xf;
8075
Cody Northropf6622dc2015-10-06 10:33:21 -06008076 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8077 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8078 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008079 cb_ci.attachmentCount = 1;
8080 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008081
Tobin Ehlise68360f2015-10-01 11:15:13 -06008082 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008083 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8084 gp_ci.stageCount = 2;
8085 gp_ci.pStages = shaderStages;
8086 gp_ci.pVertexInputState = &vi_ci;
8087 gp_ci.pInputAssemblyState = &ia_ci;
8088 gp_ci.pViewportState = &vp_state_ci;
8089 gp_ci.pRasterizationState = &rs_ci;
8090 gp_ci.pColorBlendState = &cb_ci;
8091 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008092 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008093 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8094 gp_ci.layout = pipeline_layout;
8095 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008096
8097 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008098 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008099
8100 VkPipeline pipeline;
8101 VkPipelineCache pipelineCache;
8102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008103 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008104 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008105 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008106
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008107 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008108
Tobin Ehlisd332f282015-10-02 11:00:56 -06008109 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008110 // First need to successfully create the PSO from above by setting
8111 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008112 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 -07008113
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008114 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008115 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008116 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008117 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008118 m_commandBuffer->BeginCommandBuffer();
8119 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008120 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008121 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008122 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008123 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008124 Draw(1, 0, 0, 0);
8125
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008126 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008127
8128 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8129 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8130 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8131 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008132 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008133}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008134
8135// 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 -07008136// viewportCount
8137TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8138 VkResult err;
8139
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008141
8142 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008143
8144 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008145 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008146 return;
8147 }
8148
Karl Schultz6addd812016-02-02 17:17:23 -07008149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8150
8151 VkDescriptorPoolSize ds_type_count = {};
8152 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8153 ds_type_count.descriptorCount = 1;
8154
8155 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8156 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8157 ds_pool_ci.maxSets = 1;
8158 ds_pool_ci.poolSizeCount = 1;
8159 ds_pool_ci.pPoolSizes = &ds_type_count;
8160
8161 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008162 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008163 ASSERT_VK_SUCCESS(err);
8164
8165 VkDescriptorSetLayoutBinding dsl_binding = {};
8166 dsl_binding.binding = 0;
8167 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8168 dsl_binding.descriptorCount = 1;
8169 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8170
8171 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8172 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8173 ds_layout_ci.bindingCount = 1;
8174 ds_layout_ci.pBindings = &dsl_binding;
8175
8176 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008177 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008178 ASSERT_VK_SUCCESS(err);
8179
8180 VkDescriptorSet descriptorSet;
8181 VkDescriptorSetAllocateInfo alloc_info = {};
8182 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8183 alloc_info.descriptorSetCount = 1;
8184 alloc_info.descriptorPool = ds_pool;
8185 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008186 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008187 ASSERT_VK_SUCCESS(err);
8188
8189 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8190 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8191 pipeline_layout_ci.setLayoutCount = 1;
8192 pipeline_layout_ci.pSetLayouts = &ds_layout;
8193
8194 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008195 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008196 ASSERT_VK_SUCCESS(err);
8197
8198 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8199 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8200 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008201 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008202 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008203 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008204
8205 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8206 // Set scissor as dynamic to avoid that error
8207 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8208 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8209 dyn_state_ci.dynamicStateCount = 1;
8210 dyn_state_ci.pDynamicStates = &vp_state;
8211
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008212 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8213 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8214 pipe_ms_state_ci.pNext = NULL;
8215 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8216 pipe_ms_state_ci.sampleShadingEnable = 0;
8217 pipe_ms_state_ci.minSampleShading = 1.0;
8218 pipe_ms_state_ci.pSampleMask = NULL;
8219
Karl Schultz6addd812016-02-02 17:17:23 -07008220 VkPipelineShaderStageCreateInfo shaderStages[2];
8221 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008223 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008224 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8225 // 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 -07008226 shaderStages[0] = vs.GetStageCreateInfo();
8227 shaderStages[1] = fs.GetStageCreateInfo();
8228
8229 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8230 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8231 vi_ci.pNext = nullptr;
8232 vi_ci.vertexBindingDescriptionCount = 0;
8233 vi_ci.pVertexBindingDescriptions = nullptr;
8234 vi_ci.vertexAttributeDescriptionCount = 0;
8235 vi_ci.pVertexAttributeDescriptions = nullptr;
8236
8237 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8238 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8239 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8240
8241 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8242 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008243 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008244 rs_ci.pNext = nullptr;
8245
Mark Youngc89c6312016-03-31 16:03:20 -06008246 VkPipelineColorBlendAttachmentState att = {};
8247 att.blendEnable = VK_FALSE;
8248 att.colorWriteMask = 0xf;
8249
Karl Schultz6addd812016-02-02 17:17:23 -07008250 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8251 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8252 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008253 cb_ci.attachmentCount = 1;
8254 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008255
8256 VkGraphicsPipelineCreateInfo gp_ci = {};
8257 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8258 gp_ci.stageCount = 2;
8259 gp_ci.pStages = shaderStages;
8260 gp_ci.pVertexInputState = &vi_ci;
8261 gp_ci.pInputAssemblyState = &ia_ci;
8262 gp_ci.pViewportState = &vp_state_ci;
8263 gp_ci.pRasterizationState = &rs_ci;
8264 gp_ci.pColorBlendState = &cb_ci;
8265 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008266 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008267 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8268 gp_ci.layout = pipeline_layout;
8269 gp_ci.renderPass = renderPass();
8270
8271 VkPipelineCacheCreateInfo pc_ci = {};
8272 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8273
8274 VkPipeline pipeline;
8275 VkPipelineCache pipelineCache;
8276
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008277 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008278 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008279 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008280
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008281 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008282
8283 // Now hit second fail case where we set scissor w/ different count than PSO
8284 // First need to successfully create the PSO from above by setting
8285 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8287 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008288
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008289 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008290 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008292 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008293 m_commandBuffer->BeginCommandBuffer();
8294 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008295 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008296 VkViewport viewports[1] = {};
8297 viewports[0].width = 8;
8298 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008299 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008300 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008301 Draw(1, 0, 0, 0);
8302
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008303 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008304
Chia-I Wuf7458c52015-10-26 21:10:41 +08008305 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8306 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8307 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8308 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008309 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008310}
8311
Mark Young7394fdd2016-03-31 14:56:43 -06008312TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8313 VkResult err;
8314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008316
8317 ASSERT_NO_FATAL_FAILURE(InitState());
8318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8319
8320 VkDescriptorPoolSize ds_type_count = {};
8321 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8322 ds_type_count.descriptorCount = 1;
8323
8324 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8325 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8326 ds_pool_ci.maxSets = 1;
8327 ds_pool_ci.poolSizeCount = 1;
8328 ds_pool_ci.pPoolSizes = &ds_type_count;
8329
8330 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008331 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008332 ASSERT_VK_SUCCESS(err);
8333
8334 VkDescriptorSetLayoutBinding dsl_binding = {};
8335 dsl_binding.binding = 0;
8336 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8337 dsl_binding.descriptorCount = 1;
8338 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8339
8340 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8341 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8342 ds_layout_ci.bindingCount = 1;
8343 ds_layout_ci.pBindings = &dsl_binding;
8344
8345 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008346 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008347 ASSERT_VK_SUCCESS(err);
8348
8349 VkDescriptorSet descriptorSet;
8350 VkDescriptorSetAllocateInfo alloc_info = {};
8351 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8352 alloc_info.descriptorSetCount = 1;
8353 alloc_info.descriptorPool = ds_pool;
8354 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008355 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008356 ASSERT_VK_SUCCESS(err);
8357
8358 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8359 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8360 pipeline_layout_ci.setLayoutCount = 1;
8361 pipeline_layout_ci.pSetLayouts = &ds_layout;
8362
8363 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008364 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008365 ASSERT_VK_SUCCESS(err);
8366
8367 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8368 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8369 vp_state_ci.scissorCount = 1;
8370 vp_state_ci.pScissors = NULL;
8371 vp_state_ci.viewportCount = 1;
8372 vp_state_ci.pViewports = NULL;
8373
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008374 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008375 // Set scissor as dynamic to avoid that error
8376 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8377 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8378 dyn_state_ci.dynamicStateCount = 2;
8379 dyn_state_ci.pDynamicStates = dynamic_states;
8380
8381 VkPipelineShaderStageCreateInfo shaderStages[2];
8382 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8383
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008384 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8385 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008386 this); // TODO - We shouldn't need a fragment shader
8387 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008388 shaderStages[0] = vs.GetStageCreateInfo();
8389 shaderStages[1] = fs.GetStageCreateInfo();
8390
8391 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8392 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8393 vi_ci.pNext = nullptr;
8394 vi_ci.vertexBindingDescriptionCount = 0;
8395 vi_ci.pVertexBindingDescriptions = nullptr;
8396 vi_ci.vertexAttributeDescriptionCount = 0;
8397 vi_ci.pVertexAttributeDescriptions = nullptr;
8398
8399 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8400 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8401 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8402
8403 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8404 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8405 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008406 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008407
Mark Young47107952016-05-02 15:59:55 -06008408 // Check too low (line width of -1.0f).
8409 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008410
8411 VkPipelineColorBlendAttachmentState att = {};
8412 att.blendEnable = VK_FALSE;
8413 att.colorWriteMask = 0xf;
8414
8415 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8416 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8417 cb_ci.pNext = nullptr;
8418 cb_ci.attachmentCount = 1;
8419 cb_ci.pAttachments = &att;
8420
8421 VkGraphicsPipelineCreateInfo gp_ci = {};
8422 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8423 gp_ci.stageCount = 2;
8424 gp_ci.pStages = shaderStages;
8425 gp_ci.pVertexInputState = &vi_ci;
8426 gp_ci.pInputAssemblyState = &ia_ci;
8427 gp_ci.pViewportState = &vp_state_ci;
8428 gp_ci.pRasterizationState = &rs_ci;
8429 gp_ci.pColorBlendState = &cb_ci;
8430 gp_ci.pDynamicState = &dyn_state_ci;
8431 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8432 gp_ci.layout = pipeline_layout;
8433 gp_ci.renderPass = renderPass();
8434
8435 VkPipelineCacheCreateInfo pc_ci = {};
8436 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8437
8438 VkPipeline pipeline;
8439 VkPipelineCache pipelineCache;
8440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008441 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008442 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008443 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008444
8445 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008446 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008447
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008449
8450 // Check too high (line width of 65536.0f).
8451 rs_ci.lineWidth = 65536.0f;
8452
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008453 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008454 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008455 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008456
8457 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008458 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008461
8462 dyn_state_ci.dynamicStateCount = 3;
8463
8464 rs_ci.lineWidth = 1.0f;
8465
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008466 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008467 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008468 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008469 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008470 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008471
8472 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008473 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008474 m_errorMonitor->VerifyFound();
8475
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008477
8478 // Check too high with dynamic setting.
8479 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8480 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008481 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008482
8483 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8484 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8485 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8486 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008487 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008488}
8489
Karl Schultz6addd812016-02-02 17:17:23 -07008490TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008491 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008493 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008494
8495 ASSERT_NO_FATAL_FAILURE(InitState());
8496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008497
Tony Barbour552f6c02016-12-21 14:34:07 -07008498 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008499 // Don't care about RenderPass handle b/c error should be flagged before
8500 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008501 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008502
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008503 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008504}
8505
Karl Schultz6addd812016-02-02 17:17:23 -07008506TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008507 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8509 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008510
8511 ASSERT_NO_FATAL_FAILURE(InitState());
8512 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008513
Tony Barbour552f6c02016-12-21 14:34:07 -07008514 m_commandBuffer->BeginCommandBuffer();
8515 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008516 // Just create a dummy Renderpass that's non-NULL so we can get to the
8517 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008519
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008520 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008521}
8522
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008523TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008524 TEST_DESCRIPTION(
8525 "Begin a renderPass where clearValueCount is less than"
8526 "the number of renderPass attachments that use loadOp"
8527 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008528
8529 ASSERT_NO_FATAL_FAILURE(InitState());
8530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8531
8532 // Create a renderPass with a single attachment that uses loadOp CLEAR
8533 VkAttachmentReference attach = {};
8534 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8535 VkSubpassDescription subpass = {};
8536 subpass.inputAttachmentCount = 1;
8537 subpass.pInputAttachments = &attach;
8538 VkRenderPassCreateInfo rpci = {};
8539 rpci.subpassCount = 1;
8540 rpci.pSubpasses = &subpass;
8541 rpci.attachmentCount = 1;
8542 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008543 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008544 // Set loadOp to CLEAR
8545 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8546 rpci.pAttachments = &attach_desc;
8547 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8548 VkRenderPass rp;
8549 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8550
8551 VkCommandBufferInheritanceInfo hinfo = {};
8552 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8553 hinfo.renderPass = VK_NULL_HANDLE;
8554 hinfo.subpass = 0;
8555 hinfo.framebuffer = VK_NULL_HANDLE;
8556 hinfo.occlusionQueryEnable = VK_FALSE;
8557 hinfo.queryFlags = 0;
8558 hinfo.pipelineStatistics = 0;
8559 VkCommandBufferBeginInfo info = {};
8560 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8561 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8562 info.pInheritanceInfo = &hinfo;
8563
8564 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8565 VkRenderPassBeginInfo rp_begin = {};
8566 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8567 rp_begin.pNext = NULL;
8568 rp_begin.renderPass = renderPass();
8569 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008570 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008571
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008573
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008574 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008575
8576 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008577
8578 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008579}
8580
Slawomir Cygan0808f392016-11-28 17:53:23 +01008581TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008582 TEST_DESCRIPTION(
8583 "Begin a renderPass where clearValueCount is greater than"
8584 "the number of renderPass attachments that use loadOp"
8585 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008586
8587 ASSERT_NO_FATAL_FAILURE(InitState());
8588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8589
8590 // Create a renderPass with a single attachment that uses loadOp CLEAR
8591 VkAttachmentReference attach = {};
8592 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8593 VkSubpassDescription subpass = {};
8594 subpass.inputAttachmentCount = 1;
8595 subpass.pInputAttachments = &attach;
8596 VkRenderPassCreateInfo rpci = {};
8597 rpci.subpassCount = 1;
8598 rpci.pSubpasses = &subpass;
8599 rpci.attachmentCount = 1;
8600 VkAttachmentDescription attach_desc = {};
8601 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8602 // Set loadOp to CLEAR
8603 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8604 rpci.pAttachments = &attach_desc;
8605 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8606 VkRenderPass rp;
8607 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8608
8609 VkCommandBufferBeginInfo info = {};
8610 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8611 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8612
8613 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8614 VkRenderPassBeginInfo rp_begin = {};
8615 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8616 rp_begin.pNext = NULL;
8617 rp_begin.renderPass = renderPass();
8618 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008619 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008620
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8622 " has a clearValueCount of"
8623 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008624
8625 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8626
8627 m_errorMonitor->VerifyFound();
8628
8629 vkDestroyRenderPass(m_device->device(), rp, NULL);
8630}
8631
Cody Northrop3bb4d962016-05-09 16:15:57 -06008632TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008633 TEST_DESCRIPTION("End a command buffer with an active render pass");
8634
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8636 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008637
8638 ASSERT_NO_FATAL_FAILURE(InitState());
8639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8640
Tony Barbour552f6c02016-12-21 14:34:07 -07008641 m_commandBuffer->BeginCommandBuffer();
8642 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8643 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008644
8645 m_errorMonitor->VerifyFound();
8646
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8648 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008649}
8650
Karl Schultz6addd812016-02-02 17:17:23 -07008651TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008652 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8654 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008655
8656 ASSERT_NO_FATAL_FAILURE(InitState());
8657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008658
Tony Barbour552f6c02016-12-21 14:34:07 -07008659 m_commandBuffer->BeginCommandBuffer();
8660 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008661
8662 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008663 vk_testing::Buffer dstBuffer;
8664 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008665
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008666 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008667
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008668 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008669}
8670
Karl Schultz6addd812016-02-02 17:17:23 -07008671TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008672 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8674 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008675
8676 ASSERT_NO_FATAL_FAILURE(InitState());
8677 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008678
Tony Barbour552f6c02016-12-21 14:34:07 -07008679 m_commandBuffer->BeginCommandBuffer();
8680 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008681
8682 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008683 vk_testing::Buffer dstBuffer;
8684 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008685
Karl Schultz6addd812016-02-02 17:17:23 -07008686 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008687 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8688 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8689 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008690
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008691 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008692}
8693
Karl Schultz6addd812016-02-02 17:17:23 -07008694TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008695 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8697 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008698
8699 ASSERT_NO_FATAL_FAILURE(InitState());
8700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008701
Tony Barbour552f6c02016-12-21 14:34:07 -07008702 m_commandBuffer->BeginCommandBuffer();
8703 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008704
Michael Lentine0a369f62016-02-03 16:51:46 -06008705 VkClearColorValue clear_color;
8706 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008707 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8708 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8709 const int32_t tex_width = 32;
8710 const int32_t tex_height = 32;
8711 VkImageCreateInfo image_create_info = {};
8712 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8713 image_create_info.pNext = NULL;
8714 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8715 image_create_info.format = tex_format;
8716 image_create_info.extent.width = tex_width;
8717 image_create_info.extent.height = tex_height;
8718 image_create_info.extent.depth = 1;
8719 image_create_info.mipLevels = 1;
8720 image_create_info.arrayLayers = 1;
8721 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8722 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8723 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008724
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008725 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008726 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008728 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008729
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008730 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008731 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008732
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008733 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008734}
8735
Karl Schultz6addd812016-02-02 17:17:23 -07008736TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008737 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8739 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008740
8741 ASSERT_NO_FATAL_FAILURE(InitState());
8742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008743
Tony Barbour552f6c02016-12-21 14:34:07 -07008744 m_commandBuffer->BeginCommandBuffer();
8745 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008746
8747 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008748 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008749 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8750 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8751 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8752 image_create_info.extent.width = 64;
8753 image_create_info.extent.height = 64;
8754 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8755 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008756
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008757 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008758 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008759
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008760 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008761
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008762 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8763 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008764
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008765 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008766}
8767
Karl Schultz6addd812016-02-02 17:17:23 -07008768TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008769 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008770 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008771
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8773 "vkCmdClearAttachments(): This call "
8774 "must be issued inside an active "
8775 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008776
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008777 ASSERT_NO_FATAL_FAILURE(InitState());
8778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008779
8780 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008781 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008782 ASSERT_VK_SUCCESS(err);
8783
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008784 VkClearAttachment color_attachment;
8785 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8786 color_attachment.clearValue.color.float32[0] = 0;
8787 color_attachment.clearValue.color.float32[1] = 0;
8788 color_attachment.clearValue.color.float32[2] = 0;
8789 color_attachment.clearValue.color.float32[3] = 0;
8790 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008791 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008792 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008793
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008794 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008795}
8796
Chris Forbes3b97e932016-09-07 11:29:24 +12008797TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008798 TEST_DESCRIPTION(
8799 "Test that an error is produced when CmdNextSubpass is "
8800 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008801
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8803 "vkCmdNextSubpass(): Attempted to advance "
8804 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008805
8806 ASSERT_NO_FATAL_FAILURE(InitState());
8807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8808
Tony Barbour552f6c02016-12-21 14:34:07 -07008809 m_commandBuffer->BeginCommandBuffer();
8810 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008811
8812 // error here.
8813 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8814 m_errorMonitor->VerifyFound();
8815
Tony Barbour552f6c02016-12-21 14:34:07 -07008816 m_commandBuffer->EndRenderPass();
8817 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008818}
8819
Chris Forbes6d624702016-09-07 13:57:05 +12008820TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008821 TEST_DESCRIPTION(
8822 "Test that an error is produced when CmdEndRenderPass is "
8823 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008824
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8826 "vkCmdEndRenderPass(): Called before reaching "
8827 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008828
8829 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008830 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8831 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008832
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008833 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008834
8835 VkRenderPass rp;
8836 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8837 ASSERT_VK_SUCCESS(err);
8838
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008839 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008840
8841 VkFramebuffer fb;
8842 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8843 ASSERT_VK_SUCCESS(err);
8844
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008845 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008847 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 +12008848
8849 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8850
8851 // Error here.
8852 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8853 m_errorMonitor->VerifyFound();
8854
8855 // Clean up.
8856 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8857 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8858}
8859
Karl Schultz9e66a292016-04-21 15:57:51 -06008860TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8861 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8863 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008864
8865 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008866 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008867
8868 VkBufferMemoryBarrier buf_barrier = {};
8869 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8870 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8871 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8872 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8873 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8874 buf_barrier.buffer = VK_NULL_HANDLE;
8875 buf_barrier.offset = 0;
8876 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008877 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8878 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008879
8880 m_errorMonitor->VerifyFound();
8881}
8882
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008883TEST_F(VkLayerTest, InvalidBarriers) {
8884 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8885
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008887
8888 ASSERT_NO_FATAL_FAILURE(InitState());
8889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8890
8891 VkMemoryBarrier mem_barrier = {};
8892 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8893 mem_barrier.pNext = NULL;
8894 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8895 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008896 m_commandBuffer->BeginCommandBuffer();
8897 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008898 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008899 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008900 &mem_barrier, 0, nullptr, 0, nullptr);
8901 m_errorMonitor->VerifyFound();
8902
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008904 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008905 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 -06008906 ASSERT_TRUE(image.initialized());
8907 VkImageMemoryBarrier img_barrier = {};
8908 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8909 img_barrier.pNext = NULL;
8910 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8911 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8912 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8913 // New layout can't be UNDEFINED
8914 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8915 img_barrier.image = image.handle();
8916 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8917 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8918 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8919 img_barrier.subresourceRange.baseArrayLayer = 0;
8920 img_barrier.subresourceRange.baseMipLevel = 0;
8921 img_barrier.subresourceRange.layerCount = 1;
8922 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008923 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8924 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008925 m_errorMonitor->VerifyFound();
8926 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8927
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8929 "Subresource must have the sum of the "
8930 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008931 // baseArrayLayer + layerCount must be <= image's arrayLayers
8932 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008933 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8934 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008935 m_errorMonitor->VerifyFound();
8936 img_barrier.subresourceRange.baseArrayLayer = 0;
8937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008939 // baseMipLevel + levelCount must be <= image's mipLevels
8940 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008941 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8942 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008943 m_errorMonitor->VerifyFound();
8944 img_barrier.subresourceRange.baseMipLevel = 0;
8945
Mike Weiblen7053aa32017-01-25 15:21:10 -07008946 // levelCount must be non-zero.
8947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8948 img_barrier.subresourceRange.levelCount = 0;
8949 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8950 nullptr, 0, nullptr, 1, &img_barrier);
8951 m_errorMonitor->VerifyFound();
8952 img_barrier.subresourceRange.levelCount = 1;
8953
8954 // layerCount must be non-zero.
8955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8956 img_barrier.subresourceRange.layerCount = 0;
8957 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8958 nullptr, 0, nullptr, 1, &img_barrier);
8959 m_errorMonitor->VerifyFound();
8960 img_barrier.subresourceRange.layerCount = 1;
8961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008962 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 -06008963 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008964 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8965 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008966 VkBufferMemoryBarrier buf_barrier = {};
8967 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8968 buf_barrier.pNext = NULL;
8969 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8970 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8971 buf_barrier.buffer = buffer.handle();
8972 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8973 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8974 buf_barrier.offset = 0;
8975 buf_barrier.size = VK_WHOLE_SIZE;
8976 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008977 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8978 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008979 m_errorMonitor->VerifyFound();
8980 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008983 buf_barrier.offset = 257;
8984 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008985 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8986 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008987 m_errorMonitor->VerifyFound();
8988 buf_barrier.offset = 0;
8989
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008991 buf_barrier.size = 257;
8992 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008993 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8994 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008995 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008996
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008997 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008998 m_errorMonitor->SetDesiredFailureMsg(
8999 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009000 "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 -06009001 VkDepthStencilObj ds_image(m_device);
9002 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9003 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009004 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9005 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009006 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009007
9008 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009009 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009010 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9011 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009012 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009013
9014 // Having anything other than DEPTH or STENCIL is an error
9015 m_errorMonitor->SetDesiredFailureMsg(
9016 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9017 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9018 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9019 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9020 nullptr, 0, nullptr, 1, &img_barrier);
9021 m_errorMonitor->VerifyFound();
9022
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009023 // Now test depth-only
9024 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009025 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9026 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009027 VkDepthStencilObj d_image(m_device);
9028 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9029 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009030 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009031 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009032 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009033
9034 // DEPTH bit must be set
9035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9036 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009037 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009038 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9039 0, nullptr, 0, nullptr, 1, &img_barrier);
9040 m_errorMonitor->VerifyFound();
9041
9042 // No bits other than DEPTH may be set
9043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9044 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9045 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009046 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9047 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009048 m_errorMonitor->VerifyFound();
9049 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009050
9051 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009052 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9053 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9055 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009056 VkDepthStencilObj s_image(m_device);
9057 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9058 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009059 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009060 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009061 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009062 // Use of COLOR aspect on depth image is error
9063 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009064 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9065 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009066 m_errorMonitor->VerifyFound();
9067 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009068
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009069 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009070 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009071 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 -06009072 ASSERT_TRUE(c_image.initialized());
9073 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9074 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9075 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009076
9077 // COLOR bit must be set
9078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9079 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009080 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009081 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9082 nullptr, 0, nullptr, 1, &img_barrier);
9083 m_errorMonitor->VerifyFound();
9084
9085 // No bits other than COLOR may be set
9086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9087 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9088 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009089 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9090 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009091 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009092
9093 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9094
9095 // Create command pool with incompatible queueflags
9096 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9097 uint32_t queue_family_index = UINT32_MAX;
9098 for (uint32_t i = 0; i < queue_props.size(); i++) {
9099 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9100 queue_family_index = i;
9101 break;
9102 }
9103 }
9104 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009105 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009106 return;
9107 }
9108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9109
9110 VkCommandPool command_pool;
9111 VkCommandPoolCreateInfo pool_create_info{};
9112 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9113 pool_create_info.queueFamilyIndex = queue_family_index;
9114 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9115 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9116
9117 // Allocate a command buffer
9118 VkCommandBuffer bad_command_buffer;
9119 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9120 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9121 command_buffer_allocate_info.commandPool = command_pool;
9122 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9123 command_buffer_allocate_info.commandBufferCount = 1;
9124 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9125
9126 VkCommandBufferBeginInfo cbbi = {};
9127 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9128 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9129 buf_barrier.offset = 0;
9130 buf_barrier.size = VK_WHOLE_SIZE;
9131 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9132 &buf_barrier, 0, nullptr);
9133 m_errorMonitor->VerifyFound();
9134
9135 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9136 vkEndCommandBuffer(bad_command_buffer);
9137 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009138 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009139 return;
9140 }
9141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9142 VkEvent event;
9143 VkEventCreateInfo event_create_info{};
9144 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9145 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9146 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9147 nullptr, 0, nullptr);
9148 m_errorMonitor->VerifyFound();
9149
9150 vkEndCommandBuffer(bad_command_buffer);
9151 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009152}
9153
Tony Barbour18ba25c2016-09-29 13:42:40 -06009154TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9155 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9156
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009158 ASSERT_NO_FATAL_FAILURE(InitState());
9159 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009160 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 -06009161 ASSERT_TRUE(image.initialized());
9162
9163 VkImageMemoryBarrier barrier = {};
9164 VkImageSubresourceRange range;
9165 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9166 barrier.srcAccessMask = 0;
9167 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9168 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9169 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9170 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9171 barrier.image = image.handle();
9172 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9173 range.baseMipLevel = 0;
9174 range.levelCount = 1;
9175 range.baseArrayLayer = 0;
9176 range.layerCount = 1;
9177 barrier.subresourceRange = range;
9178 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9179 cmdbuf.BeginCommandBuffer();
9180 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9181 &barrier);
9182 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9183 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9184 barrier.srcAccessMask = 0;
9185 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9186 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9187 &barrier);
9188
9189 m_errorMonitor->VerifyFound();
9190}
9191
Karl Schultz6addd812016-02-02 17:17:23 -07009192TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009193 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009194 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009195
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009197
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009198 ASSERT_NO_FATAL_FAILURE(InitState());
9199 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009200 uint32_t qfi = 0;
9201 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009202 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9203 buffCI.size = 1024;
9204 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9205 buffCI.queueFamilyIndexCount = 1;
9206 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009207
9208 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009209 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009210 ASSERT_VK_SUCCESS(err);
9211
Tony Barbour552f6c02016-12-21 14:34:07 -07009212 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009213 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009214 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9215 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009216 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009217 m_errorMonitor->SetUnexpectedError(
9218 "If buffer is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009219 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009220
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009221 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009222
Chia-I Wuf7458c52015-10-26 21:10:41 +08009223 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009224}
9225
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009226TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9227 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9229 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9230 "of the indices specified when the device was created, via the "
9231 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009232
9233 ASSERT_NO_FATAL_FAILURE(InitState());
9234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9235 VkBufferCreateInfo buffCI = {};
9236 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9237 buffCI.size = 1024;
9238 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9239 buffCI.queueFamilyIndexCount = 1;
9240 // Introduce failure by specifying invalid queue_family_index
9241 uint32_t qfi = 777;
9242 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009243 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009244
9245 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009246 m_errorMonitor->SetUnexpectedError(
9247 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009248 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9249
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009250 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009251 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009252}
9253
Karl Schultz6addd812016-02-02 17:17:23 -07009254TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009255 TEST_DESCRIPTION(
9256 "Attempt vkCmdExecuteCommands with a primary command buffer"
9257 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009258
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009259 ASSERT_NO_FATAL_FAILURE(InitState());
9260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009261
Chris Forbesf29a84f2016-10-06 18:39:28 +13009262 // An empty primary command buffer
9263 VkCommandBufferObj cb(m_device, m_commandPool);
9264 cb.BeginCommandBuffer();
9265 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009266
Chris Forbesf29a84f2016-10-06 18:39:28 +13009267 m_commandBuffer->BeginCommandBuffer();
9268 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9269 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009270
Chris Forbesf29a84f2016-10-06 18:39:28 +13009271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9272 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009273 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009274
9275 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009276}
9277
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009278TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009279 TEST_DESCRIPTION(
9280 "Attempt to update descriptor sets for images and buffers "
9281 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009282 VkResult err;
9283
9284 ASSERT_NO_FATAL_FAILURE(InitState());
9285 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9286 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9287 ds_type_count[i].type = VkDescriptorType(i);
9288 ds_type_count[i].descriptorCount = 1;
9289 }
9290 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9291 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9292 ds_pool_ci.pNext = NULL;
9293 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9294 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9295 ds_pool_ci.pPoolSizes = ds_type_count;
9296
9297 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009298 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009299 ASSERT_VK_SUCCESS(err);
9300
9301 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009302 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009303 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9304 dsl_binding[i].binding = 0;
9305 dsl_binding[i].descriptorType = VkDescriptorType(i);
9306 dsl_binding[i].descriptorCount = 1;
9307 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9308 dsl_binding[i].pImmutableSamplers = NULL;
9309 }
9310
9311 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9312 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9313 ds_layout_ci.pNext = NULL;
9314 ds_layout_ci.bindingCount = 1;
9315 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9316 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9317 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009318 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009319 ASSERT_VK_SUCCESS(err);
9320 }
9321 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9322 VkDescriptorSetAllocateInfo alloc_info = {};
9323 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9324 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9325 alloc_info.descriptorPool = ds_pool;
9326 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009327 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009328 ASSERT_VK_SUCCESS(err);
9329
9330 // Create a buffer & bufferView to be used for invalid updates
9331 VkBufferCreateInfo buff_ci = {};
9332 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009333 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009334 buff_ci.size = 256;
9335 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009336 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009337 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9338 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009339
9340 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9341 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9342 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9343 ASSERT_VK_SUCCESS(err);
9344
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009345 VkMemoryRequirements mem_reqs;
9346 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9347 VkMemoryAllocateInfo mem_alloc_info = {};
9348 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9349 mem_alloc_info.pNext = NULL;
9350 mem_alloc_info.memoryTypeIndex = 0;
9351 mem_alloc_info.allocationSize = mem_reqs.size;
9352 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9353 if (!pass) {
9354 vkDestroyBuffer(m_device->device(), buffer, NULL);
9355 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9356 return;
9357 }
9358 VkDeviceMemory mem;
9359 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9360 ASSERT_VK_SUCCESS(err);
9361 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9362 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009363
9364 VkBufferViewCreateInfo buff_view_ci = {};
9365 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9366 buff_view_ci.buffer = buffer;
9367 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9368 buff_view_ci.range = VK_WHOLE_SIZE;
9369 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009370 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009371 ASSERT_VK_SUCCESS(err);
9372
Tony Barbour415497c2017-01-24 10:06:09 -07009373 // Now get resources / view for storage_texel_buffer
9374 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9375 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9376 if (!pass) {
9377 vkDestroyBuffer(m_device->device(), buffer, NULL);
9378 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9379 vkFreeMemory(m_device->device(), mem, NULL);
9380 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9382 return;
9383 }
9384 VkDeviceMemory storage_texel_buffer_mem;
9385 VkBufferView storage_texel_buffer_view;
9386 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9387 ASSERT_VK_SUCCESS(err);
9388 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9389 ASSERT_VK_SUCCESS(err);
9390 buff_view_ci.buffer = storage_texel_buffer;
9391 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9392 ASSERT_VK_SUCCESS(err);
9393
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009394 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009395 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009396 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009397 image_ci.format = VK_FORMAT_UNDEFINED;
9398 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9399 VkFormat format = static_cast<VkFormat>(f);
9400 VkFormatProperties fProps = m_device->format_properties(format);
9401 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9402 image_ci.format = format;
9403 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9404 break;
9405 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9406 image_ci.format = format;
9407 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9408 break;
9409 }
9410 }
9411 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9412 return;
9413 }
9414
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009415 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9416 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009417 image_ci.extent.width = 64;
9418 image_ci.extent.height = 64;
9419 image_ci.extent.depth = 1;
9420 image_ci.mipLevels = 1;
9421 image_ci.arrayLayers = 1;
9422 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009423 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009424 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009425 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9426 VkImage image;
9427 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9428 ASSERT_VK_SUCCESS(err);
9429 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009430 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009431
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009432 VkMemoryAllocateInfo mem_alloc = {};
9433 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9434 mem_alloc.pNext = NULL;
9435 mem_alloc.allocationSize = 0;
9436 mem_alloc.memoryTypeIndex = 0;
9437 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9438 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009439 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009440 ASSERT_TRUE(pass);
9441 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9442 ASSERT_VK_SUCCESS(err);
9443 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9444 ASSERT_VK_SUCCESS(err);
9445 // Now create view for image
9446 VkImageViewCreateInfo image_view_ci = {};
9447 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9448 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009449 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009450 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9451 image_view_ci.subresourceRange.layerCount = 1;
9452 image_view_ci.subresourceRange.baseArrayLayer = 0;
9453 image_view_ci.subresourceRange.levelCount = 1;
9454 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9455 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009456 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009457 ASSERT_VK_SUCCESS(err);
9458
9459 VkDescriptorBufferInfo buff_info = {};
9460 buff_info.buffer = buffer;
9461 VkDescriptorImageInfo img_info = {};
9462 img_info.imageView = image_view;
9463 VkWriteDescriptorSet descriptor_write = {};
9464 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9465 descriptor_write.dstBinding = 0;
9466 descriptor_write.descriptorCount = 1;
9467 descriptor_write.pTexelBufferView = &buff_view;
9468 descriptor_write.pBufferInfo = &buff_info;
9469 descriptor_write.pImageInfo = &img_info;
9470
9471 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009472 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009473 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9474 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9475 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9476 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9477 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9478 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9479 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9480 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9481 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9482 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9483 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009484 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009485 // Start loop at 1 as SAMPLER desc type has no usage bit error
9486 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009487 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9488 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9489 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9490 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009491 descriptor_write.descriptorType = VkDescriptorType(i);
9492 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009494
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009495 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009496
9497 m_errorMonitor->VerifyFound();
9498 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009499 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9500 descriptor_write.pTexelBufferView = &buff_view;
9501 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009502 }
Tony Barbour415497c2017-01-24 10:06:09 -07009503
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009504 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9505 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009506 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009507 vkDestroyImageView(m_device->device(), image_view, NULL);
9508 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009509 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009510 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009511 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009512 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009513 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009514 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9515}
9516
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009517TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009518 TEST_DESCRIPTION(
9519 "Attempt to update buffer descriptor set that has incorrect "
9520 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9521 "1. offset value greater than buffer size\n"
9522 "2. range value of 0\n"
9523 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009524 VkResult err;
9525
9526 ASSERT_NO_FATAL_FAILURE(InitState());
9527 VkDescriptorPoolSize ds_type_count = {};
9528 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9529 ds_type_count.descriptorCount = 1;
9530
9531 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9532 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9533 ds_pool_ci.pNext = NULL;
9534 ds_pool_ci.maxSets = 1;
9535 ds_pool_ci.poolSizeCount = 1;
9536 ds_pool_ci.pPoolSizes = &ds_type_count;
9537
9538 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009539 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009540 ASSERT_VK_SUCCESS(err);
9541
9542 // Create layout with single uniform buffer descriptor
9543 VkDescriptorSetLayoutBinding dsl_binding = {};
9544 dsl_binding.binding = 0;
9545 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9546 dsl_binding.descriptorCount = 1;
9547 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9548 dsl_binding.pImmutableSamplers = NULL;
9549
9550 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9551 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9552 ds_layout_ci.pNext = NULL;
9553 ds_layout_ci.bindingCount = 1;
9554 ds_layout_ci.pBindings = &dsl_binding;
9555 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009556 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009557 ASSERT_VK_SUCCESS(err);
9558
9559 VkDescriptorSet descriptor_set = {};
9560 VkDescriptorSetAllocateInfo alloc_info = {};
9561 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9562 alloc_info.descriptorSetCount = 1;
9563 alloc_info.descriptorPool = ds_pool;
9564 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009565 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009566 ASSERT_VK_SUCCESS(err);
9567
9568 // Create a buffer to be used for invalid updates
9569 VkBufferCreateInfo buff_ci = {};
9570 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9571 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9572 buff_ci.size = 256;
9573 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9574 VkBuffer buffer;
9575 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9576 ASSERT_VK_SUCCESS(err);
9577 // Have to bind memory to buffer before descriptor update
9578 VkMemoryAllocateInfo mem_alloc = {};
9579 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9580 mem_alloc.pNext = NULL;
9581 mem_alloc.allocationSize = 256;
9582 mem_alloc.memoryTypeIndex = 0;
9583
9584 VkMemoryRequirements mem_reqs;
9585 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009586 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009587 if (!pass) {
9588 vkDestroyBuffer(m_device->device(), buffer, NULL);
9589 return;
9590 }
9591
9592 VkDeviceMemory mem;
9593 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9594 ASSERT_VK_SUCCESS(err);
9595 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9596 ASSERT_VK_SUCCESS(err);
9597
9598 VkDescriptorBufferInfo buff_info = {};
9599 buff_info.buffer = buffer;
9600 // First make offset 1 larger than buffer size
9601 buff_info.offset = 257;
9602 buff_info.range = VK_WHOLE_SIZE;
9603 VkWriteDescriptorSet descriptor_write = {};
9604 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9605 descriptor_write.dstBinding = 0;
9606 descriptor_write.descriptorCount = 1;
9607 descriptor_write.pTexelBufferView = nullptr;
9608 descriptor_write.pBufferInfo = &buff_info;
9609 descriptor_write.pImageInfo = nullptr;
9610
9611 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9612 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009614
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009615 m_errorMonitor->SetUnexpectedError(
9616 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9617 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009618 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9619
9620 m_errorMonitor->VerifyFound();
9621 // Now cause error due to range of 0
9622 buff_info.offset = 0;
9623 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009625
9626 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9627
9628 m_errorMonitor->VerifyFound();
9629 // Now cause error due to range exceeding buffer size - offset
9630 buff_info.offset = 128;
9631 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009633
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009634 m_errorMonitor->SetUnexpectedError(
9635 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9636 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009637 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9638
9639 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009640 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009641 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9642 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009643 m_errorMonitor->SetUnexpectedError(
9644 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009645 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9646 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9647}
9648
Tobin Ehlis845887e2017-02-02 19:01:44 -07009649TEST_F(VkLayerTest, DSBufferLimitErrors) {
9650 TEST_DESCRIPTION(
9651 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9652 "Test cases include:\n"
9653 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9654 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9655 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9656 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9657 VkResult err;
9658
9659 ASSERT_NO_FATAL_FAILURE(InitState());
9660 VkDescriptorPoolSize ds_type_count[2] = {};
9661 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9662 ds_type_count[0].descriptorCount = 1;
9663 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9664 ds_type_count[1].descriptorCount = 1;
9665
9666 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9667 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9668 ds_pool_ci.pNext = NULL;
9669 ds_pool_ci.maxSets = 1;
9670 ds_pool_ci.poolSizeCount = 2;
9671 ds_pool_ci.pPoolSizes = ds_type_count;
9672
9673 VkDescriptorPool ds_pool;
9674 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9675 ASSERT_VK_SUCCESS(err);
9676
9677 // Create layout with single uniform buffer & single storage buffer descriptor
9678 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9679 dsl_binding[0].binding = 0;
9680 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9681 dsl_binding[0].descriptorCount = 1;
9682 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9683 dsl_binding[0].pImmutableSamplers = NULL;
9684 dsl_binding[1].binding = 1;
9685 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9686 dsl_binding[1].descriptorCount = 1;
9687 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9688 dsl_binding[1].pImmutableSamplers = NULL;
9689
9690 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9691 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9692 ds_layout_ci.pNext = NULL;
9693 ds_layout_ci.bindingCount = 2;
9694 ds_layout_ci.pBindings = dsl_binding;
9695 VkDescriptorSetLayout ds_layout;
9696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9697 ASSERT_VK_SUCCESS(err);
9698
9699 VkDescriptorSet descriptor_set = {};
9700 VkDescriptorSetAllocateInfo alloc_info = {};
9701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9702 alloc_info.descriptorSetCount = 1;
9703 alloc_info.descriptorPool = ds_pool;
9704 alloc_info.pSetLayouts = &ds_layout;
9705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9706 ASSERT_VK_SUCCESS(err);
9707
9708 // Create a buffer to be used for invalid updates
9709 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9710 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9711 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9712 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9713 VkBufferCreateInfo ub_ci = {};
9714 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9715 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9716 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9717 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9718 VkBuffer uniform_buffer;
9719 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9720 ASSERT_VK_SUCCESS(err);
9721 VkBufferCreateInfo sb_ci = {};
9722 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9723 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9724 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9725 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9726 VkBuffer storage_buffer;
9727 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9728 ASSERT_VK_SUCCESS(err);
9729 // Have to bind memory to buffer before descriptor update
9730 VkMemoryAllocateInfo mem_alloc = {};
9731 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9732 mem_alloc.pNext = NULL;
9733 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9734 mem_alloc.memoryTypeIndex = 0;
9735
9736 VkMemoryRequirements mem_reqs;
9737 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9738 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9739 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9740 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9741 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009742 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009743 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009744 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9745 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009746 return;
9747 }
9748
9749 VkDeviceMemory mem;
9750 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009751 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009752 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9754 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9755 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9756 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9757 return;
9758 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009759 ASSERT_VK_SUCCESS(err);
9760 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9761 ASSERT_VK_SUCCESS(err);
9762 auto sb_offset = ub_ci.size + 1024;
9763 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9764 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9765 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9766 ASSERT_VK_SUCCESS(err);
9767
9768 VkDescriptorBufferInfo buff_info = {};
9769 buff_info.buffer = uniform_buffer;
9770 buff_info.range = ub_ci.size; // This will exceed limit
9771 VkWriteDescriptorSet descriptor_write = {};
9772 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9773 descriptor_write.dstBinding = 0;
9774 descriptor_write.descriptorCount = 1;
9775 descriptor_write.pTexelBufferView = nullptr;
9776 descriptor_write.pBufferInfo = &buff_info;
9777 descriptor_write.pImageInfo = nullptr;
9778
9779 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9780 descriptor_write.dstSet = descriptor_set;
9781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9782 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9783 m_errorMonitor->VerifyFound();
9784
9785 // Reduce size of range to acceptable limit & cause offset error
9786 buff_info.range = max_ub_range;
9787 buff_info.offset = min_ub_align - 1;
9788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9789 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9790 m_errorMonitor->VerifyFound();
9791
9792 // Now break storage updates
9793 buff_info.buffer = storage_buffer;
9794 buff_info.range = sb_ci.size; // This will exceed limit
9795 buff_info.offset = 0; // Reset offset for this update
9796
9797 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9798 descriptor_write.dstBinding = 1;
9799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9800 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9801 m_errorMonitor->VerifyFound();
9802
9803 // Reduce size of range to acceptable limit & cause offset error
9804 buff_info.range = max_sb_range;
9805 buff_info.offset = min_sb_align - 1;
9806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9807 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9808 m_errorMonitor->VerifyFound();
9809
9810 vkFreeMemory(m_device->device(), mem, NULL);
9811 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9812 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9813 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9814 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9815}
9816
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009817TEST_F(VkLayerTest, DSAspectBitsErrors) {
9818 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9819 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009820 TEST_DESCRIPTION(
9821 "Attempt to update descriptor sets for images "
9822 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009823 VkResult err;
9824
9825 ASSERT_NO_FATAL_FAILURE(InitState());
9826 VkDescriptorPoolSize ds_type_count = {};
9827 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9828 ds_type_count.descriptorCount = 1;
9829
9830 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9831 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9832 ds_pool_ci.pNext = NULL;
9833 ds_pool_ci.maxSets = 5;
9834 ds_pool_ci.poolSizeCount = 1;
9835 ds_pool_ci.pPoolSizes = &ds_type_count;
9836
9837 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009838 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009839 ASSERT_VK_SUCCESS(err);
9840
9841 VkDescriptorSetLayoutBinding dsl_binding = {};
9842 dsl_binding.binding = 0;
9843 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9844 dsl_binding.descriptorCount = 1;
9845 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9846 dsl_binding.pImmutableSamplers = NULL;
9847
9848 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9849 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9850 ds_layout_ci.pNext = NULL;
9851 ds_layout_ci.bindingCount = 1;
9852 ds_layout_ci.pBindings = &dsl_binding;
9853 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009854 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009855 ASSERT_VK_SUCCESS(err);
9856
9857 VkDescriptorSet descriptor_set = {};
9858 VkDescriptorSetAllocateInfo alloc_info = {};
9859 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9860 alloc_info.descriptorSetCount = 1;
9861 alloc_info.descriptorPool = ds_pool;
9862 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009863 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009864 ASSERT_VK_SUCCESS(err);
9865
9866 // Create an image to be used for invalid updates
9867 VkImageCreateInfo image_ci = {};
9868 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9869 image_ci.imageType = VK_IMAGE_TYPE_2D;
9870 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9871 image_ci.extent.width = 64;
9872 image_ci.extent.height = 64;
9873 image_ci.extent.depth = 1;
9874 image_ci.mipLevels = 1;
9875 image_ci.arrayLayers = 1;
9876 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9877 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9878 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9879 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9880 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9881 VkImage image;
9882 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9883 ASSERT_VK_SUCCESS(err);
9884 // Bind memory to image
9885 VkMemoryRequirements mem_reqs;
9886 VkDeviceMemory image_mem;
9887 bool pass;
9888 VkMemoryAllocateInfo mem_alloc = {};
9889 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9890 mem_alloc.pNext = NULL;
9891 mem_alloc.allocationSize = 0;
9892 mem_alloc.memoryTypeIndex = 0;
9893 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9894 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009896 ASSERT_TRUE(pass);
9897 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9898 ASSERT_VK_SUCCESS(err);
9899 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9900 ASSERT_VK_SUCCESS(err);
9901 // Now create view for image
9902 VkImageViewCreateInfo image_view_ci = {};
9903 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9904 image_view_ci.image = image;
9905 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9906 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9907 image_view_ci.subresourceRange.layerCount = 1;
9908 image_view_ci.subresourceRange.baseArrayLayer = 0;
9909 image_view_ci.subresourceRange.levelCount = 1;
9910 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009911 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009912
9913 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009914 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009915 ASSERT_VK_SUCCESS(err);
9916
9917 VkDescriptorImageInfo img_info = {};
9918 img_info.imageView = image_view;
9919 VkWriteDescriptorSet descriptor_write = {};
9920 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9921 descriptor_write.dstBinding = 0;
9922 descriptor_write.descriptorCount = 1;
9923 descriptor_write.pTexelBufferView = NULL;
9924 descriptor_write.pBufferInfo = NULL;
9925 descriptor_write.pImageInfo = &img_info;
9926 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9927 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009928 const char *error_msg =
9929 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9930 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009932
9933 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9934
9935 m_errorMonitor->VerifyFound();
9936 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9937 vkDestroyImage(m_device->device(), image, NULL);
9938 vkFreeMemory(m_device->device(), image_mem, NULL);
9939 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009940 m_errorMonitor->SetUnexpectedError(
9941 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009942 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9943 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9944}
9945
Karl Schultz6addd812016-02-02 17:17:23 -07009946TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009947 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009948 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9951 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9952 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009953
Tobin Ehlis3b780662015-05-28 12:11:26 -06009954 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009955 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009956 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009957 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9958 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009959
9960 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009961 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9962 ds_pool_ci.pNext = NULL;
9963 ds_pool_ci.maxSets = 1;
9964 ds_pool_ci.poolSizeCount = 1;
9965 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009966
Tobin Ehlis3b780662015-05-28 12:11:26 -06009967 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009968 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009969 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009970 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009971 dsl_binding.binding = 0;
9972 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9973 dsl_binding.descriptorCount = 1;
9974 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9975 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009976
Tony Barboureb254902015-07-15 12:50:33 -06009977 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009978 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9979 ds_layout_ci.pNext = NULL;
9980 ds_layout_ci.bindingCount = 1;
9981 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009982
Tobin Ehlis3b780662015-05-28 12:11:26 -06009983 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009984 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009985 ASSERT_VK_SUCCESS(err);
9986
9987 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009988 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009989 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009990 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009991 alloc_info.descriptorPool = ds_pool;
9992 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009993 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009994 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009995
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009996 VkSamplerCreateInfo sampler_ci = {};
9997 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9998 sampler_ci.pNext = NULL;
9999 sampler_ci.magFilter = VK_FILTER_NEAREST;
10000 sampler_ci.minFilter = VK_FILTER_NEAREST;
10001 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10002 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10003 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10004 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10005 sampler_ci.mipLodBias = 1.0;
10006 sampler_ci.anisotropyEnable = VK_FALSE;
10007 sampler_ci.maxAnisotropy = 1;
10008 sampler_ci.compareEnable = VK_FALSE;
10009 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10010 sampler_ci.minLod = 1.0;
10011 sampler_ci.maxLod = 1.0;
10012 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10013 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10014 VkSampler sampler;
10015 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10016 ASSERT_VK_SUCCESS(err);
10017
10018 VkDescriptorImageInfo info = {};
10019 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010020
10021 VkWriteDescriptorSet descriptor_write;
10022 memset(&descriptor_write, 0, sizeof(descriptor_write));
10023 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010024 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010025 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010026 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010027 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010028 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010029
10030 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10031
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010032 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010033
Chia-I Wuf7458c52015-10-26 21:10:41 +080010034 vkDestroySampler(m_device->device(), sampler, NULL);
10035 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10036 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010037}
10038
Karl Schultz6addd812016-02-02 17:17:23 -070010039TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010040 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010041 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010042
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010044
Tobin Ehlis3b780662015-05-28 12:11:26 -060010045 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010046 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010047 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010048 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10049 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010050
10051 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010052 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10053 ds_pool_ci.pNext = NULL;
10054 ds_pool_ci.maxSets = 1;
10055 ds_pool_ci.poolSizeCount = 1;
10056 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010057
Tobin Ehlis3b780662015-05-28 12:11:26 -060010058 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010059 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010060 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010061
Tony Barboureb254902015-07-15 12:50:33 -060010062 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010063 dsl_binding.binding = 0;
10064 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10065 dsl_binding.descriptorCount = 1;
10066 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10067 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010068
10069 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010070 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10071 ds_layout_ci.pNext = NULL;
10072 ds_layout_ci.bindingCount = 1;
10073 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010074
Tobin Ehlis3b780662015-05-28 12:11:26 -060010075 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010076 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010077 ASSERT_VK_SUCCESS(err);
10078
10079 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010080 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010081 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010082 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010083 alloc_info.descriptorPool = ds_pool;
10084 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010086 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010087
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010088 // Correctly update descriptor to avoid "NOT_UPDATED" error
10089 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010090 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010091 buff_info.offset = 0;
10092 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010093
10094 VkWriteDescriptorSet descriptor_write;
10095 memset(&descriptor_write, 0, sizeof(descriptor_write));
10096 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010097 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010098 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010099 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010100 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10101 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010102
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010103 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010104 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10105
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010106 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010107
Chia-I Wuf7458c52015-10-26 21:10:41 +080010108 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10109 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010110}
10111
Karl Schultz6addd812016-02-02 17:17:23 -070010112TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010113 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010114 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010115
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010117
Tobin Ehlis3b780662015-05-28 12:11:26 -060010118 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010119 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010120 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010121 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10122 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010123
10124 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010125 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10126 ds_pool_ci.pNext = NULL;
10127 ds_pool_ci.maxSets = 1;
10128 ds_pool_ci.poolSizeCount = 1;
10129 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010130
Tobin Ehlis3b780662015-05-28 12:11:26 -060010131 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010132 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010133 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010134
Tony Barboureb254902015-07-15 12:50:33 -060010135 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010136 dsl_binding.binding = 0;
10137 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10138 dsl_binding.descriptorCount = 1;
10139 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10140 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010141
10142 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010143 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10144 ds_layout_ci.pNext = NULL;
10145 ds_layout_ci.bindingCount = 1;
10146 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010147 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010148 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010149 ASSERT_VK_SUCCESS(err);
10150
10151 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010152 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010153 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010154 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010155 alloc_info.descriptorPool = ds_pool;
10156 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010157 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010158 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010159
Tony Barboureb254902015-07-15 12:50:33 -060010160 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010161 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10162 sampler_ci.pNext = NULL;
10163 sampler_ci.magFilter = VK_FILTER_NEAREST;
10164 sampler_ci.minFilter = VK_FILTER_NEAREST;
10165 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10166 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10167 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10168 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10169 sampler_ci.mipLodBias = 1.0;
10170 sampler_ci.anisotropyEnable = VK_FALSE;
10171 sampler_ci.maxAnisotropy = 1;
10172 sampler_ci.compareEnable = VK_FALSE;
10173 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10174 sampler_ci.minLod = 1.0;
10175 sampler_ci.maxLod = 1.0;
10176 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10177 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010178
Tobin Ehlis3b780662015-05-28 12:11:26 -060010179 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010180 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010181 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010182
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010183 VkDescriptorImageInfo info = {};
10184 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010185
10186 VkWriteDescriptorSet descriptor_write;
10187 memset(&descriptor_write, 0, sizeof(descriptor_write));
10188 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010189 descriptor_write.dstSet = descriptorSet;
10190 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010191 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010192 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010193 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010194 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010195
10196 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10197
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010198 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010199
Chia-I Wuf7458c52015-10-26 21:10:41 +080010200 vkDestroySampler(m_device->device(), sampler, NULL);
10201 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10202 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010203}
10204
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010205TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10206 // Create layout w/ empty binding and attempt to update it
10207 VkResult err;
10208
10209 ASSERT_NO_FATAL_FAILURE(InitState());
10210
10211 VkDescriptorPoolSize ds_type_count = {};
10212 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10213 ds_type_count.descriptorCount = 1;
10214
10215 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10216 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10217 ds_pool_ci.pNext = NULL;
10218 ds_pool_ci.maxSets = 1;
10219 ds_pool_ci.poolSizeCount = 1;
10220 ds_pool_ci.pPoolSizes = &ds_type_count;
10221
10222 VkDescriptorPool ds_pool;
10223 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10224 ASSERT_VK_SUCCESS(err);
10225
10226 VkDescriptorSetLayoutBinding dsl_binding = {};
10227 dsl_binding.binding = 0;
10228 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10229 dsl_binding.descriptorCount = 0;
10230 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10231 dsl_binding.pImmutableSamplers = NULL;
10232
10233 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10234 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10235 ds_layout_ci.pNext = NULL;
10236 ds_layout_ci.bindingCount = 1;
10237 ds_layout_ci.pBindings = &dsl_binding;
10238 VkDescriptorSetLayout ds_layout;
10239 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10240 ASSERT_VK_SUCCESS(err);
10241
10242 VkDescriptorSet descriptor_set;
10243 VkDescriptorSetAllocateInfo alloc_info = {};
10244 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10245 alloc_info.descriptorSetCount = 1;
10246 alloc_info.descriptorPool = ds_pool;
10247 alloc_info.pSetLayouts = &ds_layout;
10248 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10249 ASSERT_VK_SUCCESS(err);
10250
10251 VkSamplerCreateInfo sampler_ci = {};
10252 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10253 sampler_ci.magFilter = VK_FILTER_NEAREST;
10254 sampler_ci.minFilter = VK_FILTER_NEAREST;
10255 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10256 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10257 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10258 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10259 sampler_ci.mipLodBias = 1.0;
10260 sampler_ci.maxAnisotropy = 1;
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
10266 VkSampler sampler;
10267 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10268 ASSERT_VK_SUCCESS(err);
10269
10270 VkDescriptorImageInfo info = {};
10271 info.sampler = sampler;
10272
10273 VkWriteDescriptorSet descriptor_write;
10274 memset(&descriptor_write, 0, sizeof(descriptor_write));
10275 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10276 descriptor_write.dstSet = descriptor_set;
10277 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010278 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010279 // This is the wrong type, but empty binding error will be flagged first
10280 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10281 descriptor_write.pImageInfo = &info;
10282
10283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10284 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10285 m_errorMonitor->VerifyFound();
10286
10287 vkDestroySampler(m_device->device(), sampler, NULL);
10288 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10289 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10290}
10291
Karl Schultz6addd812016-02-02 17:17:23 -070010292TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10293 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10294 // types
10295 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010297 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 -060010298
Tobin Ehlis3b780662015-05-28 12:11:26 -060010299 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010300
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010301 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010302 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10303 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010304
10305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10307 ds_pool_ci.pNext = NULL;
10308 ds_pool_ci.maxSets = 1;
10309 ds_pool_ci.poolSizeCount = 1;
10310 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010311
Tobin Ehlis3b780662015-05-28 12:11:26 -060010312 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010314 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010315 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010316 dsl_binding.binding = 0;
10317 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10318 dsl_binding.descriptorCount = 1;
10319 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10320 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010321
Tony Barboureb254902015-07-15 12:50:33 -060010322 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010323 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10324 ds_layout_ci.pNext = NULL;
10325 ds_layout_ci.bindingCount = 1;
10326 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010327
Tobin Ehlis3b780662015-05-28 12:11:26 -060010328 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010330 ASSERT_VK_SUCCESS(err);
10331
10332 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010333 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010335 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010336 alloc_info.descriptorPool = ds_pool;
10337 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010339 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010340
Tony Barboureb254902015-07-15 12:50:33 -060010341 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010342 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10343 sampler_ci.pNext = NULL;
10344 sampler_ci.magFilter = VK_FILTER_NEAREST;
10345 sampler_ci.minFilter = VK_FILTER_NEAREST;
10346 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10347 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10348 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10349 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10350 sampler_ci.mipLodBias = 1.0;
10351 sampler_ci.anisotropyEnable = VK_FALSE;
10352 sampler_ci.maxAnisotropy = 1;
10353 sampler_ci.compareEnable = VK_FALSE;
10354 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10355 sampler_ci.minLod = 1.0;
10356 sampler_ci.maxLod = 1.0;
10357 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10358 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010359 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010360 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010361 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010362
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010363 VkDescriptorImageInfo info = {};
10364 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010365
10366 VkWriteDescriptorSet descriptor_write;
10367 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010368 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010369 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010370 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010371 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010372 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010373 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010374
10375 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10376
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010377 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010378
Chia-I Wuf7458c52015-10-26 21:10:41 +080010379 vkDestroySampler(m_device->device(), sampler, NULL);
10380 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010382}
10383
Karl Schultz6addd812016-02-02 17:17:23 -070010384TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010385 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010386 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010387
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010389
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010390 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010391 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10392 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010393 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010394 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10395 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010396
10397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10399 ds_pool_ci.pNext = NULL;
10400 ds_pool_ci.maxSets = 1;
10401 ds_pool_ci.poolSizeCount = 1;
10402 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010403
10404 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010406 ASSERT_VK_SUCCESS(err);
10407
10408 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010409 dsl_binding.binding = 0;
10410 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10411 dsl_binding.descriptorCount = 1;
10412 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10413 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010414
10415 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010416 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10417 ds_layout_ci.pNext = NULL;
10418 ds_layout_ci.bindingCount = 1;
10419 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010420 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010421 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010422 ASSERT_VK_SUCCESS(err);
10423
10424 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010425 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010426 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010427 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010428 alloc_info.descriptorPool = ds_pool;
10429 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010430 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010431 ASSERT_VK_SUCCESS(err);
10432
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010433 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010434
10435 VkDescriptorImageInfo descriptor_info;
10436 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10437 descriptor_info.sampler = sampler;
10438
10439 VkWriteDescriptorSet descriptor_write;
10440 memset(&descriptor_write, 0, sizeof(descriptor_write));
10441 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010442 descriptor_write.dstSet = descriptorSet;
10443 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010444 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010445 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10446 descriptor_write.pImageInfo = &descriptor_info;
10447
10448 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10449
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010450 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010451
Chia-I Wuf7458c52015-10-26 21:10:41 +080010452 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10453 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010454}
10455
Karl Schultz6addd812016-02-02 17:17:23 -070010456TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10457 // Create a single combined Image/Sampler descriptor and send it an invalid
10458 // imageView
10459 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010460
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010462
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010463 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010464 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010465 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10466 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010467
10468 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010469 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10470 ds_pool_ci.pNext = NULL;
10471 ds_pool_ci.maxSets = 1;
10472 ds_pool_ci.poolSizeCount = 1;
10473 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010474
10475 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010476 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010477 ASSERT_VK_SUCCESS(err);
10478
10479 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010480 dsl_binding.binding = 0;
10481 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10482 dsl_binding.descriptorCount = 1;
10483 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10484 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010485
10486 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010487 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10488 ds_layout_ci.pNext = NULL;
10489 ds_layout_ci.bindingCount = 1;
10490 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010491 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010492 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010493 ASSERT_VK_SUCCESS(err);
10494
10495 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010496 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010497 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010498 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010499 alloc_info.descriptorPool = ds_pool;
10500 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010501 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010502 ASSERT_VK_SUCCESS(err);
10503
10504 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010505 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10506 sampler_ci.pNext = NULL;
10507 sampler_ci.magFilter = VK_FILTER_NEAREST;
10508 sampler_ci.minFilter = VK_FILTER_NEAREST;
10509 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10510 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10511 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10512 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10513 sampler_ci.mipLodBias = 1.0;
10514 sampler_ci.anisotropyEnable = VK_FALSE;
10515 sampler_ci.maxAnisotropy = 1;
10516 sampler_ci.compareEnable = VK_FALSE;
10517 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10518 sampler_ci.minLod = 1.0;
10519 sampler_ci.maxLod = 1.0;
10520 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10521 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010522
10523 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010524 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010525 ASSERT_VK_SUCCESS(err);
10526
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010527 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010528
10529 VkDescriptorImageInfo descriptor_info;
10530 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10531 descriptor_info.sampler = sampler;
10532 descriptor_info.imageView = view;
10533
10534 VkWriteDescriptorSet descriptor_write;
10535 memset(&descriptor_write, 0, sizeof(descriptor_write));
10536 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010537 descriptor_write.dstSet = descriptorSet;
10538 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010539 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010540 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10541 descriptor_write.pImageInfo = &descriptor_info;
10542
10543 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10544
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010545 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010546
Chia-I Wuf7458c52015-10-26 21:10:41 +080010547 vkDestroySampler(m_device->device(), sampler, NULL);
10548 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010550}
10551
Karl Schultz6addd812016-02-02 17:17:23 -070010552TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10553 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10554 // into the other
10555 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010556
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10558 " binding #1 with type "
10559 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10560 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010561
Tobin Ehlis04356f92015-10-27 16:35:27 -060010562 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010563 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010564 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010565 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10566 ds_type_count[0].descriptorCount = 1;
10567 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10568 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010569
10570 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010571 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10572 ds_pool_ci.pNext = NULL;
10573 ds_pool_ci.maxSets = 1;
10574 ds_pool_ci.poolSizeCount = 2;
10575 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010576
10577 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010578 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010579 ASSERT_VK_SUCCESS(err);
10580 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010581 dsl_binding[0].binding = 0;
10582 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10583 dsl_binding[0].descriptorCount = 1;
10584 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10585 dsl_binding[0].pImmutableSamplers = NULL;
10586 dsl_binding[1].binding = 1;
10587 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10588 dsl_binding[1].descriptorCount = 1;
10589 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10590 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010591
10592 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010593 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10594 ds_layout_ci.pNext = NULL;
10595 ds_layout_ci.bindingCount = 2;
10596 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010597
10598 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010599 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010600 ASSERT_VK_SUCCESS(err);
10601
10602 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010603 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010605 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010606 alloc_info.descriptorPool = ds_pool;
10607 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010608 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010609 ASSERT_VK_SUCCESS(err);
10610
10611 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010612 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10613 sampler_ci.pNext = NULL;
10614 sampler_ci.magFilter = VK_FILTER_NEAREST;
10615 sampler_ci.minFilter = VK_FILTER_NEAREST;
10616 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10617 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10618 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10619 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10620 sampler_ci.mipLodBias = 1.0;
10621 sampler_ci.anisotropyEnable = VK_FALSE;
10622 sampler_ci.maxAnisotropy = 1;
10623 sampler_ci.compareEnable = VK_FALSE;
10624 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10625 sampler_ci.minLod = 1.0;
10626 sampler_ci.maxLod = 1.0;
10627 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10628 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010629
10630 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010631 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010632 ASSERT_VK_SUCCESS(err);
10633
10634 VkDescriptorImageInfo info = {};
10635 info.sampler = sampler;
10636
10637 VkWriteDescriptorSet descriptor_write;
10638 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10639 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010640 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010641 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010642 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10644 descriptor_write.pImageInfo = &info;
10645 // This write update should succeed
10646 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10647 // Now perform a copy update that fails due to type mismatch
10648 VkCopyDescriptorSet copy_ds_update;
10649 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10650 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10651 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010652 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010653 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010654 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10655 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010656 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10657
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010658 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010659 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010660 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 -060010661 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10662 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10663 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010664 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010665 copy_ds_update.dstSet = descriptorSet;
10666 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010667 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010668 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10669
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010670 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010671
Tobin Ehlis04356f92015-10-27 16:35:27 -060010672 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10674 " binding#1 with offset index of 1 plus "
10675 "update array offset of 0 and update of "
10676 "5 descriptors oversteps total number "
10677 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010678
Tobin Ehlis04356f92015-10-27 16:35:27 -060010679 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10680 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10681 copy_ds_update.srcSet = descriptorSet;
10682 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010683 copy_ds_update.dstSet = descriptorSet;
10684 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010685 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010686 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10687
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010688 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010689
Chia-I Wuf7458c52015-10-26 21:10:41 +080010690 vkDestroySampler(m_device->device(), sampler, NULL);
10691 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10692 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010693}
10694
Karl Schultz6addd812016-02-02 17:17:23 -070010695TEST_F(VkLayerTest, NumSamplesMismatch) {
10696 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10697 // sampleCount
10698 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010701
Tobin Ehlis3b780662015-05-28 12:11:26 -060010702 ASSERT_NO_FATAL_FAILURE(InitState());
10703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010704 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010705 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010706 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010707
10708 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010709 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10710 ds_pool_ci.pNext = NULL;
10711 ds_pool_ci.maxSets = 1;
10712 ds_pool_ci.poolSizeCount = 1;
10713 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010714
Tobin Ehlis3b780662015-05-28 12:11:26 -060010715 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010716 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010717 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010718
Tony Barboureb254902015-07-15 12:50:33 -060010719 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010720 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010721 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010722 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010723 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10724 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010725
Tony Barboureb254902015-07-15 12:50:33 -060010726 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10727 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10728 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010729 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010730 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010731
Tobin Ehlis3b780662015-05-28 12:11:26 -060010732 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010733 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010734 ASSERT_VK_SUCCESS(err);
10735
10736 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010737 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010738 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010739 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010740 alloc_info.descriptorPool = ds_pool;
10741 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010743 ASSERT_VK_SUCCESS(err);
10744
Tony Barboureb254902015-07-15 12:50:33 -060010745 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010746 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010747 pipe_ms_state_ci.pNext = NULL;
10748 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10749 pipe_ms_state_ci.sampleShadingEnable = 0;
10750 pipe_ms_state_ci.minSampleShading = 1.0;
10751 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010752
Tony Barboureb254902015-07-15 12:50:33 -060010753 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010754 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10755 pipeline_layout_ci.pNext = NULL;
10756 pipeline_layout_ci.setLayoutCount = 1;
10757 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010758
10759 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010760 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010761 ASSERT_VK_SUCCESS(err);
10762
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010763 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010764 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 -060010765 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010766 VkPipelineObj pipe(m_device);
10767 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010768 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010769 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010770 pipe.SetMSAA(&pipe_ms_state_ci);
10771 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010772
Tony Barbour552f6c02016-12-21 14:34:07 -070010773 m_commandBuffer->BeginCommandBuffer();
10774 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010775 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010776
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010777 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10778 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10779 VkRect2D scissor = {{0, 0}, {16, 16}};
10780 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10781
Mark Young29927482016-05-04 14:38:51 -060010782 // Render triangle (the error should trigger on the attempt to draw).
10783 Draw(3, 1, 0, 0);
10784
10785 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010786 m_commandBuffer->EndRenderPass();
10787 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010788
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010789 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010790
Chia-I Wuf7458c52015-10-26 21:10:41 +080010791 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10792 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10793 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010794}
Mark Young29927482016-05-04 14:38:51 -060010795
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010796TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010797 TEST_DESCRIPTION(
10798 "Hit RenderPass incompatible cases. "
10799 "Initial case is drawing with an active renderpass that's "
10800 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010801 VkResult err;
10802
10803 ASSERT_NO_FATAL_FAILURE(InitState());
10804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10805
10806 VkDescriptorSetLayoutBinding dsl_binding = {};
10807 dsl_binding.binding = 0;
10808 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10809 dsl_binding.descriptorCount = 1;
10810 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10811 dsl_binding.pImmutableSamplers = NULL;
10812
10813 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10814 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10815 ds_layout_ci.pNext = NULL;
10816 ds_layout_ci.bindingCount = 1;
10817 ds_layout_ci.pBindings = &dsl_binding;
10818
10819 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010820 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010821 ASSERT_VK_SUCCESS(err);
10822
10823 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10824 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10825 pipeline_layout_ci.pNext = NULL;
10826 pipeline_layout_ci.setLayoutCount = 1;
10827 pipeline_layout_ci.pSetLayouts = &ds_layout;
10828
10829 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010830 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010831 ASSERT_VK_SUCCESS(err);
10832
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010834 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 -060010835 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010836 // Create a renderpass that will be incompatible with default renderpass
10837 VkAttachmentReference attach = {};
10838 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10839 VkAttachmentReference color_att = {};
10840 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10841 VkSubpassDescription subpass = {};
10842 subpass.inputAttachmentCount = 1;
10843 subpass.pInputAttachments = &attach;
10844 subpass.colorAttachmentCount = 1;
10845 subpass.pColorAttachments = &color_att;
10846 VkRenderPassCreateInfo rpci = {};
10847 rpci.subpassCount = 1;
10848 rpci.pSubpasses = &subpass;
10849 rpci.attachmentCount = 1;
10850 VkAttachmentDescription attach_desc = {};
10851 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010852 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10853 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010854 rpci.pAttachments = &attach_desc;
10855 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10856 VkRenderPass rp;
10857 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10858 VkPipelineObj pipe(m_device);
10859 pipe.AddShader(&vs);
10860 pipe.AddShader(&fs);
10861 pipe.AddColorAttachment();
10862 VkViewport view_port = {};
10863 m_viewports.push_back(view_port);
10864 pipe.SetViewport(m_viewports);
10865 VkRect2D rect = {};
10866 m_scissors.push_back(rect);
10867 pipe.SetScissor(m_scissors);
10868 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10869
10870 VkCommandBufferInheritanceInfo cbii = {};
10871 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10872 cbii.renderPass = rp;
10873 cbii.subpass = 0;
10874 VkCommandBufferBeginInfo cbbi = {};
10875 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10876 cbbi.pInheritanceInfo = &cbii;
10877 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10878 VkRenderPassBeginInfo rpbi = {};
10879 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10880 rpbi.framebuffer = m_framebuffer;
10881 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010882 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10883 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010886 // Render triangle (the error should trigger on the attempt to draw).
10887 Draw(3, 1, 0, 0);
10888
10889 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010890 m_commandBuffer->EndRenderPass();
10891 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010892
10893 m_errorMonitor->VerifyFound();
10894
10895 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10896 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10897 vkDestroyRenderPass(m_device->device(), rp, NULL);
10898}
10899
Mark Youngc89c6312016-03-31 16:03:20 -060010900TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10901 // Create Pipeline where the number of blend attachments doesn't match the
10902 // number of color attachments. In this case, we don't add any color
10903 // blend attachments even though we have a color attachment.
10904 VkResult err;
10905
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010907
10908 ASSERT_NO_FATAL_FAILURE(InitState());
10909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10910 VkDescriptorPoolSize ds_type_count = {};
10911 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10912 ds_type_count.descriptorCount = 1;
10913
10914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10916 ds_pool_ci.pNext = NULL;
10917 ds_pool_ci.maxSets = 1;
10918 ds_pool_ci.poolSizeCount = 1;
10919 ds_pool_ci.pPoolSizes = &ds_type_count;
10920
10921 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010922 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010923 ASSERT_VK_SUCCESS(err);
10924
10925 VkDescriptorSetLayoutBinding dsl_binding = {};
10926 dsl_binding.binding = 0;
10927 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10928 dsl_binding.descriptorCount = 1;
10929 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10930 dsl_binding.pImmutableSamplers = NULL;
10931
10932 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10933 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10934 ds_layout_ci.pNext = NULL;
10935 ds_layout_ci.bindingCount = 1;
10936 ds_layout_ci.pBindings = &dsl_binding;
10937
10938 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010939 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010940 ASSERT_VK_SUCCESS(err);
10941
10942 VkDescriptorSet descriptorSet;
10943 VkDescriptorSetAllocateInfo alloc_info = {};
10944 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10945 alloc_info.descriptorSetCount = 1;
10946 alloc_info.descriptorPool = ds_pool;
10947 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010948 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010949 ASSERT_VK_SUCCESS(err);
10950
10951 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010952 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010953 pipe_ms_state_ci.pNext = NULL;
10954 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10955 pipe_ms_state_ci.sampleShadingEnable = 0;
10956 pipe_ms_state_ci.minSampleShading = 1.0;
10957 pipe_ms_state_ci.pSampleMask = NULL;
10958
10959 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10960 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10961 pipeline_layout_ci.pNext = NULL;
10962 pipeline_layout_ci.setLayoutCount = 1;
10963 pipeline_layout_ci.pSetLayouts = &ds_layout;
10964
10965 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010966 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010967 ASSERT_VK_SUCCESS(err);
10968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010969 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010970 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 -060010971 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010972 VkPipelineObj pipe(m_device);
10973 pipe.AddShader(&vs);
10974 pipe.AddShader(&fs);
10975 pipe.SetMSAA(&pipe_ms_state_ci);
10976 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010977 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010978
10979 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10981 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10982}
Mark Young29927482016-05-04 14:38:51 -060010983
Mark Muellerd4914412016-06-13 17:52:06 -060010984TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010985 TEST_DESCRIPTION(
10986 "Points to a wrong colorAttachment index in a VkClearAttachment "
10987 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010988 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010990
10991 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10992 m_errorMonitor->VerifyFound();
10993}
10994
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010995TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010996 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10997 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010998
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010999 ASSERT_NO_FATAL_FAILURE(InitState());
11000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011001
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011002 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011003 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11004 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011005
11006 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011007 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11008 ds_pool_ci.pNext = NULL;
11009 ds_pool_ci.maxSets = 1;
11010 ds_pool_ci.poolSizeCount = 1;
11011 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011012
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011013 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011014 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011015 ASSERT_VK_SUCCESS(err);
11016
Tony Barboureb254902015-07-15 12:50:33 -060011017 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011018 dsl_binding.binding = 0;
11019 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11020 dsl_binding.descriptorCount = 1;
11021 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11022 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011023
Tony Barboureb254902015-07-15 12:50:33 -060011024 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011025 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11026 ds_layout_ci.pNext = NULL;
11027 ds_layout_ci.bindingCount = 1;
11028 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011029
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011030 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011031 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011032 ASSERT_VK_SUCCESS(err);
11033
11034 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011035 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011036 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011037 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011038 alloc_info.descriptorPool = ds_pool;
11039 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011040 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011041 ASSERT_VK_SUCCESS(err);
11042
Tony Barboureb254902015-07-15 12:50:33 -060011043 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011044 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011045 pipe_ms_state_ci.pNext = NULL;
11046 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11047 pipe_ms_state_ci.sampleShadingEnable = 0;
11048 pipe_ms_state_ci.minSampleShading = 1.0;
11049 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011050
Tony Barboureb254902015-07-15 12:50:33 -060011051 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011052 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11053 pipeline_layout_ci.pNext = NULL;
11054 pipeline_layout_ci.setLayoutCount = 1;
11055 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011056
11057 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011058 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011059 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011061 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011062 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011063 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011064 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011065
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011066 VkPipelineObj pipe(m_device);
11067 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011068 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011069 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011070 m_errorMonitor->SetUnexpectedError(
11071 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11072 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011073 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011074
Tony Barbour552f6c02016-12-21 14:34:07 -070011075 m_commandBuffer->BeginCommandBuffer();
11076 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011077
Karl Schultz6addd812016-02-02 17:17:23 -070011078 // Main thing we care about for this test is that the VkImage obj we're
11079 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011080 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011081 VkClearAttachment color_attachment;
11082 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11083 color_attachment.clearValue.color.float32[0] = 1.0;
11084 color_attachment.clearValue.color.float32[1] = 1.0;
11085 color_attachment.clearValue.color.float32[2] = 1.0;
11086 color_attachment.clearValue.color.float32[3] = 1.0;
11087 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011088 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011089
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011090 // Call for full-sized FB Color attachment prior to issuing a Draw
11091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011092 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011093 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011094 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011095
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011096 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11097 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11099 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11100 m_errorMonitor->VerifyFound();
11101
11102 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11103 clear_rect.layerCount = 2;
11104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11105 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011106 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011107
Chia-I Wuf7458c52015-10-26 21:10:41 +080011108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11109 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11110 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011111}
11112
Karl Schultz6addd812016-02-02 17:17:23 -070011113TEST_F(VkLayerTest, VtxBufferBadIndex) {
11114 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11117 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011118
Tobin Ehlis502480b2015-06-24 15:53:07 -060011119 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011120 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011122
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011123 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011124 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11125 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011126
11127 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011128 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11129 ds_pool_ci.pNext = NULL;
11130 ds_pool_ci.maxSets = 1;
11131 ds_pool_ci.poolSizeCount = 1;
11132 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011133
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011134 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011135 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011136 ASSERT_VK_SUCCESS(err);
11137
Tony Barboureb254902015-07-15 12:50:33 -060011138 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011139 dsl_binding.binding = 0;
11140 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11141 dsl_binding.descriptorCount = 1;
11142 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11143 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011144
Tony Barboureb254902015-07-15 12:50:33 -060011145 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011146 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11147 ds_layout_ci.pNext = NULL;
11148 ds_layout_ci.bindingCount = 1;
11149 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011150
Tobin Ehlis502480b2015-06-24 15:53:07 -060011151 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011152 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011153 ASSERT_VK_SUCCESS(err);
11154
11155 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011156 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011157 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011158 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011159 alloc_info.descriptorPool = ds_pool;
11160 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011161 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011162 ASSERT_VK_SUCCESS(err);
11163
Tony Barboureb254902015-07-15 12:50:33 -060011164 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011165 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011166 pipe_ms_state_ci.pNext = NULL;
11167 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11168 pipe_ms_state_ci.sampleShadingEnable = 0;
11169 pipe_ms_state_ci.minSampleShading = 1.0;
11170 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011171
Tony Barboureb254902015-07-15 12:50:33 -060011172 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011173 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11174 pipeline_layout_ci.pNext = NULL;
11175 pipeline_layout_ci.setLayoutCount = 1;
11176 pipeline_layout_ci.pSetLayouts = &ds_layout;
11177 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011179 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011180 ASSERT_VK_SUCCESS(err);
11181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011182 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011183 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 -060011184 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011185 VkPipelineObj pipe(m_device);
11186 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011187 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011188 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011189 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011190 pipe.SetViewport(m_viewports);
11191 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011192 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011193
Tony Barbour552f6c02016-12-21 14:34:07 -070011194 m_commandBuffer->BeginCommandBuffer();
11195 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011196 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011197 // Don't care about actual data, just need to get to draw to flag error
11198 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011199 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011200 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011201 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011202
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011203 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011204
Chia-I Wuf7458c52015-10-26 21:10:41 +080011205 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11206 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11207 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011208}
Mark Muellerdfe37552016-07-07 14:47:42 -060011209
Mark Mueller2ee294f2016-08-04 12:59:48 -060011210TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011211 TEST_DESCRIPTION(
11212 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11213 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011214 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011215
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011216 const char *invalid_queueFamilyIndex_message =
11217 "Invalid queue create request in vkCreateDevice(). Invalid "
11218 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011220 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011221
Mark Mueller880fce52016-08-17 15:23:23 -060011222 // The following test fails with recent NVidia drivers.
11223 // By the time core_validation is reached, the NVidia
11224 // driver has sanitized the invalid condition and core_validation
11225 // is not introduced to the failure condition. This is not the case
11226 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011227 // uint32_t count = static_cast<uint32_t>(~0);
11228 // VkPhysicalDevice physical_device;
11229 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11230 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011233 float queue_priority = 0.0;
11234
11235 VkDeviceQueueCreateInfo queue_create_info = {};
11236 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11237 queue_create_info.queueCount = 1;
11238 queue_create_info.pQueuePriorities = &queue_priority;
11239 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11240
11241 VkPhysicalDeviceFeatures features = m_device->phy().features();
11242 VkDevice testDevice;
11243 VkDeviceCreateInfo device_create_info = {};
11244 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11245 device_create_info.queueCreateInfoCount = 1;
11246 device_create_info.pQueueCreateInfos = &queue_create_info;
11247 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011248 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011249 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11250 m_errorMonitor->VerifyFound();
11251
11252 queue_create_info.queueFamilyIndex = 1;
11253
11254 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11255 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11256 for (unsigned i = 0; i < feature_count; i++) {
11257 if (VK_FALSE == feature_array[i]) {
11258 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011260 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011261 m_errorMonitor->SetUnexpectedError(
11262 "You requested features that are unavailable on this device. You should first query feature availability by "
11263 "calling vkGetPhysicalDeviceFeatures().");
11264 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011265 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11266 m_errorMonitor->VerifyFound();
11267 break;
11268 }
11269 }
11270}
11271
Tobin Ehlis16edf082016-11-21 12:33:49 -070011272TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11273 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11274
11275 ASSERT_NO_FATAL_FAILURE(InitState());
11276
11277 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11278 std::vector<VkDeviceQueueCreateInfo> queue_info;
11279 queue_info.reserve(queue_props.size());
11280 std::vector<std::vector<float>> queue_priorities;
11281 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11282 VkDeviceQueueCreateInfo qi{};
11283 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11284 qi.queueFamilyIndex = i;
11285 qi.queueCount = queue_props[i].queueCount;
11286 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11287 qi.pQueuePriorities = queue_priorities[i].data();
11288 queue_info.push_back(qi);
11289 }
11290
11291 std::vector<const char *> device_extension_names;
11292
11293 VkDevice local_device;
11294 VkDeviceCreateInfo device_create_info = {};
11295 auto features = m_device->phy().features();
11296 // Intentionally disable pipeline stats
11297 features.pipelineStatisticsQuery = VK_FALSE;
11298 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11299 device_create_info.pNext = NULL;
11300 device_create_info.queueCreateInfoCount = queue_info.size();
11301 device_create_info.pQueueCreateInfos = queue_info.data();
11302 device_create_info.enabledLayerCount = 0;
11303 device_create_info.ppEnabledLayerNames = NULL;
11304 device_create_info.pEnabledFeatures = &features;
11305 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11306 ASSERT_VK_SUCCESS(err);
11307
11308 VkQueryPoolCreateInfo qpci{};
11309 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11310 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11311 qpci.queryCount = 1;
11312 VkQueryPool query_pool;
11313
11314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11315 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11316 m_errorMonitor->VerifyFound();
11317
11318 vkDestroyDevice(local_device, nullptr);
11319}
11320
Mark Mueller2ee294f2016-08-04 12:59:48 -060011321TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011322 TEST_DESCRIPTION(
11323 "Use an invalid queue index in a vkCmdWaitEvents call."
11324 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011325
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011326 const char *invalid_queue_index =
11327 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11328 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11329 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011330
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011331 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011332
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011334
11335 ASSERT_NO_FATAL_FAILURE(InitState());
11336
11337 VkEvent event;
11338 VkEventCreateInfo event_create_info{};
11339 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11340 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11341
Mark Mueller2ee294f2016-08-04 12:59:48 -060011342 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011343 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011344
Tony Barbour552f6c02016-12-21 14:34:07 -070011345 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011346
11347 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011348 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 -060011349 ASSERT_TRUE(image.initialized());
11350 VkImageMemoryBarrier img_barrier = {};
11351 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11352 img_barrier.pNext = NULL;
11353 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11354 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11355 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11356 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11357 img_barrier.image = image.handle();
11358 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011359
11360 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11361 // that layer validation catches the case when it is not.
11362 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011363 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11364 img_barrier.subresourceRange.baseArrayLayer = 0;
11365 img_barrier.subresourceRange.baseMipLevel = 0;
11366 img_barrier.subresourceRange.layerCount = 1;
11367 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011368 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11369 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011370 m_errorMonitor->VerifyFound();
11371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011373
11374 VkQueryPool query_pool;
11375 VkQueryPoolCreateInfo query_pool_create_info = {};
11376 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11377 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11378 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011379 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011381 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011382 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11383
11384 vkEndCommandBuffer(m_commandBuffer->handle());
11385 m_errorMonitor->VerifyFound();
11386
11387 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11388 vkDestroyEvent(m_device->device(), event, nullptr);
11389}
11390
Mark Muellerdfe37552016-07-07 14:47:42 -060011391TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011392 TEST_DESCRIPTION(
11393 "Submit a command buffer using deleted vertex buffer, "
11394 "delete a buffer twice, use an invalid offset for each "
11395 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011396
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011397 const char *deleted_buffer_in_command_buffer =
11398 "Cannot submit cmd buffer "
11399 "using deleted buffer ";
11400 const char *invalid_offset_message =
11401 "vkBindBufferMemory(): "
11402 "memoryOffset is 0x";
11403 const char *invalid_storage_buffer_offset_message =
11404 "vkBindBufferMemory(): "
11405 "storage memoryOffset "
11406 "is 0x";
11407 const char *invalid_texel_buffer_offset_message =
11408 "vkBindBufferMemory(): "
11409 "texel memoryOffset "
11410 "is 0x";
11411 const char *invalid_uniform_buffer_offset_message =
11412 "vkBindBufferMemory(): "
11413 "uniform memoryOffset "
11414 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011415
11416 ASSERT_NO_FATAL_FAILURE(InitState());
11417 ASSERT_NO_FATAL_FAILURE(InitViewport());
11418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11419
11420 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011421 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011422 pipe_ms_state_ci.pNext = NULL;
11423 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11424 pipe_ms_state_ci.sampleShadingEnable = 0;
11425 pipe_ms_state_ci.minSampleShading = 1.0;
11426 pipe_ms_state_ci.pSampleMask = nullptr;
11427
11428 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11429 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11430 VkPipelineLayout pipeline_layout;
11431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011432 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011433 ASSERT_VK_SUCCESS(err);
11434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011435 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11436 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011437 VkPipelineObj pipe(m_device);
11438 pipe.AddShader(&vs);
11439 pipe.AddShader(&fs);
11440 pipe.AddColorAttachment();
11441 pipe.SetMSAA(&pipe_ms_state_ci);
11442 pipe.SetViewport(m_viewports);
11443 pipe.SetScissor(m_scissors);
11444 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11445
Tony Barbour552f6c02016-12-21 14:34:07 -070011446 m_commandBuffer->BeginCommandBuffer();
11447 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011448 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011449
11450 {
11451 // Create and bind a vertex buffer in a reduced scope, which will cause
11452 // it to be deleted upon leaving this scope
11453 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011454 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011455 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11456 draw_verticies.AddVertexInputToPipe(pipe);
11457 }
11458
11459 Draw(1, 0, 0, 0);
11460
Tony Barbour552f6c02016-12-21 14:34:07 -070011461 m_commandBuffer->EndRenderPass();
11462 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011465 QueueCommandBuffer(false);
11466 m_errorMonitor->VerifyFound();
11467
11468 {
11469 // Create and bind a vertex buffer in a reduced scope, and delete it
11470 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011471 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011473 buffer_test.TestDoubleDestroy();
11474 }
11475 m_errorMonitor->VerifyFound();
11476
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011477 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011478 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011479 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011481 m_errorMonitor->SetUnexpectedError(
11482 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11483 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011484 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11485 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011486 m_errorMonitor->VerifyFound();
11487 }
11488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011489 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11490 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011491 // Create and bind a memory buffer with an invalid offset again,
11492 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011494 m_errorMonitor->SetUnexpectedError(
11495 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11496 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011497 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11498 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011499 m_errorMonitor->VerifyFound();
11500 }
11501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011502 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011503 // Create and bind a memory buffer with an invalid offset again, but
11504 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011506 m_errorMonitor->SetUnexpectedError(
11507 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11508 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011509 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11510 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011511 m_errorMonitor->VerifyFound();
11512 }
11513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011514 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011515 // Create and bind a memory buffer with an invalid offset again, but
11516 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011518 m_errorMonitor->SetUnexpectedError(
11519 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11520 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011521 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11522 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011523 m_errorMonitor->VerifyFound();
11524 }
11525
11526 {
11527 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011529 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11530 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011531 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11532 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011533 m_errorMonitor->VerifyFound();
11534 }
11535
11536 {
11537 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011539 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11540 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011541 }
11542 m_errorMonitor->VerifyFound();
11543
11544 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11545}
11546
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011547// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11548TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011549 TEST_DESCRIPTION(
11550 "Hit all possible validation checks associated with the "
11551 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11552 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011553 // 3 in ValidateCmdBufImageLayouts
11554 // * -1 Attempt to submit cmd buf w/ deleted image
11555 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11556 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011557
11558 ASSERT_NO_FATAL_FAILURE(InitState());
11559 // Create src & dst images to use for copy operations
11560 VkImage src_image;
11561 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011562 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011563
11564 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11565 const int32_t tex_width = 32;
11566 const int32_t tex_height = 32;
11567
11568 VkImageCreateInfo image_create_info = {};
11569 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11570 image_create_info.pNext = NULL;
11571 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11572 image_create_info.format = tex_format;
11573 image_create_info.extent.width = tex_width;
11574 image_create_info.extent.height = tex_height;
11575 image_create_info.extent.depth = 1;
11576 image_create_info.mipLevels = 1;
11577 image_create_info.arrayLayers = 4;
11578 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11579 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11580 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011581 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011582 image_create_info.flags = 0;
11583
11584 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11585 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011586 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011587 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11588 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011589 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11590 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11591 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11592 ASSERT_VK_SUCCESS(err);
11593
11594 // Allocate memory
11595 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011596 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011597 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011598 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11599 mem_alloc.pNext = NULL;
11600 mem_alloc.allocationSize = 0;
11601 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011602
11603 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011604 mem_alloc.allocationSize = img_mem_reqs.size;
11605 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011606 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011607 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011608 ASSERT_VK_SUCCESS(err);
11609
11610 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011611 mem_alloc.allocationSize = img_mem_reqs.size;
11612 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011613 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011614 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011615 ASSERT_VK_SUCCESS(err);
11616
11617 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011618 mem_alloc.allocationSize = img_mem_reqs.size;
11619 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011620 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011621 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011622 ASSERT_VK_SUCCESS(err);
11623
11624 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11625 ASSERT_VK_SUCCESS(err);
11626 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11627 ASSERT_VK_SUCCESS(err);
11628 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11629 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011630
Tony Barbour552f6c02016-12-21 14:34:07 -070011631 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011632 VkImageCopy copy_region;
11633 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11634 copy_region.srcSubresource.mipLevel = 0;
11635 copy_region.srcSubresource.baseArrayLayer = 0;
11636 copy_region.srcSubresource.layerCount = 1;
11637 copy_region.srcOffset.x = 0;
11638 copy_region.srcOffset.y = 0;
11639 copy_region.srcOffset.z = 0;
11640 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11641 copy_region.dstSubresource.mipLevel = 0;
11642 copy_region.dstSubresource.baseArrayLayer = 0;
11643 copy_region.dstSubresource.layerCount = 1;
11644 copy_region.dstOffset.x = 0;
11645 copy_region.dstOffset.y = 0;
11646 copy_region.dstOffset.z = 0;
11647 copy_region.extent.width = 1;
11648 copy_region.extent.height = 1;
11649 copy_region.extent.depth = 1;
11650
11651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11652 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011653 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011654 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 -060011655 m_errorMonitor->VerifyFound();
11656 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11658 "Cannot copy from an image whose source layout is "
11659 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11660 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011661 m_errorMonitor->SetUnexpectedError(
11662 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011663 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 -060011664 m_errorMonitor->VerifyFound();
11665 // Final src error is due to bad layout type
11666 m_errorMonitor->SetDesiredFailureMsg(
11667 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11668 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011669 m_errorMonitor->SetUnexpectedError(
11670 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11671 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011672 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 -060011673 m_errorMonitor->VerifyFound();
11674 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11676 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011677 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011678 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 -060011679 m_errorMonitor->VerifyFound();
11680 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11682 "Cannot copy from an image whose dest layout is "
11683 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11684 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011685 m_errorMonitor->SetUnexpectedError(
11686 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011687 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 -060011688 m_errorMonitor->VerifyFound();
11689 m_errorMonitor->SetDesiredFailureMsg(
11690 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11691 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011692 m_errorMonitor->SetUnexpectedError(
11693 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11694 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011695 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 -060011696 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011697
Cort3b021012016-12-07 12:00:57 -080011698 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11699 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11700 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11701 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11702 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11703 transfer_dst_image_barrier[0].srcAccessMask = 0;
11704 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11705 transfer_dst_image_barrier[0].image = dst_image;
11706 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11707 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11708 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11709 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11710 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11711 transfer_dst_image_barrier[0].image = depth_image;
11712 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11713 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11714 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11715
11716 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011717 VkClearColorValue color_clear_value = {};
11718 VkImageSubresourceRange clear_range;
11719 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11720 clear_range.baseMipLevel = 0;
11721 clear_range.baseArrayLayer = 0;
11722 clear_range.layerCount = 1;
11723 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011724
Cort3b021012016-12-07 12:00:57 -080011725 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11726 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011729 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011730 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011731 // Fail due to provided layout not matching actual current layout for color clear.
11732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011733 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011734 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011735
Cort530cf382016-12-08 09:59:47 -080011736 VkClearDepthStencilValue depth_clear_value = {};
11737 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011738
11739 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11740 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011743 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011744 m_errorMonitor->VerifyFound();
11745 // Fail due to provided layout not matching actual current layout for depth clear.
11746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011747 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011748 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011749
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011750 // Now cause error due to bad image layout transition in PipelineBarrier
11751 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011752 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011753 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011754 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011755 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011756 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11757 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011758 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11760 "You cannot transition the layout of aspect 1 from "
11761 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11762 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011763 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11764 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011765 m_errorMonitor->VerifyFound();
11766
11767 // Finally some layout errors at RenderPass create time
11768 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11769 VkAttachmentReference attach = {};
11770 // perf warning for GENERAL layout w/ non-DS input attachment
11771 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11772 VkSubpassDescription subpass = {};
11773 subpass.inputAttachmentCount = 1;
11774 subpass.pInputAttachments = &attach;
11775 VkRenderPassCreateInfo rpci = {};
11776 rpci.subpassCount = 1;
11777 rpci.pSubpasses = &subpass;
11778 rpci.attachmentCount = 1;
11779 VkAttachmentDescription attach_desc = {};
11780 attach_desc.format = VK_FORMAT_UNDEFINED;
11781 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011782 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011783 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11785 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011786 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11787 m_errorMonitor->VerifyFound();
11788 // error w/ non-general layout
11789 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11790
11791 m_errorMonitor->SetDesiredFailureMsg(
11792 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11793 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11794 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11795 m_errorMonitor->VerifyFound();
11796 subpass.inputAttachmentCount = 0;
11797 subpass.colorAttachmentCount = 1;
11798 subpass.pColorAttachments = &attach;
11799 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11800 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11802 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011803 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11804 m_errorMonitor->VerifyFound();
11805 // error w/ non-color opt or GENERAL layout for color attachment
11806 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11807 m_errorMonitor->SetDesiredFailureMsg(
11808 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11809 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11810 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11811 m_errorMonitor->VerifyFound();
11812 subpass.colorAttachmentCount = 0;
11813 subpass.pDepthStencilAttachment = &attach;
11814 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11815 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11817 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011818 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11819 m_errorMonitor->VerifyFound();
11820 // error w/ non-ds opt or GENERAL layout for color attachment
11821 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11823 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11824 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011825 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11826 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011827 // For this error we need a valid renderpass so create default one
11828 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11829 attach.attachment = 0;
11830 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11831 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11832 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11833 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11834 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11835 // Can't do a CLEAR load on READ_ONLY initialLayout
11836 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11837 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11838 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11840 " with invalid first layout "
11841 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11842 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011843 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11844 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011845
Cort3b021012016-12-07 12:00:57 -080011846 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11847 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11848 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011849 vkDestroyImage(m_device->device(), src_image, NULL);
11850 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011851 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011852}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011853
Tobin Ehlise0936662016-10-11 08:10:51 -060011854TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11855 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11856 VkResult err;
11857
11858 ASSERT_NO_FATAL_FAILURE(InitState());
11859
11860 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11861 VkImageTiling tiling;
11862 VkFormatProperties format_properties;
11863 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11864 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11865 tiling = VK_IMAGE_TILING_LINEAR;
11866 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11867 tiling = VK_IMAGE_TILING_OPTIMAL;
11868 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011869 printf(
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070011870 " Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011871 return;
11872 }
11873
11874 VkDescriptorPoolSize ds_type = {};
11875 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11876 ds_type.descriptorCount = 1;
11877
11878 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11879 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11880 ds_pool_ci.maxSets = 1;
11881 ds_pool_ci.poolSizeCount = 1;
11882 ds_pool_ci.pPoolSizes = &ds_type;
11883 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11884
11885 VkDescriptorPool ds_pool;
11886 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11887 ASSERT_VK_SUCCESS(err);
11888
11889 VkDescriptorSetLayoutBinding dsl_binding = {};
11890 dsl_binding.binding = 0;
11891 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11892 dsl_binding.descriptorCount = 1;
11893 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11894 dsl_binding.pImmutableSamplers = NULL;
11895
11896 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11897 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11898 ds_layout_ci.pNext = NULL;
11899 ds_layout_ci.bindingCount = 1;
11900 ds_layout_ci.pBindings = &dsl_binding;
11901
11902 VkDescriptorSetLayout ds_layout;
11903 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11904 ASSERT_VK_SUCCESS(err);
11905
11906 VkDescriptorSetAllocateInfo alloc_info = {};
11907 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11908 alloc_info.descriptorSetCount = 1;
11909 alloc_info.descriptorPool = ds_pool;
11910 alloc_info.pSetLayouts = &ds_layout;
11911 VkDescriptorSet descriptor_set;
11912 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11913 ASSERT_VK_SUCCESS(err);
11914
11915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11917 pipeline_layout_ci.pNext = NULL;
11918 pipeline_layout_ci.setLayoutCount = 1;
11919 pipeline_layout_ci.pSetLayouts = &ds_layout;
11920 VkPipelineLayout pipeline_layout;
11921 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11922 ASSERT_VK_SUCCESS(err);
11923
11924 VkImageObj image(m_device);
11925 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11926 ASSERT_TRUE(image.initialized());
11927 VkImageView view = image.targetView(tex_format);
11928
11929 VkDescriptorImageInfo image_info = {};
11930 image_info.imageView = view;
11931 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11932
11933 VkWriteDescriptorSet descriptor_write = {};
11934 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11935 descriptor_write.dstSet = descriptor_set;
11936 descriptor_write.dstBinding = 0;
11937 descriptor_write.descriptorCount = 1;
11938 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11939 descriptor_write.pImageInfo = &image_info;
11940
11941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11942 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11943 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11944 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11945 m_errorMonitor->VerifyFound();
11946
11947 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11948 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11949 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11950 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11951}
11952
Mark Mueller93b938f2016-08-18 10:27:40 -060011953TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011954 TEST_DESCRIPTION(
11955 "Use vkCmdExecuteCommands with invalid state "
11956 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011957
11958 ASSERT_NO_FATAL_FAILURE(InitState());
11959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11960
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011961 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011962 const char *simultaneous_use_message2 =
11963 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11964 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011965
11966 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011967 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011968 command_buffer_allocate_info.commandPool = m_commandPool;
11969 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11970 command_buffer_allocate_info.commandBufferCount = 1;
11971
11972 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011973 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011974 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11975 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011976 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011977 command_buffer_inheritance_info.renderPass = m_renderPass;
11978 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011979
Mark Mueller93b938f2016-08-18 10:27:40 -060011980 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011981 command_buffer_begin_info.flags =
11982 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011983 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11984
11985 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11986 vkEndCommandBuffer(secondary_command_buffer);
11987
Mark Mueller93b938f2016-08-18 10:27:40 -060011988 VkSubmitInfo submit_info = {};
11989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11990 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011991 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011992
Mark Mueller4042b652016-09-05 22:52:21 -060011993 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011994 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11996 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011997 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011998 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011999 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12000 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012001
Dave Houltonfbf52152017-01-06 12:55:29 -070012002 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012003 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012004 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012005
Mark Mueller4042b652016-09-05 22:52:21 -060012006 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012007 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12008 m_errorMonitor->SetUnexpectedError(
12009 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12010 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012011 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012012 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12015 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012016 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012017 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12018 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012019
12020 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012021
12022 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012023}
12024
Tony Barbour626994c2017-02-08 15:29:37 -070012025TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12026 TEST_DESCRIPTION(
12027 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12028 "errors");
12029 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12030 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12031 ASSERT_NO_FATAL_FAILURE(InitState());
12032
12033 VkCommandBuffer cmd_bufs[2];
12034 VkCommandBufferAllocateInfo alloc_info;
12035 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12036 alloc_info.pNext = NULL;
12037 alloc_info.commandBufferCount = 2;
12038 alloc_info.commandPool = m_commandPool;
12039 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12040 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12041
12042 VkCommandBufferBeginInfo cb_binfo;
12043 cb_binfo.pNext = NULL;
12044 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12045 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12046 cb_binfo.flags = 0;
12047 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12048 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12049 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12050 vkEndCommandBuffer(cmd_bufs[0]);
12051 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12052
12053 VkSubmitInfo submit_info = {};
12054 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12055 submit_info.commandBufferCount = 2;
12056 submit_info.pCommandBuffers = duplicates;
12057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12058 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12059 m_errorMonitor->VerifyFound();
12060 vkQueueWaitIdle(m_device->m_queue);
12061
12062 // Set one time use and now look for one time submit
12063 duplicates[0] = duplicates[1] = cmd_bufs[1];
12064 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12065 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12066 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12067 vkEndCommandBuffer(cmd_bufs[1]);
12068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12069 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12070 m_errorMonitor->VerifyFound();
12071 vkQueueWaitIdle(m_device->m_queue);
12072}
12073
Tobin Ehlisb093da82017-01-19 12:05:27 -070012074TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012075 TEST_DESCRIPTION(
12076 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12077 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012078
12079 ASSERT_NO_FATAL_FAILURE(InitState());
12080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12081
12082 std::vector<const char *> device_extension_names;
12083 auto features = m_device->phy().features();
12084 // Make sure gs & ts are disabled
12085 features.geometryShader = false;
12086 features.tessellationShader = false;
12087 // The sacrificial device object
12088 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12089
12090 VkCommandPoolCreateInfo pool_create_info{};
12091 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12092 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12093
12094 VkCommandPool command_pool;
12095 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12096
12097 VkCommandBufferAllocateInfo cmd = {};
12098 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12099 cmd.pNext = NULL;
12100 cmd.commandPool = command_pool;
12101 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12102 cmd.commandBufferCount = 1;
12103
12104 VkCommandBuffer cmd_buffer;
12105 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12106 ASSERT_VK_SUCCESS(err);
12107
12108 VkEvent event;
12109 VkEventCreateInfo evci = {};
12110 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12111 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12112 ASSERT_VK_SUCCESS(result);
12113
12114 VkCommandBufferBeginInfo cbbi = {};
12115 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12116 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12118 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12119 m_errorMonitor->VerifyFound();
12120
12121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12122 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12123 m_errorMonitor->VerifyFound();
12124
12125 vkDestroyEvent(test_device.handle(), event, NULL);
12126 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12127}
12128
Mark Mueller917f6bc2016-08-30 10:57:19 -060012129TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012130 TEST_DESCRIPTION(
12131 "Use vkCmdExecuteCommands with invalid state "
12132 "in primary and secondary command buffers. "
12133 "Delete objects that are inuse. Call VkQueueSubmit "
12134 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012135
12136 ASSERT_NO_FATAL_FAILURE(InitState());
12137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12138
Tony Barbour552f6c02016-12-21 14:34:07 -070012139 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012140
12141 VkEvent event;
12142 VkEventCreateInfo event_create_info = {};
12143 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12144 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012145 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012146
Tony Barbour552f6c02016-12-21 14:34:07 -070012147 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012148 vkDestroyEvent(m_device->device(), event, nullptr);
12149
12150 VkSubmitInfo submit_info = {};
12151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12152 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012153 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070012154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012156 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12157 m_errorMonitor->VerifyFound();
12158
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012159 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012160 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12161
12162 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12163
Mark Mueller917f6bc2016-08-30 10:57:19 -060012164 VkSemaphoreCreateInfo semaphore_create_info = {};
12165 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12166 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012167 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012168 VkFenceCreateInfo fence_create_info = {};
12169 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12170 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012171 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012172
12173 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012174 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012175 descriptor_pool_type_count.descriptorCount = 1;
12176
12177 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12178 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12179 descriptor_pool_create_info.maxSets = 1;
12180 descriptor_pool_create_info.poolSizeCount = 1;
12181 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012182 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012183
12184 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012185 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012186
12187 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012188 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012189 descriptorset_layout_binding.descriptorCount = 1;
12190 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12191
12192 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012193 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012194 descriptorset_layout_create_info.bindingCount = 1;
12195 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12196
12197 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012198 ASSERT_VK_SUCCESS(
12199 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012200
12201 VkDescriptorSet descriptorset;
12202 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012203 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012204 descriptorset_allocate_info.descriptorSetCount = 1;
12205 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12206 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012207 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012208
Mark Mueller4042b652016-09-05 22:52:21 -060012209 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12210
12211 VkDescriptorBufferInfo buffer_info = {};
12212 buffer_info.buffer = buffer_test.GetBuffer();
12213 buffer_info.offset = 0;
12214 buffer_info.range = 1024;
12215
12216 VkWriteDescriptorSet write_descriptor_set = {};
12217 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12218 write_descriptor_set.dstSet = descriptorset;
12219 write_descriptor_set.descriptorCount = 1;
12220 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12221 write_descriptor_set.pBufferInfo = &buffer_info;
12222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012225 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12226 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012227
12228 VkPipelineObj pipe(m_device);
12229 pipe.AddColorAttachment();
12230 pipe.AddShader(&vs);
12231 pipe.AddShader(&fs);
12232
12233 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012234 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012235 pipeline_layout_create_info.setLayoutCount = 1;
12236 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12237
12238 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012239 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012240
12241 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12242
Tony Barbour552f6c02016-12-21 14:34:07 -070012243 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012244 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012246 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12247 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12248 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012249
Tony Barbour552f6c02016-12-21 14:34:07 -070012250 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012251
Mark Mueller917f6bc2016-08-30 10:57:19 -060012252 submit_info.signalSemaphoreCount = 1;
12253 submit_info.pSignalSemaphores = &semaphore;
12254 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012255 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012256
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012258 vkDestroyEvent(m_device->device(), event, nullptr);
12259 m_errorMonitor->VerifyFound();
12260
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012262 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12263 m_errorMonitor->VerifyFound();
12264
Jeremy Hayes08369882017-02-02 10:31:06 -070012265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012266 vkDestroyFence(m_device->device(), fence, nullptr);
12267 m_errorMonitor->VerifyFound();
12268
Tobin Ehlis122207b2016-09-01 08:50:06 -070012269 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012270 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12271 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012272 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012273 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12274 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012275 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012276 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12277 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012278 vkDestroyEvent(m_device->device(), event, nullptr);
12279 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012280 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012281 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12282}
12283
Tobin Ehlis2adda372016-09-01 08:51:06 -070012284TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12285 TEST_DESCRIPTION("Delete in-use query pool.");
12286
12287 ASSERT_NO_FATAL_FAILURE(InitState());
12288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12289
12290 VkQueryPool query_pool;
12291 VkQueryPoolCreateInfo query_pool_ci{};
12292 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12293 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12294 query_pool_ci.queryCount = 1;
12295 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012296 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012297 // Reset query pool to create binding with cmd buffer
12298 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12299
Tony Barbour552f6c02016-12-21 14:34:07 -070012300 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012301
12302 VkSubmitInfo submit_info = {};
12303 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12304 submit_info.commandBufferCount = 1;
12305 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12306 // Submit cmd buffer and then destroy query pool while in-flight
12307 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12308
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012310 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12311 m_errorMonitor->VerifyFound();
12312
12313 vkQueueWaitIdle(m_device->m_queue);
12314 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012315 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12316 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012317 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12318}
12319
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012320TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12321 TEST_DESCRIPTION("Delete in-use pipeline.");
12322
12323 ASSERT_NO_FATAL_FAILURE(InitState());
12324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12325
12326 // Empty pipeline layout used for binding PSO
12327 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12328 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12329 pipeline_layout_ci.setLayoutCount = 0;
12330 pipeline_layout_ci.pSetLayouts = NULL;
12331
12332 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012333 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012334 ASSERT_VK_SUCCESS(err);
12335
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012337 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012338 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12339 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012340 // Store pipeline handle so we can actually delete it before test finishes
12341 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012342 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012343 VkPipelineObj pipe(m_device);
12344 pipe.AddShader(&vs);
12345 pipe.AddShader(&fs);
12346 pipe.AddColorAttachment();
12347 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12348 delete_this_pipeline = pipe.handle();
12349
Tony Barbour552f6c02016-12-21 14:34:07 -070012350 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012351 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012352 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012353
Tony Barbour552f6c02016-12-21 14:34:07 -070012354 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012355
12356 VkSubmitInfo submit_info = {};
12357 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12358 submit_info.commandBufferCount = 1;
12359 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12360 // Submit cmd buffer and then pipeline destroyed while in-flight
12361 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012362 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012363 m_errorMonitor->VerifyFound();
12364 // Make sure queue finished and then actually delete pipeline
12365 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012366 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12367 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012368 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12369 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12370}
12371
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012372TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12373 TEST_DESCRIPTION("Delete in-use imageView.");
12374
12375 ASSERT_NO_FATAL_FAILURE(InitState());
12376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12377
12378 VkDescriptorPoolSize ds_type_count;
12379 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12380 ds_type_count.descriptorCount = 1;
12381
12382 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12383 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12384 ds_pool_ci.maxSets = 1;
12385 ds_pool_ci.poolSizeCount = 1;
12386 ds_pool_ci.pPoolSizes = &ds_type_count;
12387
12388 VkDescriptorPool ds_pool;
12389 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12390 ASSERT_VK_SUCCESS(err);
12391
12392 VkSamplerCreateInfo sampler_ci = {};
12393 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12394 sampler_ci.pNext = NULL;
12395 sampler_ci.magFilter = VK_FILTER_NEAREST;
12396 sampler_ci.minFilter = VK_FILTER_NEAREST;
12397 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12398 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12399 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12400 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12401 sampler_ci.mipLodBias = 1.0;
12402 sampler_ci.anisotropyEnable = VK_FALSE;
12403 sampler_ci.maxAnisotropy = 1;
12404 sampler_ci.compareEnable = VK_FALSE;
12405 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12406 sampler_ci.minLod = 1.0;
12407 sampler_ci.maxLod = 1.0;
12408 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12409 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12410 VkSampler sampler;
12411
12412 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12413 ASSERT_VK_SUCCESS(err);
12414
12415 VkDescriptorSetLayoutBinding layout_binding;
12416 layout_binding.binding = 0;
12417 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12418 layout_binding.descriptorCount = 1;
12419 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12420 layout_binding.pImmutableSamplers = NULL;
12421
12422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12424 ds_layout_ci.bindingCount = 1;
12425 ds_layout_ci.pBindings = &layout_binding;
12426 VkDescriptorSetLayout ds_layout;
12427 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12428 ASSERT_VK_SUCCESS(err);
12429
12430 VkDescriptorSetAllocateInfo alloc_info = {};
12431 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12432 alloc_info.descriptorSetCount = 1;
12433 alloc_info.descriptorPool = ds_pool;
12434 alloc_info.pSetLayouts = &ds_layout;
12435 VkDescriptorSet descriptor_set;
12436 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12437 ASSERT_VK_SUCCESS(err);
12438
12439 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12440 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12441 pipeline_layout_ci.pNext = NULL;
12442 pipeline_layout_ci.setLayoutCount = 1;
12443 pipeline_layout_ci.pSetLayouts = &ds_layout;
12444
12445 VkPipelineLayout pipeline_layout;
12446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12447 ASSERT_VK_SUCCESS(err);
12448
12449 VkImageObj image(m_device);
12450 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12451 ASSERT_TRUE(image.initialized());
12452
12453 VkImageView view;
12454 VkImageViewCreateInfo ivci = {};
12455 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12456 ivci.image = image.handle();
12457 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12458 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12459 ivci.subresourceRange.layerCount = 1;
12460 ivci.subresourceRange.baseMipLevel = 0;
12461 ivci.subresourceRange.levelCount = 1;
12462 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12463
12464 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12465 ASSERT_VK_SUCCESS(err);
12466
12467 VkDescriptorImageInfo image_info{};
12468 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12469 image_info.imageView = view;
12470 image_info.sampler = sampler;
12471
12472 VkWriteDescriptorSet descriptor_write = {};
12473 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12474 descriptor_write.dstSet = descriptor_set;
12475 descriptor_write.dstBinding = 0;
12476 descriptor_write.descriptorCount = 1;
12477 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12478 descriptor_write.pImageInfo = &image_info;
12479
12480 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12481
12482 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012483 char const *vsSource =
12484 "#version 450\n"
12485 "\n"
12486 "out gl_PerVertex { \n"
12487 " vec4 gl_Position;\n"
12488 "};\n"
12489 "void main(){\n"
12490 " gl_Position = vec4(1);\n"
12491 "}\n";
12492 char const *fsSource =
12493 "#version 450\n"
12494 "\n"
12495 "layout(set=0, binding=0) uniform sampler2D s;\n"
12496 "layout(location=0) out vec4 x;\n"
12497 "void main(){\n"
12498 " x = texture(s, vec2(1));\n"
12499 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012500 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12501 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12502 VkPipelineObj pipe(m_device);
12503 pipe.AddShader(&vs);
12504 pipe.AddShader(&fs);
12505 pipe.AddColorAttachment();
12506 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12507
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012509
Tony Barbour552f6c02016-12-21 14:34:07 -070012510 m_commandBuffer->BeginCommandBuffer();
12511 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012512 // Bind pipeline to cmd buffer
12513 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12514 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12515 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012516
12517 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12518 VkRect2D scissor = {{0, 0}, {16, 16}};
12519 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12520 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12521
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012522 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012523 m_commandBuffer->EndRenderPass();
12524 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012525 // Submit cmd buffer then destroy sampler
12526 VkSubmitInfo submit_info = {};
12527 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12528 submit_info.commandBufferCount = 1;
12529 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12530 // Submit cmd buffer and then destroy imageView while in-flight
12531 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12532
12533 vkDestroyImageView(m_device->device(), view, nullptr);
12534 m_errorMonitor->VerifyFound();
12535 vkQueueWaitIdle(m_device->m_queue);
12536 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012537 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12538 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012539 vkDestroyImageView(m_device->device(), view, NULL);
12540 vkDestroySampler(m_device->device(), sampler, nullptr);
12541 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12543 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12544}
12545
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012546TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12547 TEST_DESCRIPTION("Delete in-use bufferView.");
12548
12549 ASSERT_NO_FATAL_FAILURE(InitState());
12550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12551
12552 VkDescriptorPoolSize ds_type_count;
12553 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12554 ds_type_count.descriptorCount = 1;
12555
12556 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12557 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12558 ds_pool_ci.maxSets = 1;
12559 ds_pool_ci.poolSizeCount = 1;
12560 ds_pool_ci.pPoolSizes = &ds_type_count;
12561
12562 VkDescriptorPool ds_pool;
12563 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12564 ASSERT_VK_SUCCESS(err);
12565
12566 VkDescriptorSetLayoutBinding layout_binding;
12567 layout_binding.binding = 0;
12568 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12569 layout_binding.descriptorCount = 1;
12570 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12571 layout_binding.pImmutableSamplers = NULL;
12572
12573 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12574 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12575 ds_layout_ci.bindingCount = 1;
12576 ds_layout_ci.pBindings = &layout_binding;
12577 VkDescriptorSetLayout ds_layout;
12578 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12579 ASSERT_VK_SUCCESS(err);
12580
12581 VkDescriptorSetAllocateInfo alloc_info = {};
12582 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12583 alloc_info.descriptorSetCount = 1;
12584 alloc_info.descriptorPool = ds_pool;
12585 alloc_info.pSetLayouts = &ds_layout;
12586 VkDescriptorSet descriptor_set;
12587 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12588 ASSERT_VK_SUCCESS(err);
12589
12590 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12591 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12592 pipeline_layout_ci.pNext = NULL;
12593 pipeline_layout_ci.setLayoutCount = 1;
12594 pipeline_layout_ci.pSetLayouts = &ds_layout;
12595
12596 VkPipelineLayout pipeline_layout;
12597 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12598 ASSERT_VK_SUCCESS(err);
12599
12600 VkBuffer buffer;
12601 uint32_t queue_family_index = 0;
12602 VkBufferCreateInfo buffer_create_info = {};
12603 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12604 buffer_create_info.size = 1024;
12605 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12606 buffer_create_info.queueFamilyIndexCount = 1;
12607 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12608
12609 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12610 ASSERT_VK_SUCCESS(err);
12611
12612 VkMemoryRequirements memory_reqs;
12613 VkDeviceMemory buffer_memory;
12614
12615 VkMemoryAllocateInfo memory_info = {};
12616 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12617 memory_info.allocationSize = 0;
12618 memory_info.memoryTypeIndex = 0;
12619
12620 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12621 memory_info.allocationSize = memory_reqs.size;
12622 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12623 ASSERT_TRUE(pass);
12624
12625 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12626 ASSERT_VK_SUCCESS(err);
12627 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12628 ASSERT_VK_SUCCESS(err);
12629
12630 VkBufferView view;
12631 VkBufferViewCreateInfo bvci = {};
12632 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12633 bvci.buffer = buffer;
12634 bvci.format = VK_FORMAT_R8_UNORM;
12635 bvci.range = VK_WHOLE_SIZE;
12636
12637 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12638 ASSERT_VK_SUCCESS(err);
12639
12640 VkWriteDescriptorSet descriptor_write = {};
12641 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12642 descriptor_write.dstSet = descriptor_set;
12643 descriptor_write.dstBinding = 0;
12644 descriptor_write.descriptorCount = 1;
12645 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12646 descriptor_write.pTexelBufferView = &view;
12647
12648 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12649
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012650 char const *vsSource =
12651 "#version 450\n"
12652 "\n"
12653 "out gl_PerVertex { \n"
12654 " vec4 gl_Position;\n"
12655 "};\n"
12656 "void main(){\n"
12657 " gl_Position = vec4(1);\n"
12658 "}\n";
12659 char const *fsSource =
12660 "#version 450\n"
12661 "\n"
12662 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12663 "layout(location=0) out vec4 x;\n"
12664 "void main(){\n"
12665 " x = imageLoad(s, 0);\n"
12666 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012667 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12668 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12669 VkPipelineObj pipe(m_device);
12670 pipe.AddShader(&vs);
12671 pipe.AddShader(&fs);
12672 pipe.AddColorAttachment();
12673 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12674
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012676
Tony Barbour552f6c02016-12-21 14:34:07 -070012677 m_commandBuffer->BeginCommandBuffer();
12678 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012679 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12680 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12681 VkRect2D scissor = {{0, 0}, {16, 16}};
12682 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12683 // Bind pipeline to cmd buffer
12684 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12685 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12686 &descriptor_set, 0, nullptr);
12687 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012688 m_commandBuffer->EndRenderPass();
12689 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012690
12691 VkSubmitInfo submit_info = {};
12692 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12693 submit_info.commandBufferCount = 1;
12694 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12695 // Submit cmd buffer and then destroy bufferView while in-flight
12696 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12697
12698 vkDestroyBufferView(m_device->device(), view, nullptr);
12699 m_errorMonitor->VerifyFound();
12700 vkQueueWaitIdle(m_device->m_queue);
12701 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012702 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12703 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012704 vkDestroyBufferView(m_device->device(), view, NULL);
12705 vkDestroyBuffer(m_device->device(), buffer, NULL);
12706 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12707 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12708 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12709 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12710}
12711
Tobin Ehlis209532e2016-09-07 13:52:18 -060012712TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12713 TEST_DESCRIPTION("Delete in-use sampler.");
12714
12715 ASSERT_NO_FATAL_FAILURE(InitState());
12716 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12717
12718 VkDescriptorPoolSize ds_type_count;
12719 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12720 ds_type_count.descriptorCount = 1;
12721
12722 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12723 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12724 ds_pool_ci.maxSets = 1;
12725 ds_pool_ci.poolSizeCount = 1;
12726 ds_pool_ci.pPoolSizes = &ds_type_count;
12727
12728 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012729 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012730 ASSERT_VK_SUCCESS(err);
12731
12732 VkSamplerCreateInfo sampler_ci = {};
12733 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12734 sampler_ci.pNext = NULL;
12735 sampler_ci.magFilter = VK_FILTER_NEAREST;
12736 sampler_ci.minFilter = VK_FILTER_NEAREST;
12737 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12738 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12739 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12740 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12741 sampler_ci.mipLodBias = 1.0;
12742 sampler_ci.anisotropyEnable = VK_FALSE;
12743 sampler_ci.maxAnisotropy = 1;
12744 sampler_ci.compareEnable = VK_FALSE;
12745 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12746 sampler_ci.minLod = 1.0;
12747 sampler_ci.maxLod = 1.0;
12748 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12749 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12750 VkSampler sampler;
12751
12752 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12753 ASSERT_VK_SUCCESS(err);
12754
12755 VkDescriptorSetLayoutBinding layout_binding;
12756 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012757 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012758 layout_binding.descriptorCount = 1;
12759 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12760 layout_binding.pImmutableSamplers = NULL;
12761
12762 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12763 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12764 ds_layout_ci.bindingCount = 1;
12765 ds_layout_ci.pBindings = &layout_binding;
12766 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012767 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012768 ASSERT_VK_SUCCESS(err);
12769
12770 VkDescriptorSetAllocateInfo alloc_info = {};
12771 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12772 alloc_info.descriptorSetCount = 1;
12773 alloc_info.descriptorPool = ds_pool;
12774 alloc_info.pSetLayouts = &ds_layout;
12775 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012776 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012777 ASSERT_VK_SUCCESS(err);
12778
12779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12781 pipeline_layout_ci.pNext = NULL;
12782 pipeline_layout_ci.setLayoutCount = 1;
12783 pipeline_layout_ci.pSetLayouts = &ds_layout;
12784
12785 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012786 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012787 ASSERT_VK_SUCCESS(err);
12788
12789 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012790 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 -060012791 ASSERT_TRUE(image.initialized());
12792
12793 VkImageView view;
12794 VkImageViewCreateInfo ivci = {};
12795 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12796 ivci.image = image.handle();
12797 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12798 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12799 ivci.subresourceRange.layerCount = 1;
12800 ivci.subresourceRange.baseMipLevel = 0;
12801 ivci.subresourceRange.levelCount = 1;
12802 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12803
12804 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12805 ASSERT_VK_SUCCESS(err);
12806
12807 VkDescriptorImageInfo image_info{};
12808 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12809 image_info.imageView = view;
12810 image_info.sampler = sampler;
12811
12812 VkWriteDescriptorSet descriptor_write = {};
12813 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12814 descriptor_write.dstSet = descriptor_set;
12815 descriptor_write.dstBinding = 0;
12816 descriptor_write.descriptorCount = 1;
12817 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12818 descriptor_write.pImageInfo = &image_info;
12819
12820 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12821
12822 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012823 char const *vsSource =
12824 "#version 450\n"
12825 "\n"
12826 "out gl_PerVertex { \n"
12827 " vec4 gl_Position;\n"
12828 "};\n"
12829 "void main(){\n"
12830 " gl_Position = vec4(1);\n"
12831 "}\n";
12832 char const *fsSource =
12833 "#version 450\n"
12834 "\n"
12835 "layout(set=0, binding=0) uniform sampler2D s;\n"
12836 "layout(location=0) out vec4 x;\n"
12837 "void main(){\n"
12838 " x = texture(s, vec2(1));\n"
12839 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012840 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12841 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12842 VkPipelineObj pipe(m_device);
12843 pipe.AddShader(&vs);
12844 pipe.AddShader(&fs);
12845 pipe.AddColorAttachment();
12846 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12847
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012849
Tony Barbour552f6c02016-12-21 14:34:07 -070012850 m_commandBuffer->BeginCommandBuffer();
12851 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012852 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012853 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12854 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12855 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012856
12857 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12858 VkRect2D scissor = {{0, 0}, {16, 16}};
12859 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12860 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12861
Tobin Ehlis209532e2016-09-07 13:52:18 -060012862 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012863 m_commandBuffer->EndRenderPass();
12864 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012865 // Submit cmd buffer then destroy sampler
12866 VkSubmitInfo submit_info = {};
12867 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12868 submit_info.commandBufferCount = 1;
12869 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12870 // Submit cmd buffer and then destroy sampler while in-flight
12871 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12872
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012873 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012874 m_errorMonitor->VerifyFound();
12875 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012876
Tobin Ehlis209532e2016-09-07 13:52:18 -060012877 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012878 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12879 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012880 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012881 vkDestroyImageView(m_device->device(), view, NULL);
12882 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12883 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12884 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12885}
12886
Mark Mueller1cd9f412016-08-25 13:23:52 -060012887TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012888 TEST_DESCRIPTION(
12889 "Call VkQueueSubmit with a semaphore that is already "
12890 "signaled but not waited on by the queue. Wait on a "
12891 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012892
12893 ASSERT_NO_FATAL_FAILURE(InitState());
12894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12895
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012896 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 -070012897 const char *invalid_fence_wait_message =
12898 " which has not been submitted on a Queue or during "
12899 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012900
Tony Barbour552f6c02016-12-21 14:34:07 -070012901 m_commandBuffer->BeginCommandBuffer();
12902 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012903
12904 VkSemaphoreCreateInfo semaphore_create_info = {};
12905 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12906 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012907 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012908 VkSubmitInfo submit_info = {};
12909 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12910 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012911 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012912 submit_info.signalSemaphoreCount = 1;
12913 submit_info.pSignalSemaphores = &semaphore;
12914 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012915 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012916 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012917 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012918 m_commandBuffer->BeginCommandBuffer();
12919 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012921 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12922 m_errorMonitor->VerifyFound();
12923
Mark Mueller1cd9f412016-08-25 13:23:52 -060012924 VkFenceCreateInfo fence_create_info = {};
12925 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12926 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012927 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012930 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12931 m_errorMonitor->VerifyFound();
12932
Mark Mueller4042b652016-09-05 22:52:21 -060012933 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012934 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012935 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12936}
12937
Tobin Ehlis4af23302016-07-19 10:50:30 -060012938TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012939 TEST_DESCRIPTION(
12940 "Bind a secondary command buffer with with a framebuffer "
12941 "that does not match the framebuffer for the active "
12942 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012943 ASSERT_NO_FATAL_FAILURE(InitState());
12944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12945
12946 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012947 VkAttachmentDescription attachment = {0,
12948 VK_FORMAT_B8G8R8A8_UNORM,
12949 VK_SAMPLE_COUNT_1_BIT,
12950 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12951 VK_ATTACHMENT_STORE_OP_STORE,
12952 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12953 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12954 VK_IMAGE_LAYOUT_UNDEFINED,
12955 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012959 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012961 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012962
12963 VkRenderPass rp;
12964 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12965 ASSERT_VK_SUCCESS(err);
12966
12967 // A compatible framebuffer.
12968 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012969 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 -060012970 ASSERT_TRUE(image.initialized());
12971
12972 VkImageViewCreateInfo ivci = {
12973 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12974 nullptr,
12975 0,
12976 image.handle(),
12977 VK_IMAGE_VIEW_TYPE_2D,
12978 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012979 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12980 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012981 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12982 };
12983 VkImageView view;
12984 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12985 ASSERT_VK_SUCCESS(err);
12986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012987 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012988 VkFramebuffer fb;
12989 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12990 ASSERT_VK_SUCCESS(err);
12991
12992 VkCommandBufferAllocateInfo cbai = {};
12993 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12994 cbai.commandPool = m_commandPool;
12995 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12996 cbai.commandBufferCount = 1;
12997
12998 VkCommandBuffer sec_cb;
12999 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13000 ASSERT_VK_SUCCESS(err);
13001 VkCommandBufferBeginInfo cbbi = {};
13002 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013003 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013004 cbii.renderPass = renderPass();
13005 cbii.framebuffer = fb;
13006 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13007 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 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 -060013009 cbbi.pInheritanceInfo = &cbii;
13010 vkBeginCommandBuffer(sec_cb, &cbbi);
13011 vkEndCommandBuffer(sec_cb);
13012
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013013 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013014 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13015 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013018 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013019 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13020 m_errorMonitor->VerifyFound();
13021 // Cleanup
13022 vkDestroyImageView(m_device->device(), view, NULL);
13023 vkDestroyRenderPass(m_device->device(), rp, NULL);
13024 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13025}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013026
13027TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013028 TEST_DESCRIPTION(
13029 "If logicOp is available on the device, set it to an "
13030 "invalid value. If logicOp is not available, attempt to "
13031 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013032 ASSERT_NO_FATAL_FAILURE(InitState());
13033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13034
13035 auto features = m_device->phy().features();
13036 // Set the expected error depending on whether or not logicOp available
13037 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13039 "If logic operations feature not "
13040 "enabled, logicOpEnable must be "
13041 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013042 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013044 }
13045 // Create a pipeline using logicOp
13046 VkResult err;
13047
13048 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13049 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13050
13051 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013052 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013053 ASSERT_VK_SUCCESS(err);
13054
13055 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13056 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13057 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013058 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013059 vp_state_ci.pViewports = &vp;
13060 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013061 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013062 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013063
13064 VkPipelineShaderStageCreateInfo shaderStages[2];
13065 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013067 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13068 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013069 shaderStages[0] = vs.GetStageCreateInfo();
13070 shaderStages[1] = fs.GetStageCreateInfo();
13071
13072 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13073 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13074
13075 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13076 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13077 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13078
13079 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13080 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013081 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013082
13083 VkPipelineColorBlendAttachmentState att = {};
13084 att.blendEnable = VK_FALSE;
13085 att.colorWriteMask = 0xf;
13086
13087 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13088 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13089 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13090 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013091 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013092 cb_ci.attachmentCount = 1;
13093 cb_ci.pAttachments = &att;
13094
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013095 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13096 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13097 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13098
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013099 VkGraphicsPipelineCreateInfo gp_ci = {};
13100 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13101 gp_ci.stageCount = 2;
13102 gp_ci.pStages = shaderStages;
13103 gp_ci.pVertexInputState = &vi_ci;
13104 gp_ci.pInputAssemblyState = &ia_ci;
13105 gp_ci.pViewportState = &vp_state_ci;
13106 gp_ci.pRasterizationState = &rs_ci;
13107 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013108 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013109 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13110 gp_ci.layout = pipeline_layout;
13111 gp_ci.renderPass = renderPass();
13112
13113 VkPipelineCacheCreateInfo pc_ci = {};
13114 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13115
13116 VkPipeline pipeline;
13117 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013118 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013119 ASSERT_VK_SUCCESS(err);
13120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013121 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013122 m_errorMonitor->VerifyFound();
13123 if (VK_SUCCESS == err) {
13124 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13125 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013126 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13127 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13128}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013129
Mike Stroyanaccf7692015-05-12 16:00:45 -060013130#if GTEST_IS_THREADSAFE
13131struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013132 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013133 VkEvent event;
13134 bool bailout;
13135};
13136
Karl Schultz6addd812016-02-02 17:17:23 -070013137extern "C" void *AddToCommandBuffer(void *arg) {
13138 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013139
Mike Stroyana6d14942016-07-13 15:10:05 -060013140 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013141 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013142 if (data->bailout) {
13143 break;
13144 }
13145 }
13146 return NULL;
13147}
13148
Karl Schultz6addd812016-02-02 17:17:23 -070013149TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013150 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013153
Mike Stroyanaccf7692015-05-12 16:00:45 -060013154 ASSERT_NO_FATAL_FAILURE(InitState());
13155 ASSERT_NO_FATAL_FAILURE(InitViewport());
13156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13157
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013158 // Calls AllocateCommandBuffers
13159 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013160
13161 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013162 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013163
13164 VkEventCreateInfo event_info;
13165 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013166 VkResult err;
13167
13168 memset(&event_info, 0, sizeof(event_info));
13169 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13170
Chia-I Wuf7458c52015-10-26 21:10:41 +080013171 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013172 ASSERT_VK_SUCCESS(err);
13173
Mike Stroyanaccf7692015-05-12 16:00:45 -060013174 err = vkResetEvent(device(), event);
13175 ASSERT_VK_SUCCESS(err);
13176
13177 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013178 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013179 data.event = event;
13180 data.bailout = false;
13181 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013182
13183 // First do some correct operations using multiple threads.
13184 // Add many entries to command buffer from another thread.
13185 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13186 // Make non-conflicting calls from this thread at the same time.
13187 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013188 uint32_t count;
13189 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013190 }
13191 test_platform_thread_join(thread, NULL);
13192
13193 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013194 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013195 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013196 // Add many entries to command buffer from this thread at the same time.
13197 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013198
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013199 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013200 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013201
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013202 m_errorMonitor->SetBailout(NULL);
13203
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013204 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013205
Chia-I Wuf7458c52015-10-26 21:10:41 +080013206 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013207}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013208#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013209
Karl Schultz6addd812016-02-02 17:17:23 -070013210TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013211 TEST_DESCRIPTION(
13212 "Test that an error is produced for a spirv module "
13213 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013216
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013217 ASSERT_NO_FATAL_FAILURE(InitState());
13218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13219
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013220 VkShaderModule module;
13221 VkShaderModuleCreateInfo moduleCreateInfo;
13222 struct icd_spv_header spv;
13223
13224 spv.magic = ICD_SPV_MAGIC;
13225 spv.version = ICD_SPV_VERSION;
13226 spv.gen_magic = 0;
13227
13228 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13229 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013230 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013231 moduleCreateInfo.codeSize = 4;
13232 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013233 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013235 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013236}
13237
Karl Schultz6addd812016-02-02 17:17:23 -070013238TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013239 TEST_DESCRIPTION(
13240 "Test that an error is produced for a spirv module "
13241 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013244
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013245 ASSERT_NO_FATAL_FAILURE(InitState());
13246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13247
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013248 VkShaderModule module;
13249 VkShaderModuleCreateInfo moduleCreateInfo;
13250 struct icd_spv_header spv;
13251
13252 spv.magic = ~ICD_SPV_MAGIC;
13253 spv.version = ICD_SPV_VERSION;
13254 spv.gen_magic = 0;
13255
13256 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13257 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013258 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013259 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13260 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013261 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013262
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013263 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013264}
13265
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013266#if 0
13267// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013268TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013270 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013271
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013272 ASSERT_NO_FATAL_FAILURE(InitState());
13273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13274
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013275 VkShaderModule module;
13276 VkShaderModuleCreateInfo moduleCreateInfo;
13277 struct icd_spv_header spv;
13278
13279 spv.magic = ICD_SPV_MAGIC;
13280 spv.version = ~ICD_SPV_VERSION;
13281 spv.gen_magic = 0;
13282
13283 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13284 moduleCreateInfo.pNext = NULL;
13285
Karl Schultz6addd812016-02-02 17:17:23 -070013286 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013287 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13288 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013289 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013291 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013292}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013293#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013294
Karl Schultz6addd812016-02-02 17:17:23 -070013295TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013296 TEST_DESCRIPTION(
13297 "Test that a warning is produced for a vertex output that "
13298 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013300
Chris Forbes9f7ff632015-05-25 11:13:08 +120013301 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013303
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013304 char const *vsSource =
13305 "#version 450\n"
13306 "\n"
13307 "layout(location=0) out float x;\n"
13308 "out gl_PerVertex {\n"
13309 " vec4 gl_Position;\n"
13310 "};\n"
13311 "void main(){\n"
13312 " gl_Position = vec4(1);\n"
13313 " x = 0;\n"
13314 "}\n";
13315 char const *fsSource =
13316 "#version 450\n"
13317 "\n"
13318 "layout(location=0) out vec4 color;\n"
13319 "void main(){\n"
13320 " color = vec4(1);\n"
13321 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013322
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013323 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13324 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013325
13326 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013327 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013328 pipe.AddShader(&vs);
13329 pipe.AddShader(&fs);
13330
Chris Forbes9f7ff632015-05-25 11:13:08 +120013331 VkDescriptorSetObj descriptorSet(m_device);
13332 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013333 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013334
Tony Barbour5781e8f2015-08-04 16:23:11 -060013335 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013336
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013337 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013338}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013339
Mark Mueller098c9cb2016-09-08 09:01:57 -060013340TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13341 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13342
13343 ASSERT_NO_FATAL_FAILURE(InitState());
13344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13345
13346 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013347 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013348
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013349 char const *vsSource =
13350 "#version 450\n"
13351 "\n"
13352 "out gl_PerVertex {\n"
13353 " vec4 gl_Position;\n"
13354 "};\n"
13355 "void main(){\n"
13356 " gl_Position = vec4(1);\n"
13357 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013358
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013359 char const *fsSource =
13360 "#version 450\n"
13361 "\n"
13362 "layout (constant_id = 0) const float r = 0.0f;\n"
13363 "layout(location = 0) out vec4 uFragColor;\n"
13364 "void main(){\n"
13365 " uFragColor = vec4(r,1,0,1);\n"
13366 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013367
13368 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13370
13371 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13372 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13373
13374 VkPipelineLayout pipeline_layout;
13375 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13376
13377 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13378 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13379 vp_state_create_info.viewportCount = 1;
13380 VkViewport viewport = {};
13381 vp_state_create_info.pViewports = &viewport;
13382 vp_state_create_info.scissorCount = 1;
13383 VkRect2D scissors = {};
13384 vp_state_create_info.pScissors = &scissors;
13385
13386 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13387
13388 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13389 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13390 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13391 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13392
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013393 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013394
13395 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13396 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13397
13398 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13399 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13400 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13401
13402 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13403 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13404 rasterization_state_create_info.pNext = nullptr;
13405 rasterization_state_create_info.lineWidth = 1.0f;
13406 rasterization_state_create_info.rasterizerDiscardEnable = true;
13407
13408 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13409 color_blend_attachment_state.blendEnable = VK_FALSE;
13410 color_blend_attachment_state.colorWriteMask = 0xf;
13411
13412 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13413 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13414 color_blend_state_create_info.attachmentCount = 1;
13415 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13416
13417 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13418 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13419 graphicspipe_create_info.stageCount = 2;
13420 graphicspipe_create_info.pStages = shader_stage_create_info;
13421 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13422 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13423 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13424 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13425 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13426 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13427 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13428 graphicspipe_create_info.layout = pipeline_layout;
13429 graphicspipe_create_info.renderPass = renderPass();
13430
13431 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13432 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13433
13434 VkPipelineCache pipelineCache;
13435 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13436
13437 // This structure maps constant ids to data locations.
13438 const VkSpecializationMapEntry entry =
13439 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013440 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013441
13442 uint32_t data = 1;
13443
13444 // Set up the info describing spec map and data
13445 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013446 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013447 };
13448 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13449
13450 VkPipeline pipeline;
13451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13452 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13453 m_errorMonitor->VerifyFound();
13454
13455 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13456 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13457}
13458
13459TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13460 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13461
13462 ASSERT_NO_FATAL_FAILURE(InitState());
13463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13464
13465 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13466
13467 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13468 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13469 descriptor_pool_type_count[0].descriptorCount = 1;
13470 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13471 descriptor_pool_type_count[1].descriptorCount = 1;
13472
13473 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13474 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13475 descriptor_pool_create_info.maxSets = 1;
13476 descriptor_pool_create_info.poolSizeCount = 2;
13477 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13478 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13479
13480 VkDescriptorPool descriptorset_pool;
13481 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13482
13483 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13484 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13485 descriptorset_layout_binding.descriptorCount = 1;
13486 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13487
13488 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13489 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13490 descriptorset_layout_create_info.bindingCount = 1;
13491 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13492
13493 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013494 ASSERT_VK_SUCCESS(
13495 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013496
13497 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13498 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13499 descriptorset_allocate_info.descriptorSetCount = 1;
13500 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13501 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13502 VkDescriptorSet descriptorset;
13503 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13504
13505 // Challenge core_validation with a non uniform buffer type.
13506 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13507
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013508 char const *vsSource =
13509 "#version 450\n"
13510 "\n"
13511 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13512 " mat4 mvp;\n"
13513 "} ubuf;\n"
13514 "out gl_PerVertex {\n"
13515 " vec4 gl_Position;\n"
13516 "};\n"
13517 "void main(){\n"
13518 " gl_Position = ubuf.mvp * vec4(1);\n"
13519 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013520
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013521 char const *fsSource =
13522 "#version 450\n"
13523 "\n"
13524 "layout(location = 0) out vec4 uFragColor;\n"
13525 "void main(){\n"
13526 " uFragColor = vec4(0,1,0,1);\n"
13527 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013528
13529 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13530 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13531
13532 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13533 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13534 pipeline_layout_create_info.setLayoutCount = 1;
13535 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13536
13537 VkPipelineLayout pipeline_layout;
13538 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13539
13540 VkPipelineObj pipe(m_device);
13541 pipe.AddColorAttachment();
13542 pipe.AddShader(&vs);
13543 pipe.AddShader(&fs);
13544
13545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13546 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13547 m_errorMonitor->VerifyFound();
13548
13549 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13550 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13551 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13552}
13553
13554TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13555 TEST_DESCRIPTION(
13556 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13557
13558 ASSERT_NO_FATAL_FAILURE(InitState());
13559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13560
13561 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13562
13563 VkDescriptorPoolSize descriptor_pool_type_count = {};
13564 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13565 descriptor_pool_type_count.descriptorCount = 1;
13566
13567 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13568 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13569 descriptor_pool_create_info.maxSets = 1;
13570 descriptor_pool_create_info.poolSizeCount = 1;
13571 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13572 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13573
13574 VkDescriptorPool descriptorset_pool;
13575 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13576
13577 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13578 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13579 descriptorset_layout_binding.descriptorCount = 1;
13580 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13581 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13582
13583 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13584 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13585 descriptorset_layout_create_info.bindingCount = 1;
13586 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13587
13588 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013589 ASSERT_VK_SUCCESS(
13590 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013591
13592 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13593 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13594 descriptorset_allocate_info.descriptorSetCount = 1;
13595 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13596 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13597 VkDescriptorSet descriptorset;
13598 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13599
13600 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13601
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013602 char const *vsSource =
13603 "#version 450\n"
13604 "\n"
13605 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13606 " mat4 mvp;\n"
13607 "} ubuf;\n"
13608 "out gl_PerVertex {\n"
13609 " vec4 gl_Position;\n"
13610 "};\n"
13611 "void main(){\n"
13612 " gl_Position = ubuf.mvp * vec4(1);\n"
13613 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013614
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013615 char const *fsSource =
13616 "#version 450\n"
13617 "\n"
13618 "layout(location = 0) out vec4 uFragColor;\n"
13619 "void main(){\n"
13620 " uFragColor = vec4(0,1,0,1);\n"
13621 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013622
13623 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13624 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13625
13626 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13627 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13628 pipeline_layout_create_info.setLayoutCount = 1;
13629 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13630
13631 VkPipelineLayout pipeline_layout;
13632 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13633
13634 VkPipelineObj pipe(m_device);
13635 pipe.AddColorAttachment();
13636 pipe.AddShader(&vs);
13637 pipe.AddShader(&fs);
13638
13639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13640 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13641 m_errorMonitor->VerifyFound();
13642
13643 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13644 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13645 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13646}
13647
13648TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013649 TEST_DESCRIPTION(
13650 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13651 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013652
13653 ASSERT_NO_FATAL_FAILURE(InitState());
13654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13655
13656 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013657 "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 -060013658
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013659 char const *vsSource =
13660 "#version 450\n"
13661 "\n"
13662 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13663 "out gl_PerVertex {\n"
13664 " vec4 gl_Position;\n"
13665 "};\n"
13666 "void main(){\n"
13667 " gl_Position = vec4(consts.x);\n"
13668 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013669
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013670 char const *fsSource =
13671 "#version 450\n"
13672 "\n"
13673 "layout(location = 0) out vec4 uFragColor;\n"
13674 "void main(){\n"
13675 " uFragColor = vec4(0,1,0,1);\n"
13676 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013677
13678 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13680
13681 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13682 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13683
13684 // Set up a push constant range
13685 VkPushConstantRange push_constant_ranges = {};
13686 // Set to the wrong stage to challenge core_validation
13687 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13688 push_constant_ranges.size = 4;
13689
13690 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13691 pipeline_layout_create_info.pushConstantRangeCount = 1;
13692
13693 VkPipelineLayout pipeline_layout;
13694 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13695
13696 VkPipelineObj pipe(m_device);
13697 pipe.AddColorAttachment();
13698 pipe.AddShader(&vs);
13699 pipe.AddShader(&fs);
13700
13701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13702 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13703 m_errorMonitor->VerifyFound();
13704
13705 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13706}
13707
13708TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13709 TEST_DESCRIPTION(
13710 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13711
13712 ASSERT_NO_FATAL_FAILURE(InitState());
13713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13714
13715 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013716 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013717
13718 // Some awkward steps are required to test with custom device features.
13719 std::vector<const char *> device_extension_names;
13720 auto features = m_device->phy().features();
13721 // Disable support for 64 bit floats
13722 features.shaderFloat64 = false;
13723 // The sacrificial device object
13724 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13725
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013726 char const *vsSource =
13727 "#version 450\n"
13728 "\n"
13729 "out gl_PerVertex {\n"
13730 " vec4 gl_Position;\n"
13731 "};\n"
13732 "void main(){\n"
13733 " gl_Position = vec4(1);\n"
13734 "}\n";
13735 char const *fsSource =
13736 "#version 450\n"
13737 "\n"
13738 "layout(location=0) out vec4 color;\n"
13739 "void main(){\n"
13740 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13741 " color = vec4(green);\n"
13742 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013743
13744 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13745 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13746
13747 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013748
13749 VkPipelineObj pipe(&test_device);
13750 pipe.AddColorAttachment();
13751 pipe.AddShader(&vs);
13752 pipe.AddShader(&fs);
13753
13754 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13755 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13756 VkPipelineLayout pipeline_layout;
13757 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13758
13759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13760 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13761 m_errorMonitor->VerifyFound();
13762
13763 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13764}
13765
13766TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13767 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13768
13769 ASSERT_NO_FATAL_FAILURE(InitState());
13770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13771
13772 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13773
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013774 char const *vsSource =
13775 "#version 450\n"
13776 "\n"
13777 "out gl_PerVertex {\n"
13778 " vec4 gl_Position;\n"
13779 "};\n"
13780 "layout(xfb_buffer = 1) out;"
13781 "void main(){\n"
13782 " gl_Position = vec4(1);\n"
13783 "}\n";
13784 char const *fsSource =
13785 "#version 450\n"
13786 "\n"
13787 "layout(location=0) out vec4 color;\n"
13788 "void main(){\n"
13789 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13790 " color = vec4(green);\n"
13791 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013792
13793 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13794 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13795
13796 VkPipelineObj pipe(m_device);
13797 pipe.AddColorAttachment();
13798 pipe.AddShader(&vs);
13799 pipe.AddShader(&fs);
13800
13801 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13802 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13803 VkPipelineLayout pipeline_layout;
13804 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13805
13806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13807 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13808 m_errorMonitor->VerifyFound();
13809
13810 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13811}
13812
Karl Schultz6addd812016-02-02 17:17:23 -070013813TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013814 TEST_DESCRIPTION(
13815 "Test that an error is produced for a fragment shader input "
13816 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013819
Chris Forbes59cb88d2015-05-25 11:13:13 +120013820 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013821 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013822
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013823 char const *vsSource =
13824 "#version 450\n"
13825 "\n"
13826 "out gl_PerVertex {\n"
13827 " vec4 gl_Position;\n"
13828 "};\n"
13829 "void main(){\n"
13830 " gl_Position = vec4(1);\n"
13831 "}\n";
13832 char const *fsSource =
13833 "#version 450\n"
13834 "\n"
13835 "layout(location=0) in float x;\n"
13836 "layout(location=0) out vec4 color;\n"
13837 "void main(){\n"
13838 " color = vec4(x);\n"
13839 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013840
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013841 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13842 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013843
13844 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013845 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013846 pipe.AddShader(&vs);
13847 pipe.AddShader(&fs);
13848
Chris Forbes59cb88d2015-05-25 11:13:13 +120013849 VkDescriptorSetObj descriptorSet(m_device);
13850 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013851 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013852
Tony Barbour5781e8f2015-08-04 16:23:11 -060013853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013854
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013855 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013856}
13857
Karl Schultz6addd812016-02-02 17:17:23 -070013858TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013859 TEST_DESCRIPTION(
13860 "Test that an error is produced for a fragment shader input "
13861 "within an interace block, which is not present in the outputs "
13862 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013864
13865 ASSERT_NO_FATAL_FAILURE(InitState());
13866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13867
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013868 char const *vsSource =
13869 "#version 450\n"
13870 "\n"
13871 "out gl_PerVertex {\n"
13872 " vec4 gl_Position;\n"
13873 "};\n"
13874 "void main(){\n"
13875 " gl_Position = vec4(1);\n"
13876 "}\n";
13877 char const *fsSource =
13878 "#version 450\n"
13879 "\n"
13880 "in block { layout(location=0) float x; } ins;\n"
13881 "layout(location=0) out vec4 color;\n"
13882 "void main(){\n"
13883 " color = vec4(ins.x);\n"
13884 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013885
13886 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13887 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13888
13889 VkPipelineObj pipe(m_device);
13890 pipe.AddColorAttachment();
13891 pipe.AddShader(&vs);
13892 pipe.AddShader(&fs);
13893
13894 VkDescriptorSetObj descriptorSet(m_device);
13895 descriptorSet.AppendDummy();
13896 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13897
13898 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13899
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013900 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013901}
13902
Karl Schultz6addd812016-02-02 17:17:23 -070013903TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013904 TEST_DESCRIPTION(
13905 "Test that an error is produced for mismatched array sizes "
13906 "across the vertex->fragment shader interface");
13907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13908 "Type mismatch on location 0.0: 'ptr to "
13909 "output arr[2] of float32' vs 'ptr to "
13910 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013911
13912 ASSERT_NO_FATAL_FAILURE(InitState());
13913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13914
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013915 char const *vsSource =
13916 "#version 450\n"
13917 "\n"
13918 "layout(location=0) out float x[2];\n"
13919 "out gl_PerVertex {\n"
13920 " vec4 gl_Position;\n"
13921 "};\n"
13922 "void main(){\n"
13923 " x[0] = 0; x[1] = 0;\n"
13924 " gl_Position = vec4(1);\n"
13925 "}\n";
13926 char const *fsSource =
13927 "#version 450\n"
13928 "\n"
13929 "layout(location=0) in float x[1];\n"
13930 "layout(location=0) out vec4 color;\n"
13931 "void main(){\n"
13932 " color = vec4(x[0]);\n"
13933 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013934
13935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13937
13938 VkPipelineObj pipe(m_device);
13939 pipe.AddColorAttachment();
13940 pipe.AddShader(&vs);
13941 pipe.AddShader(&fs);
13942
13943 VkDescriptorSetObj descriptorSet(m_device);
13944 descriptorSet.AppendDummy();
13945 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13946
13947 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13948
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013949 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013950}
13951
Karl Schultz6addd812016-02-02 17:17:23 -070013952TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013953 TEST_DESCRIPTION(
13954 "Test that an error is produced for mismatched types across "
13955 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013957
Chris Forbesb56af562015-05-25 11:13:17 +120013958 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013960
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013961 char const *vsSource =
13962 "#version 450\n"
13963 "\n"
13964 "layout(location=0) out int x;\n"
13965 "out gl_PerVertex {\n"
13966 " vec4 gl_Position;\n"
13967 "};\n"
13968 "void main(){\n"
13969 " x = 0;\n"
13970 " gl_Position = vec4(1);\n"
13971 "}\n";
13972 char const *fsSource =
13973 "#version 450\n"
13974 "\n"
13975 "layout(location=0) in float x;\n" /* VS writes int */
13976 "layout(location=0) out vec4 color;\n"
13977 "void main(){\n"
13978 " color = vec4(x);\n"
13979 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013980
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013981 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13982 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013983
13984 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013985 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013986 pipe.AddShader(&vs);
13987 pipe.AddShader(&fs);
13988
Chris Forbesb56af562015-05-25 11:13:17 +120013989 VkDescriptorSetObj descriptorSet(m_device);
13990 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013991 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013992
Tony Barbour5781e8f2015-08-04 16:23:11 -060013993 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013994
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013995 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013996}
13997
Karl Schultz6addd812016-02-02 17:17:23 -070013998TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013999 TEST_DESCRIPTION(
14000 "Test that an error is produced for mismatched types across "
14001 "the vertex->fragment shader interface, when the variable is contained within "
14002 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014004
14005 ASSERT_NO_FATAL_FAILURE(InitState());
14006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14007
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014008 char const *vsSource =
14009 "#version 450\n"
14010 "\n"
14011 "out block { layout(location=0) int x; } outs;\n"
14012 "out gl_PerVertex {\n"
14013 " vec4 gl_Position;\n"
14014 "};\n"
14015 "void main(){\n"
14016 " outs.x = 0;\n"
14017 " gl_Position = vec4(1);\n"
14018 "}\n";
14019 char const *fsSource =
14020 "#version 450\n"
14021 "\n"
14022 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14023 "layout(location=0) out vec4 color;\n"
14024 "void main(){\n"
14025 " color = vec4(ins.x);\n"
14026 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014027
14028 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14029 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14030
14031 VkPipelineObj pipe(m_device);
14032 pipe.AddColorAttachment();
14033 pipe.AddShader(&vs);
14034 pipe.AddShader(&fs);
14035
14036 VkDescriptorSetObj descriptorSet(m_device);
14037 descriptorSet.AppendDummy();
14038 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14039
14040 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14041
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014042 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014043}
14044
14045TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014046 TEST_DESCRIPTION(
14047 "Test that an error is produced for location mismatches across "
14048 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14049 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014050 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 +130014051
14052 ASSERT_NO_FATAL_FAILURE(InitState());
14053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14054
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014055 char const *vsSource =
14056 "#version 450\n"
14057 "\n"
14058 "out block { layout(location=1) float x; } outs;\n"
14059 "out gl_PerVertex {\n"
14060 " vec4 gl_Position;\n"
14061 "};\n"
14062 "void main(){\n"
14063 " outs.x = 0;\n"
14064 " gl_Position = vec4(1);\n"
14065 "}\n";
14066 char const *fsSource =
14067 "#version 450\n"
14068 "\n"
14069 "in block { layout(location=0) float x; } ins;\n"
14070 "layout(location=0) out vec4 color;\n"
14071 "void main(){\n"
14072 " color = vec4(ins.x);\n"
14073 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014074
14075 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14076 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14077
14078 VkPipelineObj pipe(m_device);
14079 pipe.AddColorAttachment();
14080 pipe.AddShader(&vs);
14081 pipe.AddShader(&fs);
14082
14083 VkDescriptorSetObj descriptorSet(m_device);
14084 descriptorSet.AppendDummy();
14085 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14086
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014087 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014088 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14089
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014090 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014091}
14092
14093TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014094 TEST_DESCRIPTION(
14095 "Test that an error is produced for component mismatches across the "
14096 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14097 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014098 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 +130014099
14100 ASSERT_NO_FATAL_FAILURE(InitState());
14101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14102
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014103 char const *vsSource =
14104 "#version 450\n"
14105 "\n"
14106 "out block { layout(location=0, component=0) float x; } outs;\n"
14107 "out gl_PerVertex {\n"
14108 " vec4 gl_Position;\n"
14109 "};\n"
14110 "void main(){\n"
14111 " outs.x = 0;\n"
14112 " gl_Position = vec4(1);\n"
14113 "}\n";
14114 char const *fsSource =
14115 "#version 450\n"
14116 "\n"
14117 "in block { layout(location=0, component=1) float x; } ins;\n"
14118 "layout(location=0) out vec4 color;\n"
14119 "void main(){\n"
14120 " color = vec4(ins.x);\n"
14121 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014122
14123 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14124 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14125
14126 VkPipelineObj pipe(m_device);
14127 pipe.AddColorAttachment();
14128 pipe.AddShader(&vs);
14129 pipe.AddShader(&fs);
14130
14131 VkDescriptorSetObj descriptorSet(m_device);
14132 descriptorSet.AppendDummy();
14133 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14134
14135 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14136
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014137 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014138}
14139
Chris Forbes1f3b0152016-11-30 12:48:40 +130014140TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14141 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14142
14143 ASSERT_NO_FATAL_FAILURE(InitState());
14144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14145
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014146 char const *vsSource =
14147 "#version 450\n"
14148 "layout(location=0) out mediump float x;\n"
14149 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14150 char const *fsSource =
14151 "#version 450\n"
14152 "layout(location=0) in highp float x;\n"
14153 "layout(location=0) out vec4 color;\n"
14154 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014155
14156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14158
14159 VkPipelineObj pipe(m_device);
14160 pipe.AddColorAttachment();
14161 pipe.AddShader(&vs);
14162 pipe.AddShader(&fs);
14163
14164 VkDescriptorSetObj descriptorSet(m_device);
14165 descriptorSet.AppendDummy();
14166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14167
14168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14169
14170 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14171
14172 m_errorMonitor->VerifyFound();
14173}
14174
Chris Forbes870a39e2016-11-30 12:55:56 +130014175TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14176 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14177
14178 ASSERT_NO_FATAL_FAILURE(InitState());
14179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14180
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014181 char const *vsSource =
14182 "#version 450\n"
14183 "out block { layout(location=0) mediump float x; };\n"
14184 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14185 char const *fsSource =
14186 "#version 450\n"
14187 "in block { layout(location=0) highp float x; };\n"
14188 "layout(location=0) out vec4 color;\n"
14189 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014190
14191 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14192 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14193
14194 VkPipelineObj pipe(m_device);
14195 pipe.AddColorAttachment();
14196 pipe.AddShader(&vs);
14197 pipe.AddShader(&fs);
14198
14199 VkDescriptorSetObj descriptorSet(m_device);
14200 descriptorSet.AppendDummy();
14201 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14202
14203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14204
14205 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14206
14207 m_errorMonitor->VerifyFound();
14208}
14209
Karl Schultz6addd812016-02-02 17:17:23 -070014210TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014211 TEST_DESCRIPTION(
14212 "Test that a warning is produced for a vertex attribute which is "
14213 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014215
Chris Forbesde136e02015-05-25 11:13:28 +120014216 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014218
14219 VkVertexInputBindingDescription input_binding;
14220 memset(&input_binding, 0, sizeof(input_binding));
14221
14222 VkVertexInputAttributeDescription input_attrib;
14223 memset(&input_attrib, 0, sizeof(input_attrib));
14224 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14225
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014226 char const *vsSource =
14227 "#version 450\n"
14228 "\n"
14229 "out gl_PerVertex {\n"
14230 " vec4 gl_Position;\n"
14231 "};\n"
14232 "void main(){\n"
14233 " gl_Position = vec4(1);\n"
14234 "}\n";
14235 char const *fsSource =
14236 "#version 450\n"
14237 "\n"
14238 "layout(location=0) out vec4 color;\n"
14239 "void main(){\n"
14240 " color = vec4(1);\n"
14241 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +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 Forbesde136e02015-05-25 11:13:28 +120014245
14246 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014247 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014248 pipe.AddShader(&vs);
14249 pipe.AddShader(&fs);
14250
14251 pipe.AddVertexInputBindings(&input_binding, 1);
14252 pipe.AddVertexInputAttribs(&input_attrib, 1);
14253
Chris Forbesde136e02015-05-25 11:13:28 +120014254 VkDescriptorSetObj descriptorSet(m_device);
14255 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014256 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014257
Tony Barbour5781e8f2015-08-04 16:23:11 -060014258 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014259
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014260 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014261}
14262
Karl Schultz6addd812016-02-02 17:17:23 -070014263TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014264 TEST_DESCRIPTION(
14265 "Test that a warning is produced for a location mismatch on "
14266 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014268
14269 ASSERT_NO_FATAL_FAILURE(InitState());
14270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14271
14272 VkVertexInputBindingDescription input_binding;
14273 memset(&input_binding, 0, sizeof(input_binding));
14274
14275 VkVertexInputAttributeDescription input_attrib;
14276 memset(&input_attrib, 0, sizeof(input_attrib));
14277 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14278
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014279 char const *vsSource =
14280 "#version 450\n"
14281 "\n"
14282 "layout(location=1) in float x;\n"
14283 "out gl_PerVertex {\n"
14284 " vec4 gl_Position;\n"
14285 "};\n"
14286 "void main(){\n"
14287 " gl_Position = vec4(x);\n"
14288 "}\n";
14289 char const *fsSource =
14290 "#version 450\n"
14291 "\n"
14292 "layout(location=0) out vec4 color;\n"
14293 "void main(){\n"
14294 " color = vec4(1);\n"
14295 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014296
14297 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14298 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14299
14300 VkPipelineObj pipe(m_device);
14301 pipe.AddColorAttachment();
14302 pipe.AddShader(&vs);
14303 pipe.AddShader(&fs);
14304
14305 pipe.AddVertexInputBindings(&input_binding, 1);
14306 pipe.AddVertexInputAttribs(&input_attrib, 1);
14307
14308 VkDescriptorSetObj descriptorSet(m_device);
14309 descriptorSet.AppendDummy();
14310 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14311
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014312 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014313 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14314
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014315 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014316}
14317
Karl Schultz6addd812016-02-02 17:17:23 -070014318TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014319 TEST_DESCRIPTION(
14320 "Test that an error is produced for a vertex shader input which is not "
14321 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14323 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014324
Chris Forbes62e8e502015-05-25 11:13:29 +120014325 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014327
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014328 char const *vsSource =
14329 "#version 450\n"
14330 "\n"
14331 "layout(location=0) in vec4 x;\n" /* not provided */
14332 "out gl_PerVertex {\n"
14333 " vec4 gl_Position;\n"
14334 "};\n"
14335 "void main(){\n"
14336 " gl_Position = x;\n"
14337 "}\n";
14338 char const *fsSource =
14339 "#version 450\n"
14340 "\n"
14341 "layout(location=0) out vec4 color;\n"
14342 "void main(){\n"
14343 " color = vec4(1);\n"
14344 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014345
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014348
14349 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014350 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014351 pipe.AddShader(&vs);
14352 pipe.AddShader(&fs);
14353
Chris Forbes62e8e502015-05-25 11:13:29 +120014354 VkDescriptorSetObj descriptorSet(m_device);
14355 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014356 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014357
Tony Barbour5781e8f2015-08-04 16:23:11 -060014358 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014359
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014360 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014361}
14362
Karl Schultz6addd812016-02-02 17:17:23 -070014363TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014364 TEST_DESCRIPTION(
14365 "Test that an error is produced for a mismatch between the "
14366 "fundamental type (float/int/uint) of an attribute and the "
14367 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014368 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 -060014369
Chris Forbesc97d98e2015-05-25 11:13:31 +120014370 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014372
14373 VkVertexInputBindingDescription input_binding;
14374 memset(&input_binding, 0, sizeof(input_binding));
14375
14376 VkVertexInputAttributeDescription input_attrib;
14377 memset(&input_attrib, 0, sizeof(input_attrib));
14378 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14379
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014380 char const *vsSource =
14381 "#version 450\n"
14382 "\n"
14383 "layout(location=0) in int x;\n" /* attrib provided float */
14384 "out gl_PerVertex {\n"
14385 " vec4 gl_Position;\n"
14386 "};\n"
14387 "void main(){\n"
14388 " gl_Position = vec4(x);\n"
14389 "}\n";
14390 char const *fsSource =
14391 "#version 450\n"
14392 "\n"
14393 "layout(location=0) out vec4 color;\n"
14394 "void main(){\n"
14395 " color = vec4(1);\n"
14396 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014397
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014398 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14399 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014400
14401 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014402 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014403 pipe.AddShader(&vs);
14404 pipe.AddShader(&fs);
14405
14406 pipe.AddVertexInputBindings(&input_binding, 1);
14407 pipe.AddVertexInputAttribs(&input_attrib, 1);
14408
Chris Forbesc97d98e2015-05-25 11:13:31 +120014409 VkDescriptorSetObj descriptorSet(m_device);
14410 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014411 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014412
Tony Barbour5781e8f2015-08-04 16:23:11 -060014413 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014414
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014415 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014416}
14417
Chris Forbesc68b43c2016-04-06 11:18:47 +120014418TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014419 TEST_DESCRIPTION(
14420 "Test that an error is produced for a pipeline containing multiple "
14421 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14423 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014424
14425 ASSERT_NO_FATAL_FAILURE(InitState());
14426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014428 char const *vsSource =
14429 "#version 450\n"
14430 "\n"
14431 "out gl_PerVertex {\n"
14432 " vec4 gl_Position;\n"
14433 "};\n"
14434 "void main(){\n"
14435 " gl_Position = vec4(1);\n"
14436 "}\n";
14437 char const *fsSource =
14438 "#version 450\n"
14439 "\n"
14440 "layout(location=0) out vec4 color;\n"
14441 "void main(){\n"
14442 " color = vec4(1);\n"
14443 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014444
14445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14447
14448 VkPipelineObj pipe(m_device);
14449 pipe.AddColorAttachment();
14450 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014451 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014452 pipe.AddShader(&fs);
14453
14454 VkDescriptorSetObj descriptorSet(m_device);
14455 descriptorSet.AppendDummy();
14456 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14457
14458 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14459
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014460 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014461}
14462
Chris Forbes82ff92a2016-09-09 10:50:24 +120014463TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014465
14466 ASSERT_NO_FATAL_FAILURE(InitState());
14467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14468
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014469 char const *vsSource =
14470 "#version 450\n"
14471 "out gl_PerVertex {\n"
14472 " vec4 gl_Position;\n"
14473 "};\n"
14474 "void main(){\n"
14475 " gl_Position = vec4(0);\n"
14476 "}\n";
14477 char const *fsSource =
14478 "#version 450\n"
14479 "\n"
14480 "layout(location=0) out vec4 color;\n"
14481 "void main(){\n"
14482 " color = vec4(1);\n"
14483 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014484
14485 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14486 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14487
14488 VkPipelineObj pipe(m_device);
14489 pipe.AddColorAttachment();
14490 pipe.AddShader(&vs);
14491 pipe.AddShader(&fs);
14492
14493 VkDescriptorSetObj descriptorSet(m_device);
14494 descriptorSet.AppendDummy();
14495 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14496
14497 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14498
14499 m_errorMonitor->VerifyFound();
14500}
14501
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014502TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14504 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14505 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014506
14507 ASSERT_NO_FATAL_FAILURE(InitState());
14508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14509
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014510 char const *vsSource =
14511 "#version 450\n"
14512 "void main(){ gl_Position = vec4(0); }\n";
14513 char const *fsSource =
14514 "#version 450\n"
14515 "\n"
14516 "layout(location=0) out vec4 color;\n"
14517 "void main(){\n"
14518 " color = vec4(1);\n"
14519 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014520
14521 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14522 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14523
14524 VkPipelineObj pipe(m_device);
14525 pipe.AddColorAttachment();
14526 pipe.AddShader(&vs);
14527 pipe.AddShader(&fs);
14528
14529 VkDescriptorSetObj descriptorSet(m_device);
14530 descriptorSet.AppendDummy();
14531 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14532
14533 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014534 {
14535 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14536 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14537 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014538 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014539 {
14540 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14541 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14542 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014543 },
14544 };
14545 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014546 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014547 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014548 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14549 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014550 VkRenderPass rp;
14551 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14552 ASSERT_VK_SUCCESS(err);
14553
14554 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14555
14556 m_errorMonitor->VerifyFound();
14557
14558 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14559}
14560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014561TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014562 TEST_DESCRIPTION(
14563 "Test that an error is produced for a variable output from "
14564 "the TCS without the patch decoration, but consumed in the TES "
14565 "with the decoration.");
14566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14567 "is per-vertex in tessellation control shader stage "
14568 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014569
14570 ASSERT_NO_FATAL_FAILURE(InitState());
14571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14572
Chris Forbesc1e852d2016-04-04 19:26:42 +120014573 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014574 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014575 return;
14576 }
14577
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014578 char const *vsSource =
14579 "#version 450\n"
14580 "void main(){}\n";
14581 char const *tcsSource =
14582 "#version 450\n"
14583 "layout(location=0) out int x[];\n"
14584 "layout(vertices=3) out;\n"
14585 "void main(){\n"
14586 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14587 " gl_TessLevelInner[0] = 1;\n"
14588 " x[gl_InvocationID] = gl_InvocationID;\n"
14589 "}\n";
14590 char const *tesSource =
14591 "#version 450\n"
14592 "layout(triangles, equal_spacing, cw) in;\n"
14593 "layout(location=0) patch in int x;\n"
14594 "out gl_PerVertex { vec4 gl_Position; };\n"
14595 "void main(){\n"
14596 " gl_Position.xyz = gl_TessCoord;\n"
14597 " gl_Position.w = x;\n"
14598 "}\n";
14599 char const *fsSource =
14600 "#version 450\n"
14601 "layout(location=0) out vec4 color;\n"
14602 "void main(){\n"
14603 " color = vec4(1);\n"
14604 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014605
14606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14607 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14608 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14609 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014611 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14612 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014613
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014614 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014615
14616 VkPipelineObj pipe(m_device);
14617 pipe.SetInputAssembly(&iasci);
14618 pipe.SetTessellation(&tsci);
14619 pipe.AddColorAttachment();
14620 pipe.AddShader(&vs);
14621 pipe.AddShader(&tcs);
14622 pipe.AddShader(&tes);
14623 pipe.AddShader(&fs);
14624
14625 VkDescriptorSetObj descriptorSet(m_device);
14626 descriptorSet.AppendDummy();
14627 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14628
14629 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14630
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014631 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014632}
14633
Karl Schultz6addd812016-02-02 17:17:23 -070014634TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014635 TEST_DESCRIPTION(
14636 "Test that an error is produced for a vertex attribute setup where multiple "
14637 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14639 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014640
Chris Forbes280ba2c2015-06-12 11:16:41 +120014641 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014643
14644 /* Two binding descriptions for binding 0 */
14645 VkVertexInputBindingDescription input_bindings[2];
14646 memset(input_bindings, 0, sizeof(input_bindings));
14647
14648 VkVertexInputAttributeDescription input_attrib;
14649 memset(&input_attrib, 0, sizeof(input_attrib));
14650 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14651
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014652 char const *vsSource =
14653 "#version 450\n"
14654 "\n"
14655 "layout(location=0) in float x;\n" /* attrib provided float */
14656 "out gl_PerVertex {\n"
14657 " vec4 gl_Position;\n"
14658 "};\n"
14659 "void main(){\n"
14660 " gl_Position = vec4(x);\n"
14661 "}\n";
14662 char const *fsSource =
14663 "#version 450\n"
14664 "\n"
14665 "layout(location=0) out vec4 color;\n"
14666 "void main(){\n"
14667 " color = vec4(1);\n"
14668 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014669
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014670 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14671 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014672
14673 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014674 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014675 pipe.AddShader(&vs);
14676 pipe.AddShader(&fs);
14677
14678 pipe.AddVertexInputBindings(input_bindings, 2);
14679 pipe.AddVertexInputAttribs(&input_attrib, 1);
14680
Chris Forbes280ba2c2015-06-12 11:16:41 +120014681 VkDescriptorSetObj descriptorSet(m_device);
14682 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014683 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014684
Tony Barbour5781e8f2015-08-04 16:23:11 -060014685 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014686
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014687 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014688}
Chris Forbes8f68b562015-05-25 11:13:32 +120014689
Karl Schultz6addd812016-02-02 17:17:23 -070014690TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014691 TEST_DESCRIPTION(
14692 "Test that an error is produced for a fragment shader which does not "
14693 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014695
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014696 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014697
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014698 char const *vsSource =
14699 "#version 450\n"
14700 "\n"
14701 "out gl_PerVertex {\n"
14702 " vec4 gl_Position;\n"
14703 "};\n"
14704 "void main(){\n"
14705 " gl_Position = vec4(1);\n"
14706 "}\n";
14707 char const *fsSource =
14708 "#version 450\n"
14709 "\n"
14710 "void main(){\n"
14711 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014712
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014713 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14714 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014715
14716 VkPipelineObj pipe(m_device);
14717 pipe.AddShader(&vs);
14718 pipe.AddShader(&fs);
14719
Chia-I Wu08accc62015-07-07 11:50:03 +080014720 /* set up CB 0, not written */
14721 pipe.AddColorAttachment();
14722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014723
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014724 VkDescriptorSetObj descriptorSet(m_device);
14725 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014726 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014727
Tony Barbour5781e8f2015-08-04 16:23:11 -060014728 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014729
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014730 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014731}
14732
Karl Schultz6addd812016-02-02 17:17:23 -070014733TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014734 TEST_DESCRIPTION(
14735 "Test that a warning is produced for a fragment shader which provides a spurious "
14736 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014738 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014739
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014740 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014741
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014742 char const *vsSource =
14743 "#version 450\n"
14744 "\n"
14745 "out gl_PerVertex {\n"
14746 " vec4 gl_Position;\n"
14747 "};\n"
14748 "void main(){\n"
14749 " gl_Position = vec4(1);\n"
14750 "}\n";
14751 char const *fsSource =
14752 "#version 450\n"
14753 "\n"
14754 "layout(location=0) out vec4 x;\n"
14755 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14756 "void main(){\n"
14757 " x = vec4(1);\n"
14758 " y = vec4(1);\n"
14759 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014760
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014761 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014763
14764 VkPipelineObj pipe(m_device);
14765 pipe.AddShader(&vs);
14766 pipe.AddShader(&fs);
14767
Chia-I Wu08accc62015-07-07 11:50:03 +080014768 /* set up CB 0, not written */
14769 pipe.AddColorAttachment();
14770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014771 /* FS writes CB 1, but we don't configure it */
14772
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014773 VkDescriptorSetObj descriptorSet(m_device);
14774 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014775 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014776
Tony Barbour5781e8f2015-08-04 16:23:11 -060014777 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014778
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014779 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014780}
14781
Karl Schultz6addd812016-02-02 17:17:23 -070014782TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014783 TEST_DESCRIPTION(
14784 "Test that an error is produced for a mismatch between the fundamental "
14785 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014787
Chris Forbesa36d69e2015-05-25 11:13:44 +120014788 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014789
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014790 char const *vsSource =
14791 "#version 450\n"
14792 "\n"
14793 "out gl_PerVertex {\n"
14794 " vec4 gl_Position;\n"
14795 "};\n"
14796 "void main(){\n"
14797 " gl_Position = vec4(1);\n"
14798 "}\n";
14799 char const *fsSource =
14800 "#version 450\n"
14801 "\n"
14802 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14803 "void main(){\n"
14804 " x = ivec4(1);\n"
14805 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014806
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014807 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14808 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014809
14810 VkPipelineObj pipe(m_device);
14811 pipe.AddShader(&vs);
14812 pipe.AddShader(&fs);
14813
Chia-I Wu08accc62015-07-07 11:50:03 +080014814 /* set up CB 0; type is UNORM by default */
14815 pipe.AddColorAttachment();
14816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014817
Chris Forbesa36d69e2015-05-25 11:13:44 +120014818 VkDescriptorSetObj descriptorSet(m_device);
14819 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014820 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014821
Tony Barbour5781e8f2015-08-04 16:23:11 -060014822 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014823
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014824 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014825}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014826
Karl Schultz6addd812016-02-02 17:17:23 -070014827TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014828 TEST_DESCRIPTION(
14829 "Test that an error is produced for a shader consuming a uniform "
14830 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014832
Chris Forbes556c76c2015-08-14 12:04:59 +120014833 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014834
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014835 char const *vsSource =
14836 "#version 450\n"
14837 "\n"
14838 "out gl_PerVertex {\n"
14839 " vec4 gl_Position;\n"
14840 "};\n"
14841 "void main(){\n"
14842 " gl_Position = vec4(1);\n"
14843 "}\n";
14844 char const *fsSource =
14845 "#version 450\n"
14846 "\n"
14847 "layout(location=0) out vec4 x;\n"
14848 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14849 "void main(){\n"
14850 " x = vec4(bar.y);\n"
14851 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014852
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014855
Chris Forbes556c76c2015-08-14 12:04:59 +120014856 VkPipelineObj pipe(m_device);
14857 pipe.AddShader(&vs);
14858 pipe.AddShader(&fs);
14859
14860 /* set up CB 0; type is UNORM by default */
14861 pipe.AddColorAttachment();
14862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14863
14864 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014865 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014866
14867 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14868
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014869 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014870}
14871
Chris Forbes5c59e902016-02-26 16:56:09 +130014872TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014873 TEST_DESCRIPTION(
14874 "Test that an error is produced for a shader consuming push constants "
14875 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014877
14878 ASSERT_NO_FATAL_FAILURE(InitState());
14879
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014880 char const *vsSource =
14881 "#version 450\n"
14882 "\n"
14883 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14884 "out gl_PerVertex {\n"
14885 " vec4 gl_Position;\n"
14886 "};\n"
14887 "void main(){\n"
14888 " gl_Position = vec4(consts.x);\n"
14889 "}\n";
14890 char const *fsSource =
14891 "#version 450\n"
14892 "\n"
14893 "layout(location=0) out vec4 x;\n"
14894 "void main(){\n"
14895 " x = vec4(1);\n"
14896 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014897
14898 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14899 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14900
14901 VkPipelineObj pipe(m_device);
14902 pipe.AddShader(&vs);
14903 pipe.AddShader(&fs);
14904
14905 /* set up CB 0; type is UNORM by default */
14906 pipe.AddColorAttachment();
14907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14908
14909 VkDescriptorSetObj descriptorSet(m_device);
14910 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14911
14912 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14913
14914 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014915 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014916}
14917
Chris Forbes3fb17902016-08-22 14:57:55 +120014918TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014919 TEST_DESCRIPTION(
14920 "Test that an error is produced for a shader consuming an input attachment "
14921 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14923 "consumes input attachment index 0 but not provided in subpass");
14924
14925 ASSERT_NO_FATAL_FAILURE(InitState());
14926
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014927 char const *vsSource =
14928 "#version 450\n"
14929 "\n"
14930 "out gl_PerVertex {\n"
14931 " vec4 gl_Position;\n"
14932 "};\n"
14933 "void main(){\n"
14934 " gl_Position = vec4(1);\n"
14935 "}\n";
14936 char const *fsSource =
14937 "#version 450\n"
14938 "\n"
14939 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14940 "layout(location=0) out vec4 color;\n"
14941 "void main() {\n"
14942 " color = subpassLoad(x);\n"
14943 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014944
14945 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14946 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14947
14948 VkPipelineObj pipe(m_device);
14949 pipe.AddShader(&vs);
14950 pipe.AddShader(&fs);
14951 pipe.AddColorAttachment();
14952 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14953
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014954 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14955 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014956 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014957 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014958 ASSERT_VK_SUCCESS(err);
14959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014960 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014961 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014962 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014963 ASSERT_VK_SUCCESS(err);
14964
14965 // error here.
14966 pipe.CreateVKPipeline(pl, renderPass());
14967
14968 m_errorMonitor->VerifyFound();
14969
14970 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14971 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14972}
14973
Chris Forbes5a9a0472016-08-22 16:02:09 +120014974TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014975 TEST_DESCRIPTION(
14976 "Test that an error is produced for a shader consuming an input attachment "
14977 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14979 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14980
14981 ASSERT_NO_FATAL_FAILURE(InitState());
14982
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014983 char const *vsSource =
14984 "#version 450\n"
14985 "\n"
14986 "out gl_PerVertex {\n"
14987 " vec4 gl_Position;\n"
14988 "};\n"
14989 "void main(){\n"
14990 " gl_Position = vec4(1);\n"
14991 "}\n";
14992 char const *fsSource =
14993 "#version 450\n"
14994 "\n"
14995 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14996 "layout(location=0) out vec4 color;\n"
14997 "void main() {\n"
14998 " color = subpassLoad(x);\n"
14999 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015000
15001 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15002 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15003
15004 VkPipelineObj pipe(m_device);
15005 pipe.AddShader(&vs);
15006 pipe.AddShader(&fs);
15007 pipe.AddColorAttachment();
15008 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015010 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15011 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015012 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015013 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015014 ASSERT_VK_SUCCESS(err);
15015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015017 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015018 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015019 ASSERT_VK_SUCCESS(err);
15020
15021 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015022 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15023 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15024 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15025 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15026 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 +120015027 };
15028 VkAttachmentReference color = {
15029 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15030 };
15031 VkAttachmentReference input = {
15032 1, VK_IMAGE_LAYOUT_GENERAL,
15033 };
15034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015035 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015037 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015038 VkRenderPass rp;
15039 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15040 ASSERT_VK_SUCCESS(err);
15041
15042 // error here.
15043 pipe.CreateVKPipeline(pl, rp);
15044
15045 m_errorMonitor->VerifyFound();
15046
15047 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15048 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15049 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15050}
15051
Chris Forbes541f7b02016-08-22 15:30:27 +120015052TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015053 TEST_DESCRIPTION(
15054 "Test that an error is produced for a shader consuming an input attachment "
15055 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015057 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015058
15059 ASSERT_NO_FATAL_FAILURE(InitState());
15060
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015061 char const *vsSource =
15062 "#version 450\n"
15063 "\n"
15064 "out gl_PerVertex {\n"
15065 " vec4 gl_Position;\n"
15066 "};\n"
15067 "void main(){\n"
15068 " gl_Position = vec4(1);\n"
15069 "}\n";
15070 char const *fsSource =
15071 "#version 450\n"
15072 "\n"
15073 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15074 "layout(location=0) out vec4 color;\n"
15075 "void main() {\n"
15076 " color = subpassLoad(xs[0]);\n"
15077 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015078
15079 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15080 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15081
15082 VkPipelineObj pipe(m_device);
15083 pipe.AddShader(&vs);
15084 pipe.AddShader(&fs);
15085 pipe.AddColorAttachment();
15086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015088 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15089 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015090 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015091 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015092 ASSERT_VK_SUCCESS(err);
15093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015094 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015095 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015096 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015097 ASSERT_VK_SUCCESS(err);
15098
15099 // error here.
15100 pipe.CreateVKPipeline(pl, renderPass());
15101
15102 m_errorMonitor->VerifyFound();
15103
15104 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15105 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15106}
15107
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015108TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015109 TEST_DESCRIPTION(
15110 "Test that an error is produced for a compute pipeline consuming a "
15111 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015113
15114 ASSERT_NO_FATAL_FAILURE(InitState());
15115
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015116 char const *csSource =
15117 "#version 450\n"
15118 "\n"
15119 "layout(local_size_x=1) in;\n"
15120 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15121 "void main(){\n"
15122 " x = vec4(1);\n"
15123 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015124
15125 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15126
15127 VkDescriptorSetObj descriptorSet(m_device);
15128 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015130 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15131 nullptr,
15132 0,
15133 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15134 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15135 descriptorSet.GetPipelineLayout(),
15136 VK_NULL_HANDLE,
15137 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015138
15139 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015140 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015141
15142 m_errorMonitor->VerifyFound();
15143
15144 if (err == VK_SUCCESS) {
15145 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15146 }
15147}
15148
Chris Forbes22a9b092016-07-19 14:34:05 +120015149TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015150 TEST_DESCRIPTION(
15151 "Test that an error is produced for a pipeline consuming a "
15152 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15154 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015155
15156 ASSERT_NO_FATAL_FAILURE(InitState());
15157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015158 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15159 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015160 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015161 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015162 ASSERT_VK_SUCCESS(err);
15163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015164 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015165 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015166 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015167 ASSERT_VK_SUCCESS(err);
15168
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015169 char const *csSource =
15170 "#version 450\n"
15171 "\n"
15172 "layout(local_size_x=1) in;\n"
15173 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15174 "void main() {\n"
15175 " x.x = 1.0f;\n"
15176 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015177 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015179 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15180 nullptr,
15181 0,
15182 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15183 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15184 pl,
15185 VK_NULL_HANDLE,
15186 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015187
15188 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015189 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015190
15191 m_errorMonitor->VerifyFound();
15192
15193 if (err == VK_SUCCESS) {
15194 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15195 }
15196
15197 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15198 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15199}
15200
Chris Forbes50020592016-07-27 13:52:41 +120015201TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015202 TEST_DESCRIPTION(
15203 "Test that an error is produced when an image view type "
15204 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015206 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 +120015207
15208 ASSERT_NO_FATAL_FAILURE(InitState());
15209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15210
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015211 char const *vsSource =
15212 "#version 450\n"
15213 "\n"
15214 "out gl_PerVertex { vec4 gl_Position; };\n"
15215 "void main() { gl_Position = vec4(0); }\n";
15216 char const *fsSource =
15217 "#version 450\n"
15218 "\n"
15219 "layout(set=0, binding=0) uniform sampler3D s;\n"
15220 "layout(location=0) out vec4 color;\n"
15221 "void main() {\n"
15222 " color = texture(s, vec3(0));\n"
15223 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015224 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15225 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15226
15227 VkPipelineObj pipe(m_device);
15228 pipe.AddShader(&vs);
15229 pipe.AddShader(&fs);
15230 pipe.AddColorAttachment();
15231
15232 VkTextureObj texture(m_device, nullptr);
15233 VkSamplerObj sampler(m_device);
15234
15235 VkDescriptorSetObj descriptorSet(m_device);
15236 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15237 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15238
15239 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15240 ASSERT_VK_SUCCESS(err);
15241
Tony Barbour552f6c02016-12-21 14:34:07 -070015242 m_commandBuffer->BeginCommandBuffer();
15243 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015244
15245 m_commandBuffer->BindPipeline(pipe);
15246 m_commandBuffer->BindDescriptorSet(descriptorSet);
15247
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015248 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015249 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015250 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015251 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15252
15253 // error produced here.
15254 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15255
15256 m_errorMonitor->VerifyFound();
15257
Tony Barbour552f6c02016-12-21 14:34:07 -070015258 m_commandBuffer->EndRenderPass();
15259 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015260}
15261
Chris Forbes5533bfc2016-07-27 14:12:34 +120015262TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015263 TEST_DESCRIPTION(
15264 "Test that an error is produced when a multisampled images "
15265 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015268
15269 ASSERT_NO_FATAL_FAILURE(InitState());
15270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15271
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015272 char const *vsSource =
15273 "#version 450\n"
15274 "\n"
15275 "out gl_PerVertex { vec4 gl_Position; };\n"
15276 "void main() { gl_Position = vec4(0); }\n";
15277 char const *fsSource =
15278 "#version 450\n"
15279 "\n"
15280 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15281 "layout(location=0) out vec4 color;\n"
15282 "void main() {\n"
15283 " color = texelFetch(s, ivec2(0), 0);\n"
15284 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015285 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15286 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15287
15288 VkPipelineObj pipe(m_device);
15289 pipe.AddShader(&vs);
15290 pipe.AddShader(&fs);
15291 pipe.AddColorAttachment();
15292
15293 VkTextureObj texture(m_device, nullptr);
15294 VkSamplerObj sampler(m_device);
15295
15296 VkDescriptorSetObj descriptorSet(m_device);
15297 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15299
15300 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15301 ASSERT_VK_SUCCESS(err);
15302
Tony Barbour552f6c02016-12-21 14:34:07 -070015303 m_commandBuffer->BeginCommandBuffer();
15304 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015305
15306 m_commandBuffer->BindPipeline(pipe);
15307 m_commandBuffer->BindDescriptorSet(descriptorSet);
15308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015309 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015310 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015311 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015312 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15313
15314 // error produced here.
15315 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15316
15317 m_errorMonitor->VerifyFound();
15318
Tony Barbour552f6c02016-12-21 14:34:07 -070015319 m_commandBuffer->EndRenderPass();
15320 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015321}
15322
Mark Youngc48c4c12016-04-11 14:26:49 -060015323TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015325
15326 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015327
15328 // Create an image
15329 VkImage image;
15330
Karl Schultz6addd812016-02-02 17:17:23 -070015331 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15332 const int32_t tex_width = 32;
15333 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015334
15335 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015336 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15337 image_create_info.pNext = NULL;
15338 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15339 image_create_info.format = tex_format;
15340 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015341 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015342 image_create_info.extent.depth = 1;
15343 image_create_info.mipLevels = 1;
15344 image_create_info.arrayLayers = 1;
15345 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15346 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15347 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15348 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015349
15350 // Introduce error by sending down a bogus width extent
15351 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015352 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015353
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015354 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015355}
15356
Mark Youngc48c4c12016-04-11 14:26:49 -060015357TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015359
15360 ASSERT_NO_FATAL_FAILURE(InitState());
15361
15362 // Create an image
15363 VkImage image;
15364
15365 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15366 const int32_t tex_width = 32;
15367 const int32_t tex_height = 32;
15368
15369 VkImageCreateInfo image_create_info = {};
15370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15371 image_create_info.pNext = NULL;
15372 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15373 image_create_info.format = tex_format;
15374 image_create_info.extent.width = tex_width;
15375 image_create_info.extent.height = tex_height;
15376 image_create_info.extent.depth = 1;
15377 image_create_info.mipLevels = 1;
15378 image_create_info.arrayLayers = 1;
15379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15380 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15381 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15382 image_create_info.flags = 0;
15383
15384 // Introduce error by sending down a bogus width extent
15385 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015386 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015387 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15388
15389 m_errorMonitor->VerifyFound();
15390}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015391
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015392TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015393 TEST_DESCRIPTION(
15394 "Create a render pass with an attachment description "
15395 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015396
15397 ASSERT_NO_FATAL_FAILURE(InitState());
15398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15399
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015401
15402 VkAttachmentReference color_attach = {};
15403 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15404 color_attach.attachment = 0;
15405 VkSubpassDescription subpass = {};
15406 subpass.colorAttachmentCount = 1;
15407 subpass.pColorAttachments = &color_attach;
15408
15409 VkRenderPassCreateInfo rpci = {};
15410 rpci.subpassCount = 1;
15411 rpci.pSubpasses = &subpass;
15412 rpci.attachmentCount = 1;
15413 VkAttachmentDescription attach_desc = {};
15414 attach_desc.format = VK_FORMAT_UNDEFINED;
15415 rpci.pAttachments = &attach_desc;
15416 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15417 VkRenderPass rp;
15418 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15419
15420 m_errorMonitor->VerifyFound();
15421
15422 if (result == VK_SUCCESS) {
15423 vkDestroyRenderPass(m_device->device(), rp, NULL);
15424 }
15425}
15426
Karl Schultz6addd812016-02-02 17:17:23 -070015427TEST_F(VkLayerTest, InvalidImageView) {
15428 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015429
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015431
Tobin Ehliscde08892015-09-22 10:11:37 -060015432 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015433
Mike Stroyana3082432015-09-25 13:39:21 -060015434 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015435 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015436
Karl Schultz6addd812016-02-02 17:17:23 -070015437 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15438 const int32_t tex_width = 32;
15439 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015440
15441 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015442 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15443 image_create_info.pNext = NULL;
15444 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15445 image_create_info.format = tex_format;
15446 image_create_info.extent.width = tex_width;
15447 image_create_info.extent.height = tex_height;
15448 image_create_info.extent.depth = 1;
15449 image_create_info.mipLevels = 1;
15450 image_create_info.arrayLayers = 1;
15451 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15452 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15453 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15454 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015455
Chia-I Wuf7458c52015-10-26 21:10:41 +080015456 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015457 ASSERT_VK_SUCCESS(err);
15458
15459 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015460 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015461 image_view_create_info.image = image;
15462 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15463 image_view_create_info.format = tex_format;
15464 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015465 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015466 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015467 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015468
15469 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015470 m_errorMonitor->SetUnexpectedError(
15471 "If image is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015472 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015473
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015474 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015475 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015476}
Mike Stroyana3082432015-09-25 13:39:21 -060015477
Mark Youngd339ba32016-05-30 13:28:35 -060015478TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15479 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015481 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015482
15483 ASSERT_NO_FATAL_FAILURE(InitState());
15484
15485 // Create an image and try to create a view with no memory backing the image
15486 VkImage image;
15487
15488 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15489 const int32_t tex_width = 32;
15490 const int32_t tex_height = 32;
15491
15492 VkImageCreateInfo image_create_info = {};
15493 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15494 image_create_info.pNext = NULL;
15495 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15496 image_create_info.format = tex_format;
15497 image_create_info.extent.width = tex_width;
15498 image_create_info.extent.height = tex_height;
15499 image_create_info.extent.depth = 1;
15500 image_create_info.mipLevels = 1;
15501 image_create_info.arrayLayers = 1;
15502 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15503 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15504 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15505 image_create_info.flags = 0;
15506
15507 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15508 ASSERT_VK_SUCCESS(err);
15509
15510 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015511 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015512 image_view_create_info.image = image;
15513 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15514 image_view_create_info.format = tex_format;
15515 image_view_create_info.subresourceRange.layerCount = 1;
15516 image_view_create_info.subresourceRange.baseMipLevel = 0;
15517 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015518 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015519
15520 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015521 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015522
15523 m_errorMonitor->VerifyFound();
15524 vkDestroyImage(m_device->device(), image, NULL);
15525 // If last error is success, it still created the view, so delete it.
15526 if (err == VK_SUCCESS) {
15527 vkDestroyImageView(m_device->device(), view, NULL);
15528 }
Mark Youngd339ba32016-05-30 13:28:35 -060015529}
15530
Karl Schultz6addd812016-02-02 17:17:23 -070015531TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015532 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015534
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015535 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015536
Karl Schultz6addd812016-02-02 17:17:23 -070015537 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015538 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015539 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015540 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015541
15542 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015543 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015544 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015545 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15546 image_view_create_info.format = tex_format;
15547 image_view_create_info.subresourceRange.baseMipLevel = 0;
15548 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015549 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015550 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015551 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015552
15553 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015554 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015555
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015556 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015557}
15558
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015559TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015560 VkResult err;
15561 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015562
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015564
Mike Stroyana3082432015-09-25 13:39:21 -060015565 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015566
15567 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015568 VkImage srcImage;
15569 VkImage dstImage;
15570 VkDeviceMemory srcMem;
15571 VkDeviceMemory destMem;
15572 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015573
15574 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015575 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15576 image_create_info.pNext = NULL;
15577 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15578 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15579 image_create_info.extent.width = 32;
15580 image_create_info.extent.height = 32;
15581 image_create_info.extent.depth = 1;
15582 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015583 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015584 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15585 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15586 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15587 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015589 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015590 ASSERT_VK_SUCCESS(err);
15591
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015592 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015593 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015594 ASSERT_VK_SUCCESS(err);
15595
15596 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015597 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015598 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15599 memAlloc.pNext = NULL;
15600 memAlloc.allocationSize = 0;
15601 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015602
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015603 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015604 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015605 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015606 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015607 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015608 ASSERT_VK_SUCCESS(err);
15609
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015610 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015611 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015612 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015613 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015614 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015615 ASSERT_VK_SUCCESS(err);
15616
15617 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15618 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015619 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015620 ASSERT_VK_SUCCESS(err);
15621
Tony Barbour552f6c02016-12-21 14:34:07 -070015622 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015623 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015624 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015625 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015626 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015627 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015628 copyRegion.srcOffset.x = 0;
15629 copyRegion.srcOffset.y = 0;
15630 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015631 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015632 copyRegion.dstSubresource.mipLevel = 0;
15633 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015634 // Introduce failure by forcing the dst layerCount to differ from src
15635 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015636 copyRegion.dstOffset.x = 0;
15637 copyRegion.dstOffset.y = 0;
15638 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015639 copyRegion.extent.width = 1;
15640 copyRegion.extent.height = 1;
15641 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015642 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015643 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015644
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015645 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015646
Chia-I Wuf7458c52015-10-26 21:10:41 +080015647 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015648 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015649 vkFreeMemory(m_device->device(), srcMem, NULL);
15650 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015651}
15652
Tony Barbourd6673642016-05-05 14:46:39 -060015653TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015654 TEST_DESCRIPTION("Creating images with unsuported formats ");
15655
15656 ASSERT_NO_FATAL_FAILURE(InitState());
15657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15658 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015659 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 -060015660 VK_IMAGE_TILING_OPTIMAL, 0);
15661 ASSERT_TRUE(image.initialized());
15662
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015663 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015664 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015665 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15667 image_create_info.format = VK_FORMAT_UNDEFINED;
15668 image_create_info.extent.width = 32;
15669 image_create_info.extent.height = 32;
15670 image_create_info.extent.depth = 1;
15671 image_create_info.mipLevels = 1;
15672 image_create_info.arrayLayers = 1;
15673 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15674 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15675 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015676
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15678 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015679
15680 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015681 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15682 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15683 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15684 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015685 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15686 m_errorMonitor->VerifyFound();
15687
Tony Barbourd6673642016-05-05 14:46:39 -060015688 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015689 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015690 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15691 VkFormat format = static_cast<VkFormat>(f);
15692 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015693 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015694 unsupported = format;
15695 break;
15696 }
15697 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015698
Tony Barbourd6673642016-05-05 14:46:39 -060015699 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015700 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015702
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015703 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15704 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15705 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15706 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15707 m_errorMonitor->SetUnexpectedError(
15708 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15709 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15710 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015711 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015712 m_errorMonitor->VerifyFound();
15713 }
15714}
15715
15716TEST_F(VkLayerTest, ImageLayerViewTests) {
15717 VkResult ret;
15718 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15719
15720 ASSERT_NO_FATAL_FAILURE(InitState());
15721
15722 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015723 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 -060015724 VK_IMAGE_TILING_OPTIMAL, 0);
15725 ASSERT_TRUE(image.initialized());
15726
15727 VkImageView imgView;
15728 VkImageViewCreateInfo imgViewInfo = {};
15729 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15730 imgViewInfo.image = image.handle();
15731 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15732 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15733 imgViewInfo.subresourceRange.layerCount = 1;
15734 imgViewInfo.subresourceRange.baseMipLevel = 0;
15735 imgViewInfo.subresourceRange.levelCount = 1;
15736 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15737
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015739 // View can't have baseMipLevel >= image's mipLevels - Expect
15740 // VIEW_CREATE_ERROR
15741 imgViewInfo.subresourceRange.baseMipLevel = 1;
15742 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15743 m_errorMonitor->VerifyFound();
15744 imgViewInfo.subresourceRange.baseMipLevel = 0;
15745
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015747 // View can't have baseArrayLayer >= image's arraySize - Expect
15748 // VIEW_CREATE_ERROR
15749 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15750 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15751 m_errorMonitor->VerifyFound();
15752 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15753
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015755 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15756 imgViewInfo.subresourceRange.levelCount = 0;
15757 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15758 m_errorMonitor->VerifyFound();
15759 imgViewInfo.subresourceRange.levelCount = 1;
15760
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015761 m_errorMonitor->SetDesiredFailureMsg(
15762 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15763 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015764 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15765 imgViewInfo.subresourceRange.layerCount = 0;
15766 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15767 m_errorMonitor->VerifyFound();
15768 imgViewInfo.subresourceRange.layerCount = 1;
15769
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15771 "Formats MUST be IDENTICAL unless "
15772 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15773 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015774 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15775 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15776 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15777 m_errorMonitor->VerifyFound();
15778 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15779
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015781 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15782 // VIEW_CREATE_ERROR
15783 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15784 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15785 m_errorMonitor->VerifyFound();
15786 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15787
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015789 // TODO: Update framework to easily passing mutable flag into ImageObj init
15790 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015791 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15792 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15793 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015794 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15795 // VIEW_CREATE_ERROR
15796 VkImageCreateInfo mutImgInfo = image.create_info();
15797 VkImage mutImage;
15798 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015799 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015800 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15801 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15802 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15803 ASSERT_VK_SUCCESS(ret);
15804 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015805 m_errorMonitor->SetUnexpectedError(
15806 "If image is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Tony Barbourd6673642016-05-05 14:46:39 -060015807 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15808 m_errorMonitor->VerifyFound();
15809 imgViewInfo.image = image.handle();
15810 vkDestroyImage(m_device->handle(), mutImage, NULL);
15811}
15812
Dave Houlton59a20702017-02-02 17:26:23 -070015813TEST_F(VkLayerTest, ImageBufferCopyTests) {
15814 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
15815
15816 ASSERT_NO_FATAL_FAILURE(InitState());
15817 VkImageObj image_64k(m_device); // 128^2 texels, 64k
15818 VkImageObj image_16k(m_device); // 64^2 texels, 16k
15819 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
15820 VkImageObj image_16k_bc5(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
15821 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
15822 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15823 VK_IMAGE_TILING_OPTIMAL, 0);
15824 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
15825 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15826 VK_IMAGE_TILING_OPTIMAL, 0);
15827 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15828 VK_IMAGE_TILING_OPTIMAL, 0);
15829 image_16k_bc5.init(32, 32, VK_FORMAT_BC5_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15830 ASSERT_TRUE(image_64k.initialized());
15831 ASSERT_TRUE(image_16k.initialized());
15832 ASSERT_TRUE(image_16k_depth.initialized());
15833 ASSERT_TRUE(image_16k_bc5.initialized());
15834
15835 vk_testing::Buffer buffer_64k, buffer_16k;
15836 VkMemoryPropertyFlags reqs = 0;
15837 buffer_64k.init_as_src_and_dst(*m_device, 128 * 128 * 4, reqs); // 64k
15838 buffer_16k.init_as_src_and_dst(*m_device, 64 * 64 * 4, reqs); // 16k
15839
15840 VkBufferImageCopy region = {};
15841 region.bufferRowLength = 0;
15842 region.bufferImageHeight = 0;
15843 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15844 region.imageSubresource.layerCount = 1;
15845 region.imageOffset = {0, 0, 0};
15846 region.imageExtent = {64, 64, 1};
15847 region.bufferOffset = 0;
15848
15849 // attempt copies before putting command buffer in recording state
15850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
15851 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15852 &region);
15853 m_errorMonitor->VerifyFound();
15854
15855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
15856 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
15857 &region);
15858 m_errorMonitor->VerifyFound();
15859
15860 // start recording
15861 m_commandBuffer->BeginCommandBuffer();
15862
15863 // successful copies
15864 m_errorMonitor->ExpectSuccess();
15865 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15866 &region);
15867 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15868 &region);
15869 region.imageOffset.x = 16; // 16k copy, offset requires larger image
15870 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15871 &region);
15872 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
15873 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15874 &region);
15875 region.imageOffset.x = 0;
15876 region.imageExtent.height = 64;
15877 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
15878 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
15879 &region);
15880 m_errorMonitor->VerifyNotFound();
15881
15882 // image/buffer too small (extent) on copy to image
15883 region.imageExtent = {65, 64, 1};
15884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
15885 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15886 &region);
15887 m_errorMonitor->VerifyFound();
15888
15889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
15890 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15891 &region);
15892 m_errorMonitor->VerifyFound();
15893
15894 // image/buffer too small (offset) on copy to image
15895 region.imageExtent = {64, 64, 1};
15896 region.imageOffset = {0, 4, 0};
15897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
15898 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15899 &region);
15900 m_errorMonitor->VerifyFound();
15901
15902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
15903 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15904 &region);
15905 m_errorMonitor->VerifyFound();
15906
15907 // image/buffer too small on copy to buffer
15908 region.imageExtent = {64, 64, 1};
15909 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070015910 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070015911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
15912 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15913 &region);
15914 m_errorMonitor->VerifyFound();
15915
15916 region.imageExtent = {64, 65, 1};
15917 region.bufferOffset = 0;
15918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
15919 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
15920 &region);
15921 m_errorMonitor->VerifyFound();
15922
15923 // buffer size ok but rowlength causes loose packing
15924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
15925 region.imageExtent = {64, 64, 1};
15926 region.bufferRowLength = 68;
15927 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15928 &region);
15929 m_errorMonitor->VerifyFound();
15930
Dave Houlton59a20702017-02-02 17:26:23 -070015931 // aspect bits
15932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
15933 region.imageExtent = {64, 64, 1};
15934 region.bufferRowLength = 0;
15935 region.bufferImageHeight = 0;
15936 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15937 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
15938 buffer_16k.handle(), 1, &region);
15939 m_errorMonitor->VerifyFound();
15940
15941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
15942 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
15943 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15944 &region);
15945 m_errorMonitor->VerifyFound();
15946
15947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
15948 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15949 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
15950 buffer_16k.handle(), 1, &region);
15951 m_errorMonitor->VerifyFound();
15952
15953 // copying compressed formats
15954
15955 // Just fits
15956 m_errorMonitor->ExpectSuccess();
15957 region.imageExtent = {128, 128, 1};
15958 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(),
15959 1, &region);
15960 m_errorMonitor->VerifyNotFound();
15961
15962 // with offset, too big for buffer
15963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
15964 region.bufferOffset = 16;
15965 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(),
15966 1, &region);
15967 m_errorMonitor->VerifyFound();
15968
15969 // buffer offset must be a multiple of texel block size (16)
15970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
15971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
15972 region.imageExtent = {64, 64, 1};
15973 region.bufferOffset = 24;
15974 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(),
15975 1, &region);
15976 m_errorMonitor->VerifyFound();
15977
15978 // rowlength not a multiple of block width (4)
15979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
15980 region.bufferOffset = 0;
15981 region.bufferRowLength = 130;
15982 region.bufferImageHeight = 0;
15983 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(),
15984 1, &region);
15985 m_errorMonitor->VerifyFound();
15986
15987 // imageheight not a multiple of block height (4)
15988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
15989 region.bufferRowLength = 0;
15990 region.bufferImageHeight = 130;
15991 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(),
15992 1, &region);
15993 m_errorMonitor->VerifyFound();
15994
15995 // image extents must be multiple of block dimensions (4x4)
15996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
15997 region.bufferImageHeight = 0;
15998 region.imageOffset = {4, 6, 0};
15999 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(),
16000 1, &region);
16001 m_errorMonitor->VerifyFound();
16002
16003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16004 region.imageOffset = {22, 0, 0};
16005 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(),
16006 1, &region);
16007 m_errorMonitor->VerifyFound();
16008}
16009
Tony Barbourd6673642016-05-05 14:46:39 -060016010TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016011 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
16012
16013 ASSERT_NO_FATAL_FAILURE(InitState());
16014
Rene Lindsay135204f2016-12-22 17:11:09 -070016015 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016016 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016017 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 -070016018 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016019 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016020 vk_testing::Buffer buffer;
16021 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016022 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016023 VkBufferImageCopy region = {};
16024 region.bufferRowLength = 128;
16025 region.bufferImageHeight = 128;
16026 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16027 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016028 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016029 region.imageExtent.height = 4;
16030 region.imageExtent.width = 4;
16031 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016032
16033 VkImageObj image2(m_device);
16034 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 -070016035 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016036 ASSERT_TRUE(image2.initialized());
16037 vk_testing::Buffer buffer2;
16038 VkMemoryPropertyFlags reqs2 = 0;
16039 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16040 VkBufferImageCopy region2 = {};
16041 region2.bufferRowLength = 128;
16042 region2.bufferImageHeight = 128;
16043 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16044 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16045 region2.imageSubresource.layerCount = 1;
16046 region2.imageExtent.height = 4;
16047 region2.imageExtent.width = 4;
16048 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016049 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016050
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016051 // Image must have offset.z of 0 and extent.depth of 1
16052 // Introduce failure by setting imageExtent.depth to 0
16053 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016055 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016056 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016057 m_errorMonitor->VerifyFound();
16058
16059 region.imageExtent.depth = 1;
16060
16061 // Image must have offset.z of 0 and extent.depth of 1
16062 // Introduce failure by setting imageOffset.z to 4
16063 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016065 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016066 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016067 m_errorMonitor->VerifyFound();
16068
16069 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016070 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16071 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016072 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016074 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16075 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016076 m_errorMonitor->VerifyFound();
16077
16078 // BufferOffset must be a multiple of 4
16079 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016080 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016082 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16083 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016084 m_errorMonitor->VerifyFound();
16085
16086 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16087 region.bufferOffset = 0;
16088 region.imageExtent.height = 128;
16089 region.imageExtent.width = 128;
16090 // Introduce failure by setting bufferRowLength > 0 but less than width
16091 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016093 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16094 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016095 m_errorMonitor->VerifyFound();
16096
16097 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16098 region.bufferRowLength = 128;
16099 // Introduce failure by setting bufferRowHeight > 0 but less than height
16100 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016102 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16103 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016104 m_errorMonitor->VerifyFound();
16105
16106 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016107 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016108 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16109 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016110 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016111 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16112 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016113 VkImageBlit blitRegion = {};
16114 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16115 blitRegion.srcSubresource.baseArrayLayer = 0;
16116 blitRegion.srcSubresource.layerCount = 1;
16117 blitRegion.srcSubresource.mipLevel = 0;
16118 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16119 blitRegion.dstSubresource.baseArrayLayer = 0;
16120 blitRegion.dstSubresource.layerCount = 1;
16121 blitRegion.dstSubresource.mipLevel = 0;
16122
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016123 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016125 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016126 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16127 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016128 m_errorMonitor->VerifyFound();
16129
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016131 VkImageMemoryBarrier img_barrier;
16132 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16133 img_barrier.pNext = NULL;
16134 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16135 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16136 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16137 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16138 img_barrier.image = image.handle();
16139 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16140 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16141 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16142 img_barrier.subresourceRange.baseArrayLayer = 0;
16143 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016144 img_barrier.subresourceRange.layerCount = 0;
16145 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016146 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16147 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016148 m_errorMonitor->VerifyFound();
16149 img_barrier.subresourceRange.layerCount = 1;
16150}
16151
16152TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016153 TEST_DESCRIPTION("Exceed the limits of image format ");
16154
Cody Northropc31a84f2016-08-22 10:41:47 -060016155 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016157 VkImageCreateInfo image_create_info = {};
16158 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16159 image_create_info.pNext = NULL;
16160 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16161 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16162 image_create_info.extent.width = 32;
16163 image_create_info.extent.height = 32;
16164 image_create_info.extent.depth = 1;
16165 image_create_info.mipLevels = 1;
16166 image_create_info.arrayLayers = 1;
16167 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16168 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16169 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16170 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16171 image_create_info.flags = 0;
16172
16173 VkImage nullImg;
16174 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016175 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16176 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016177 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016178 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16179 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16180 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016181 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016184 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16185 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16186 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16187 m_errorMonitor->VerifyFound();
16188 image_create_info.mipLevels = 1;
16189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016191 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16192 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16193 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16194 m_errorMonitor->VerifyFound();
16195 image_create_info.arrayLayers = 1;
16196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016198 int samples = imgFmtProps.sampleCounts >> 1;
16199 image_create_info.samples = (VkSampleCountFlagBits)samples;
16200 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16201 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16202 m_errorMonitor->VerifyFound();
16203 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16204
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16206 "pCreateInfo->initialLayout, must be "
16207 "VK_IMAGE_LAYOUT_UNDEFINED or "
16208 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016209 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16210 // Expect INVALID_LAYOUT
16211 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16212 m_errorMonitor->VerifyFound();
16213 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16214}
16215
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016216TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016217 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016219
16220 ASSERT_NO_FATAL_FAILURE(InitState());
16221
16222 VkImageObj src_image(m_device);
16223 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16224 VkImageObj dst_image(m_device);
16225 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16226
Tony Barbour552f6c02016-12-21 14:34:07 -070016227 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016228 VkImageCopy copy_region;
16229 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16230 copy_region.srcSubresource.mipLevel = 0;
16231 copy_region.srcSubresource.baseArrayLayer = 0;
16232 copy_region.srcSubresource.layerCount = 0;
16233 copy_region.srcOffset.x = 0;
16234 copy_region.srcOffset.y = 0;
16235 copy_region.srcOffset.z = 0;
16236 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16237 copy_region.dstSubresource.mipLevel = 0;
16238 copy_region.dstSubresource.baseArrayLayer = 0;
16239 copy_region.dstSubresource.layerCount = 0;
16240 copy_region.dstOffset.x = 0;
16241 copy_region.dstOffset.y = 0;
16242 copy_region.dstOffset.z = 0;
16243 copy_region.extent.width = 64;
16244 copy_region.extent.height = 64;
16245 copy_region.extent.depth = 1;
16246 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16247 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016248 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016249
16250 m_errorMonitor->VerifyFound();
16251}
16252
16253TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016254 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016256
16257 ASSERT_NO_FATAL_FAILURE(InitState());
16258
16259 VkImageObj src_image(m_device);
16260 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16261 VkImageObj dst_image(m_device);
16262 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16263
Tony Barbour552f6c02016-12-21 14:34:07 -070016264 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016265 VkImageCopy copy_region;
16266 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16267 copy_region.srcSubresource.mipLevel = 0;
16268 copy_region.srcSubresource.baseArrayLayer = 0;
16269 copy_region.srcSubresource.layerCount = 0;
16270 copy_region.srcOffset.x = 0;
16271 copy_region.srcOffset.y = 0;
16272 copy_region.srcOffset.z = 0;
16273 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16274 copy_region.dstSubresource.mipLevel = 0;
16275 copy_region.dstSubresource.baseArrayLayer = 0;
16276 copy_region.dstSubresource.layerCount = 0;
16277 copy_region.dstOffset.x = 0;
16278 copy_region.dstOffset.y = 0;
16279 copy_region.dstOffset.z = 0;
16280 copy_region.extent.width = 64;
16281 copy_region.extent.height = 64;
16282 copy_region.extent.depth = 1;
16283 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16284 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016285 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016286
16287 m_errorMonitor->VerifyFound();
16288}
16289
Karl Schultz6addd812016-02-02 17:17:23 -070016290TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016291 VkResult err;
16292 bool pass;
16293
16294 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016296
16297 ASSERT_NO_FATAL_FAILURE(InitState());
16298
16299 // Create two images of different types and try to copy between them
16300 VkImage srcImage;
16301 VkImage dstImage;
16302 VkDeviceMemory srcMem;
16303 VkDeviceMemory destMem;
16304 VkMemoryRequirements memReqs;
16305
16306 VkImageCreateInfo image_create_info = {};
16307 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16308 image_create_info.pNext = NULL;
16309 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16310 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16311 image_create_info.extent.width = 32;
16312 image_create_info.extent.height = 32;
16313 image_create_info.extent.depth = 1;
16314 image_create_info.mipLevels = 1;
16315 image_create_info.arrayLayers = 1;
16316 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16317 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16318 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16319 image_create_info.flags = 0;
16320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016321 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016322 ASSERT_VK_SUCCESS(err);
16323
16324 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16325 // Introduce failure by creating second image with a different-sized format.
16326 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016328 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016329 ASSERT_VK_SUCCESS(err);
16330
16331 // Allocate memory
16332 VkMemoryAllocateInfo memAlloc = {};
16333 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16334 memAlloc.pNext = NULL;
16335 memAlloc.allocationSize = 0;
16336 memAlloc.memoryTypeIndex = 0;
16337
16338 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16339 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016340 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016341 ASSERT_TRUE(pass);
16342 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16343 ASSERT_VK_SUCCESS(err);
16344
16345 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16346 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016347 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016348 ASSERT_TRUE(pass);
16349 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16350 ASSERT_VK_SUCCESS(err);
16351
16352 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16353 ASSERT_VK_SUCCESS(err);
16354 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16355 ASSERT_VK_SUCCESS(err);
16356
Tony Barbour552f6c02016-12-21 14:34:07 -070016357 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016358 VkImageCopy copyRegion;
16359 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16360 copyRegion.srcSubresource.mipLevel = 0;
16361 copyRegion.srcSubresource.baseArrayLayer = 0;
16362 copyRegion.srcSubresource.layerCount = 0;
16363 copyRegion.srcOffset.x = 0;
16364 copyRegion.srcOffset.y = 0;
16365 copyRegion.srcOffset.z = 0;
16366 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16367 copyRegion.dstSubresource.mipLevel = 0;
16368 copyRegion.dstSubresource.baseArrayLayer = 0;
16369 copyRegion.dstSubresource.layerCount = 0;
16370 copyRegion.dstOffset.x = 0;
16371 copyRegion.dstOffset.y = 0;
16372 copyRegion.dstOffset.z = 0;
16373 copyRegion.extent.width = 1;
16374 copyRegion.extent.height = 1;
16375 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016376 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016377 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016378
16379 m_errorMonitor->VerifyFound();
16380
16381 vkDestroyImage(m_device->device(), srcImage, NULL);
16382 vkDestroyImage(m_device->device(), dstImage, NULL);
16383 vkFreeMemory(m_device->device(), srcMem, NULL);
16384 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016385}
16386
Karl Schultz6addd812016-02-02 17:17:23 -070016387TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16388 VkResult err;
16389 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016390
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016391 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16393 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016394
Mike Stroyana3082432015-09-25 13:39:21 -060016395 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016396
16397 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016398 VkImage srcImage;
16399 VkImage dstImage;
16400 VkDeviceMemory srcMem;
16401 VkDeviceMemory destMem;
16402 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016403
16404 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016405 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16406 image_create_info.pNext = NULL;
16407 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16408 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16409 image_create_info.extent.width = 32;
16410 image_create_info.extent.height = 32;
16411 image_create_info.extent.depth = 1;
16412 image_create_info.mipLevels = 1;
16413 image_create_info.arrayLayers = 1;
16414 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16415 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16416 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16417 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016419 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016420 ASSERT_VK_SUCCESS(err);
16421
Karl Schultzbdb75952016-04-19 11:36:49 -060016422 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16423
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016424 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016425 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016426 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016427 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016429 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016430 ASSERT_VK_SUCCESS(err);
16431
16432 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016433 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016434 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16435 memAlloc.pNext = NULL;
16436 memAlloc.allocationSize = 0;
16437 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016438
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016439 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016440 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016441 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016442 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016443 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016444 ASSERT_VK_SUCCESS(err);
16445
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016446 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016447 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016448 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016449 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016450 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016451 ASSERT_VK_SUCCESS(err);
16452
16453 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16454 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016455 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016456 ASSERT_VK_SUCCESS(err);
16457
Tony Barbour552f6c02016-12-21 14:34:07 -070016458 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016459 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016460 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016461 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016462 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016463 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016464 copyRegion.srcOffset.x = 0;
16465 copyRegion.srcOffset.y = 0;
16466 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016467 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016468 copyRegion.dstSubresource.mipLevel = 0;
16469 copyRegion.dstSubresource.baseArrayLayer = 0;
16470 copyRegion.dstSubresource.layerCount = 0;
16471 copyRegion.dstOffset.x = 0;
16472 copyRegion.dstOffset.y = 0;
16473 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016474 copyRegion.extent.width = 1;
16475 copyRegion.extent.height = 1;
16476 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016477 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016478 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016479
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016480 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016481
Chia-I Wuf7458c52015-10-26 21:10:41 +080016482 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016483 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016484 vkFreeMemory(m_device->device(), srcMem, NULL);
16485 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016486}
16487
Karl Schultz6addd812016-02-02 17:17:23 -070016488TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16489 VkResult err;
16490 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16493 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016494
Mike Stroyana3082432015-09-25 13:39:21 -060016495 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016496
16497 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016498 VkImage srcImage;
16499 VkImage dstImage;
16500 VkDeviceMemory srcMem;
16501 VkDeviceMemory destMem;
16502 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016503
16504 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016505 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16506 image_create_info.pNext = NULL;
16507 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16508 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16509 image_create_info.extent.width = 32;
16510 image_create_info.extent.height = 1;
16511 image_create_info.extent.depth = 1;
16512 image_create_info.mipLevels = 1;
16513 image_create_info.arrayLayers = 1;
16514 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16515 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16516 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16517 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016520 ASSERT_VK_SUCCESS(err);
16521
Karl Schultz6addd812016-02-02 17:17:23 -070016522 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016524 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016525 ASSERT_VK_SUCCESS(err);
16526
16527 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016528 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016529 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16530 memAlloc.pNext = NULL;
16531 memAlloc.allocationSize = 0;
16532 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016533
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016534 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016535 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016536 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016537 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016538 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016539 ASSERT_VK_SUCCESS(err);
16540
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016541 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016542 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016543 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016544 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016545 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016546 ASSERT_VK_SUCCESS(err);
16547
16548 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016550 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016551 ASSERT_VK_SUCCESS(err);
16552
Tony Barbour552f6c02016-12-21 14:34:07 -070016553 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016554 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016555 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16556 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016557 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016558 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016559 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016560 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016561 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016562 resolveRegion.srcOffset.x = 0;
16563 resolveRegion.srcOffset.y = 0;
16564 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016565 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016566 resolveRegion.dstSubresource.mipLevel = 0;
16567 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016568 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016569 resolveRegion.dstOffset.x = 0;
16570 resolveRegion.dstOffset.y = 0;
16571 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016572 resolveRegion.extent.width = 1;
16573 resolveRegion.extent.height = 1;
16574 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016575 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016576 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016577
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016578 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016579
Chia-I Wuf7458c52015-10-26 21:10:41 +080016580 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016581 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016582 vkFreeMemory(m_device->device(), srcMem, NULL);
16583 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016584}
16585
Karl Schultz6addd812016-02-02 17:17:23 -070016586TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16587 VkResult err;
16588 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16591 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016592
Mike Stroyana3082432015-09-25 13:39:21 -060016593 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016594
Chris Forbesa7530692016-05-08 12:35:39 +120016595 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016596 VkImage srcImage;
16597 VkImage dstImage;
16598 VkDeviceMemory srcMem;
16599 VkDeviceMemory destMem;
16600 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016601
16602 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016603 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16604 image_create_info.pNext = NULL;
16605 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16606 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16607 image_create_info.extent.width = 32;
16608 image_create_info.extent.height = 1;
16609 image_create_info.extent.depth = 1;
16610 image_create_info.mipLevels = 1;
16611 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016612 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016613 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16614 // Note: Some implementations expect color attachment usage for any
16615 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016616 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016617 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016619 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016620 ASSERT_VK_SUCCESS(err);
16621
Karl Schultz6addd812016-02-02 17:17:23 -070016622 // Note: Some implementations expect color attachment usage for any
16623 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016624 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016626 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016627 ASSERT_VK_SUCCESS(err);
16628
16629 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016630 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016631 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16632 memAlloc.pNext = NULL;
16633 memAlloc.allocationSize = 0;
16634 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016635
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016636 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016637 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016638 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016639 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016640 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016641 ASSERT_VK_SUCCESS(err);
16642
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016643 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016644 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016645 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016646 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016647 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016648 ASSERT_VK_SUCCESS(err);
16649
16650 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16651 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016652 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016653 ASSERT_VK_SUCCESS(err);
16654
Tony Barbour552f6c02016-12-21 14:34:07 -070016655 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016656 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016657 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16658 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016659 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016660 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016661 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016662 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016663 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016664 resolveRegion.srcOffset.x = 0;
16665 resolveRegion.srcOffset.y = 0;
16666 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016667 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016668 resolveRegion.dstSubresource.mipLevel = 0;
16669 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016670 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016671 resolveRegion.dstOffset.x = 0;
16672 resolveRegion.dstOffset.y = 0;
16673 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016674 resolveRegion.extent.width = 1;
16675 resolveRegion.extent.height = 1;
16676 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016677 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016678 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016679
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016680 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016681
Chia-I Wuf7458c52015-10-26 21:10:41 +080016682 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016683 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016684 vkFreeMemory(m_device->device(), srcMem, NULL);
16685 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016686}
16687
Karl Schultz6addd812016-02-02 17:17:23 -070016688TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16689 VkResult err;
16690 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016691
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016693 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016694
Mike Stroyana3082432015-09-25 13:39:21 -060016695 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016696
16697 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016698 VkImage srcImage;
16699 VkImage dstImage;
16700 VkDeviceMemory srcMem;
16701 VkDeviceMemory destMem;
16702 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016703
16704 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16706 image_create_info.pNext = NULL;
16707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16709 image_create_info.extent.width = 32;
16710 image_create_info.extent.height = 1;
16711 image_create_info.extent.depth = 1;
16712 image_create_info.mipLevels = 1;
16713 image_create_info.arrayLayers = 1;
16714 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16716 // Note: Some implementations expect color attachment usage for any
16717 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016718 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016719 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016722 ASSERT_VK_SUCCESS(err);
16723
Karl Schultz6addd812016-02-02 17:17:23 -070016724 // Set format to something other than source image
16725 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16726 // Note: Some implementations expect color attachment usage for any
16727 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016728 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016729 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016731 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016732 ASSERT_VK_SUCCESS(err);
16733
16734 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016735 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016736 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16737 memAlloc.pNext = NULL;
16738 memAlloc.allocationSize = 0;
16739 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016740
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016741 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016742 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016743 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016744 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016745 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016746 ASSERT_VK_SUCCESS(err);
16747
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016748 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016749 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016750 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016751 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016752 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016753 ASSERT_VK_SUCCESS(err);
16754
16755 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16756 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016757 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016758 ASSERT_VK_SUCCESS(err);
16759
Tony Barbour552f6c02016-12-21 14:34:07 -070016760 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016761 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016762 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16763 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016764 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016765 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016766 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016767 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016768 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016769 resolveRegion.srcOffset.x = 0;
16770 resolveRegion.srcOffset.y = 0;
16771 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016772 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016773 resolveRegion.dstSubresource.mipLevel = 0;
16774 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016775 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016776 resolveRegion.dstOffset.x = 0;
16777 resolveRegion.dstOffset.y = 0;
16778 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016779 resolveRegion.extent.width = 1;
16780 resolveRegion.extent.height = 1;
16781 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016782 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016783 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016784
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016785 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016786
Chia-I Wuf7458c52015-10-26 21:10:41 +080016787 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016788 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016789 vkFreeMemory(m_device->device(), srcMem, NULL);
16790 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016791}
16792
Karl Schultz6addd812016-02-02 17:17:23 -070016793TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16794 VkResult err;
16795 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016796
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016798 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016799
Mike Stroyana3082432015-09-25 13:39:21 -060016800 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016801
16802 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016803 VkImage srcImage;
16804 VkImage dstImage;
16805 VkDeviceMemory srcMem;
16806 VkDeviceMemory destMem;
16807 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016808
16809 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016810 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16811 image_create_info.pNext = NULL;
16812 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16813 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16814 image_create_info.extent.width = 32;
16815 image_create_info.extent.height = 1;
16816 image_create_info.extent.depth = 1;
16817 image_create_info.mipLevels = 1;
16818 image_create_info.arrayLayers = 1;
16819 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16820 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16821 // Note: Some implementations expect color attachment usage for any
16822 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016823 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016824 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016825
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016826 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016827 ASSERT_VK_SUCCESS(err);
16828
Karl Schultz6addd812016-02-02 17:17:23 -070016829 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16830 // Note: Some implementations expect color attachment usage for any
16831 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016832 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016833 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016835 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016836 ASSERT_VK_SUCCESS(err);
16837
16838 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016839 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016840 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16841 memAlloc.pNext = NULL;
16842 memAlloc.allocationSize = 0;
16843 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016844
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016845 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016846 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016847 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016848 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016849 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016850 ASSERT_VK_SUCCESS(err);
16851
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016852 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016853 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016854 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016855 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016856 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016857 ASSERT_VK_SUCCESS(err);
16858
16859 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16860 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016861 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016862 ASSERT_VK_SUCCESS(err);
16863
Tony Barbour552f6c02016-12-21 14:34:07 -070016864 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016865 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016866 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16867 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016868 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016869 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016870 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016871 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016872 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016873 resolveRegion.srcOffset.x = 0;
16874 resolveRegion.srcOffset.y = 0;
16875 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016876 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016877 resolveRegion.dstSubresource.mipLevel = 0;
16878 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016879 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016880 resolveRegion.dstOffset.x = 0;
16881 resolveRegion.dstOffset.y = 0;
16882 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016883 resolveRegion.extent.width = 1;
16884 resolveRegion.extent.height = 1;
16885 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016886 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016887 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016888
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016889 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016890
Chia-I Wuf7458c52015-10-26 21:10:41 +080016891 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016892 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016893 vkFreeMemory(m_device->device(), srcMem, NULL);
16894 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016895}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016896
Karl Schultz6addd812016-02-02 17:17:23 -070016897TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016898 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016899 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16900 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016901 // The image format check comes 2nd in validation so we trigger it first,
16902 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016903 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16906 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016907
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016908 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016909
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016910 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016911 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16912 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016913
16914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16916 ds_pool_ci.pNext = NULL;
16917 ds_pool_ci.maxSets = 1;
16918 ds_pool_ci.poolSizeCount = 1;
16919 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016920
16921 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016922 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016923 ASSERT_VK_SUCCESS(err);
16924
16925 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016926 dsl_binding.binding = 0;
16927 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16928 dsl_binding.descriptorCount = 1;
16929 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16930 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016931
16932 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016933 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16934 ds_layout_ci.pNext = NULL;
16935 ds_layout_ci.bindingCount = 1;
16936 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016937 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016938 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016939 ASSERT_VK_SUCCESS(err);
16940
16941 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016942 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016944 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016945 alloc_info.descriptorPool = ds_pool;
16946 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016948 ASSERT_VK_SUCCESS(err);
16949
Karl Schultz6addd812016-02-02 17:17:23 -070016950 VkImage image_bad;
16951 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016952 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016953 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016954 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016955 const int32_t tex_width = 32;
16956 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016957
16958 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016959 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16960 image_create_info.pNext = NULL;
16961 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16962 image_create_info.format = tex_format_bad;
16963 image_create_info.extent.width = tex_width;
16964 image_create_info.extent.height = tex_height;
16965 image_create_info.extent.depth = 1;
16966 image_create_info.mipLevels = 1;
16967 image_create_info.arrayLayers = 1;
16968 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16969 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016970 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016971 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016973 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016974 ASSERT_VK_SUCCESS(err);
16975 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016976 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16977 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016978 ASSERT_VK_SUCCESS(err);
16979
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016980 // ---Bind image memory---
16981 VkMemoryRequirements img_mem_reqs;
16982 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
16983 VkMemoryAllocateInfo image_alloc_info = {};
16984 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16985 image_alloc_info.pNext = NULL;
16986 image_alloc_info.memoryTypeIndex = 0;
16987 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016988 bool pass =
16989 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 -070016990 ASSERT_TRUE(pass);
16991 VkDeviceMemory mem;
16992 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
16993 ASSERT_VK_SUCCESS(err);
16994 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
16995 ASSERT_VK_SUCCESS(err);
16996 // -----------------------
16997
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016998 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016999 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017000 image_view_create_info.image = image_bad;
17001 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17002 image_view_create_info.format = tex_format_bad;
17003 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17004 image_view_create_info.subresourceRange.baseMipLevel = 0;
17005 image_view_create_info.subresourceRange.layerCount = 1;
17006 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017007 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017008
17009 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017010 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017011
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017012 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017013
Chia-I Wuf7458c52015-10-26 21:10:41 +080017014 vkDestroyImage(m_device->device(), image_bad, NULL);
17015 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017016 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17017 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017018
17019 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017020}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017021
17022TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017023 TEST_DESCRIPTION(
17024 "Call ClearColorImage w/ a depth|stencil image and "
17025 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017026
17027 ASSERT_NO_FATAL_FAILURE(InitState());
17028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17029
Tony Barbour552f6c02016-12-21 14:34:07 -070017030 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017031
17032 // Color image
17033 VkClearColorValue clear_color;
17034 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17035 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17036 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17037 const int32_t img_width = 32;
17038 const int32_t img_height = 32;
17039 VkImageCreateInfo image_create_info = {};
17040 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17041 image_create_info.pNext = NULL;
17042 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17043 image_create_info.format = color_format;
17044 image_create_info.extent.width = img_width;
17045 image_create_info.extent.height = img_height;
17046 image_create_info.extent.depth = 1;
17047 image_create_info.mipLevels = 1;
17048 image_create_info.arrayLayers = 1;
17049 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17050 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17051 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17052
17053 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017054 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017056 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017057
17058 // Depth/Stencil image
17059 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017060 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017061 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17062 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17063 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17064 ds_image_create_info.extent.width = 64;
17065 ds_image_create_info.extent.height = 64;
17066 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017067 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 -060017068
17069 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017070 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017072 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 -060017073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017076 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017077 &color_range);
17078
17079 m_errorMonitor->VerifyFound();
17080
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17082 "vkCmdClearColorImage called with "
17083 "image created without "
17084 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017085
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017086 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017087 &color_range);
17088
17089 m_errorMonitor->VerifyFound();
17090
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017091 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17093 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017094
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017095 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17096 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017097
17098 m_errorMonitor->VerifyFound();
17099}
Tobin Ehliscde08892015-09-22 10:11:37 -060017100
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017101// WSI Enabled Tests
17102//
Chris Forbes09368e42016-10-13 11:59:22 +130017103#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017104TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17105
17106#if defined(VK_USE_PLATFORM_XCB_KHR)
17107 VkSurfaceKHR surface = VK_NULL_HANDLE;
17108
17109 VkResult err;
17110 bool pass;
17111 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17112 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17113 // uint32_t swapchain_image_count = 0;
17114 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17115 // uint32_t image_index = 0;
17116 // VkPresentInfoKHR present_info = {};
17117
17118 ASSERT_NO_FATAL_FAILURE(InitState());
17119
17120 // Use the create function from one of the VK_KHR_*_surface extension in
17121 // order to create a surface, testing all known errors in the process,
17122 // before successfully creating a surface:
17123 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17125 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17126 pass = (err != VK_SUCCESS);
17127 ASSERT_TRUE(pass);
17128 m_errorMonitor->VerifyFound();
17129
17130 // Next, try to create a surface with the wrong
17131 // VkXcbSurfaceCreateInfoKHR::sType:
17132 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17133 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17135 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17136 pass = (err != VK_SUCCESS);
17137 ASSERT_TRUE(pass);
17138 m_errorMonitor->VerifyFound();
17139
17140 // Create a native window, and then correctly create a surface:
17141 xcb_connection_t *connection;
17142 xcb_screen_t *screen;
17143 xcb_window_t xcb_window;
17144 xcb_intern_atom_reply_t *atom_wm_delete_window;
17145
17146 const xcb_setup_t *setup;
17147 xcb_screen_iterator_t iter;
17148 int scr;
17149 uint32_t value_mask, value_list[32];
17150 int width = 1;
17151 int height = 1;
17152
17153 connection = xcb_connect(NULL, &scr);
17154 ASSERT_TRUE(connection != NULL);
17155 setup = xcb_get_setup(connection);
17156 iter = xcb_setup_roots_iterator(setup);
17157 while (scr-- > 0)
17158 xcb_screen_next(&iter);
17159 screen = iter.data;
17160
17161 xcb_window = xcb_generate_id(connection);
17162
17163 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17164 value_list[0] = screen->black_pixel;
17165 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17166
17167 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17168 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17169
17170 /* Magic code that will send notification when window is destroyed */
17171 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17172 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17173
17174 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17175 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17176 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17177 free(reply);
17178
17179 xcb_map_window(connection, xcb_window);
17180
17181 // Force the x/y coordinates to 100,100 results are identical in consecutive
17182 // runs
17183 const uint32_t coords[] = { 100, 100 };
17184 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17185
17186 // Finally, try to correctly create a surface:
17187 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17188 xcb_create_info.pNext = NULL;
17189 xcb_create_info.flags = 0;
17190 xcb_create_info.connection = connection;
17191 xcb_create_info.window = xcb_window;
17192 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17193 pass = (err == VK_SUCCESS);
17194 ASSERT_TRUE(pass);
17195
17196 // Check if surface supports presentation:
17197
17198 // 1st, do so without having queried the queue families:
17199 VkBool32 supported = false;
17200 // TODO: Get the following error to come out:
17201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17202 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17203 "function");
17204 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17205 pass = (err != VK_SUCCESS);
17206 // ASSERT_TRUE(pass);
17207 // m_errorMonitor->VerifyFound();
17208
17209 // Next, query a queue family index that's too large:
17210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17211 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17212 pass = (err != VK_SUCCESS);
17213 ASSERT_TRUE(pass);
17214 m_errorMonitor->VerifyFound();
17215
17216 // Finally, do so correctly:
17217 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17218 // SUPPORTED
17219 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17220 pass = (err == VK_SUCCESS);
17221 ASSERT_TRUE(pass);
17222
17223 // Before proceeding, try to create a swapchain without having called
17224 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17225 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17226 swapchain_create_info.pNext = NULL;
17227 swapchain_create_info.flags = 0;
17228 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17229 swapchain_create_info.surface = surface;
17230 swapchain_create_info.imageArrayLayers = 1;
17231 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17232 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17234 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17235 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17236 pass = (err != VK_SUCCESS);
17237 ASSERT_TRUE(pass);
17238 m_errorMonitor->VerifyFound();
17239
17240 // Get the surface capabilities:
17241 VkSurfaceCapabilitiesKHR surface_capabilities;
17242
17243 // Do so correctly (only error logged by this entrypoint is if the
17244 // extension isn't enabled):
17245 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17246 pass = (err == VK_SUCCESS);
17247 ASSERT_TRUE(pass);
17248
17249 // Get the surface formats:
17250 uint32_t surface_format_count;
17251
17252 // First, try without a pointer to surface_format_count:
17253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17254 "specified as NULL");
17255 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17256 pass = (err == VK_SUCCESS);
17257 ASSERT_TRUE(pass);
17258 m_errorMonitor->VerifyFound();
17259
17260 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17261 // correctly done a 1st try (to get the count):
17262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17263 surface_format_count = 0;
17264 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17265 pass = (err == VK_SUCCESS);
17266 ASSERT_TRUE(pass);
17267 m_errorMonitor->VerifyFound();
17268
17269 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17270 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17271 pass = (err == VK_SUCCESS);
17272 ASSERT_TRUE(pass);
17273
17274 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17275 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17276
17277 // Next, do a 2nd try with surface_format_count being set too high:
17278 surface_format_count += 5;
17279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17280 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17281 pass = (err == VK_SUCCESS);
17282 ASSERT_TRUE(pass);
17283 m_errorMonitor->VerifyFound();
17284
17285 // Finally, do a correct 1st and 2nd try:
17286 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17287 pass = (err == VK_SUCCESS);
17288 ASSERT_TRUE(pass);
17289 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17290 pass = (err == VK_SUCCESS);
17291 ASSERT_TRUE(pass);
17292
17293 // Get the surface present modes:
17294 uint32_t surface_present_mode_count;
17295
17296 // First, try without a pointer to surface_format_count:
17297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17298 "specified as NULL");
17299
17300 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17301 pass = (err == VK_SUCCESS);
17302 ASSERT_TRUE(pass);
17303 m_errorMonitor->VerifyFound();
17304
17305 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17306 // correctly done a 1st try (to get the count):
17307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17308 surface_present_mode_count = 0;
17309 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17310 (VkPresentModeKHR *)&surface_present_mode_count);
17311 pass = (err == VK_SUCCESS);
17312 ASSERT_TRUE(pass);
17313 m_errorMonitor->VerifyFound();
17314
17315 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17316 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17317 pass = (err == VK_SUCCESS);
17318 ASSERT_TRUE(pass);
17319
17320 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17321 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17322
17323 // Next, do a 2nd try with surface_format_count being set too high:
17324 surface_present_mode_count += 5;
17325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17326 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17327 pass = (err == VK_SUCCESS);
17328 ASSERT_TRUE(pass);
17329 m_errorMonitor->VerifyFound();
17330
17331 // Finally, do a correct 1st and 2nd try:
17332 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17333 pass = (err == VK_SUCCESS);
17334 ASSERT_TRUE(pass);
17335 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17336 pass = (err == VK_SUCCESS);
17337 ASSERT_TRUE(pass);
17338
17339 // Create a swapchain:
17340
17341 // First, try without a pointer to swapchain_create_info:
17342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17343 "specified as NULL");
17344
17345 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17346 pass = (err != VK_SUCCESS);
17347 ASSERT_TRUE(pass);
17348 m_errorMonitor->VerifyFound();
17349
17350 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17351 // sType:
17352 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17354
17355 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17356 pass = (err != VK_SUCCESS);
17357 ASSERT_TRUE(pass);
17358 m_errorMonitor->VerifyFound();
17359
17360 // Next, call with a NULL swapchain pointer:
17361 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17362 swapchain_create_info.pNext = NULL;
17363 swapchain_create_info.flags = 0;
17364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17365 "specified as NULL");
17366
17367 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17368 pass = (err != VK_SUCCESS);
17369 ASSERT_TRUE(pass);
17370 m_errorMonitor->VerifyFound();
17371
17372 // TODO: Enhance swapchain layer so that
17373 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17374
17375 // Next, call with a queue family index that's too large:
17376 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17377 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17378 swapchain_create_info.queueFamilyIndexCount = 2;
17379 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17381 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17382 pass = (err != VK_SUCCESS);
17383 ASSERT_TRUE(pass);
17384 m_errorMonitor->VerifyFound();
17385
17386 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17387 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17388 swapchain_create_info.queueFamilyIndexCount = 1;
17389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17390 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17391 "pCreateInfo->pQueueFamilyIndices).");
17392 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17393 pass = (err != VK_SUCCESS);
17394 ASSERT_TRUE(pass);
17395 m_errorMonitor->VerifyFound();
17396
17397 // Next, call with an invalid imageSharingMode:
17398 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17399 swapchain_create_info.queueFamilyIndexCount = 1;
17400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17401 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17402 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17403 pass = (err != VK_SUCCESS);
17404 ASSERT_TRUE(pass);
17405 m_errorMonitor->VerifyFound();
17406 // Fix for the future:
17407 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17408 // SUPPORTED
17409 swapchain_create_info.queueFamilyIndexCount = 0;
17410 queueFamilyIndex[0] = 0;
17411 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17412
17413 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17414 // Get the images from a swapchain:
17415 // Acquire an image from a swapchain:
17416 // Present an image to a swapchain:
17417 // Destroy the swapchain:
17418
17419 // TODOs:
17420 //
17421 // - Try destroying the device without first destroying the swapchain
17422 //
17423 // - Try destroying the device without first destroying the surface
17424 //
17425 // - Try destroying the surface without first destroying the swapchain
17426
17427 // Destroy the surface:
17428 vkDestroySurfaceKHR(instance(), surface, NULL);
17429
17430 // Tear down the window:
17431 xcb_destroy_window(connection, xcb_window);
17432 xcb_disconnect(connection);
17433
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017434#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017435 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017436#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017437}
Chris Forbes09368e42016-10-13 11:59:22 +130017438#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017439
17440//
17441// POSITIVE VALIDATION TESTS
17442//
17443// These tests do not expect to encounter ANY validation errors pass only if this is true
17444
Tobin Ehlise0006882016-11-03 10:14:28 -060017445TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017446 TEST_DESCRIPTION(
17447 "Perform an image layout transition in a secondary command buffer followed "
17448 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017449 VkResult err;
17450 m_errorMonitor->ExpectSuccess();
17451 ASSERT_NO_FATAL_FAILURE(InitState());
17452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17453 // Allocate a secondary and primary cmd buffer
17454 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17455 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17456 command_buffer_allocate_info.commandPool = m_commandPool;
17457 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17458 command_buffer_allocate_info.commandBufferCount = 1;
17459
17460 VkCommandBuffer secondary_command_buffer;
17461 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17462 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17463 VkCommandBuffer primary_command_buffer;
17464 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17465 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17466 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17467 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17468 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17469 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17470 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17471
17472 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17473 ASSERT_VK_SUCCESS(err);
17474 VkImageObj image(m_device);
17475 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17476 ASSERT_TRUE(image.initialized());
17477 VkImageMemoryBarrier img_barrier = {};
17478 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17479 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17480 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17481 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17482 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17483 img_barrier.image = image.handle();
17484 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17485 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17486 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17487 img_barrier.subresourceRange.baseArrayLayer = 0;
17488 img_barrier.subresourceRange.baseMipLevel = 0;
17489 img_barrier.subresourceRange.layerCount = 1;
17490 img_barrier.subresourceRange.levelCount = 1;
17491 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17492 0, nullptr, 1, &img_barrier);
17493 err = vkEndCommandBuffer(secondary_command_buffer);
17494 ASSERT_VK_SUCCESS(err);
17495
17496 // Now update primary cmd buffer to execute secondary and transitions image
17497 command_buffer_begin_info.pInheritanceInfo = nullptr;
17498 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17499 ASSERT_VK_SUCCESS(err);
17500 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17501 VkImageMemoryBarrier img_barrier2 = {};
17502 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17503 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17504 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17505 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17506 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17507 img_barrier2.image = image.handle();
17508 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17509 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17510 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17511 img_barrier2.subresourceRange.baseArrayLayer = 0;
17512 img_barrier2.subresourceRange.baseMipLevel = 0;
17513 img_barrier2.subresourceRange.layerCount = 1;
17514 img_barrier2.subresourceRange.levelCount = 1;
17515 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17516 nullptr, 1, &img_barrier2);
17517 err = vkEndCommandBuffer(primary_command_buffer);
17518 ASSERT_VK_SUCCESS(err);
17519 VkSubmitInfo submit_info = {};
17520 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17521 submit_info.commandBufferCount = 1;
17522 submit_info.pCommandBuffers = &primary_command_buffer;
17523 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17524 ASSERT_VK_SUCCESS(err);
17525 m_errorMonitor->VerifyNotFound();
17526 err = vkDeviceWaitIdle(m_device->device());
17527 ASSERT_VK_SUCCESS(err);
17528 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17529 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17530}
17531
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017532// This is a positive test. No failures are expected.
17533TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017534 TEST_DESCRIPTION(
17535 "Ensure that the vkUpdateDescriptorSets validation code "
17536 "is ignoring VkWriteDescriptorSet members that are not "
17537 "related to the descriptor type specified by "
17538 "VkWriteDescriptorSet::descriptorType. Correct "
17539 "validation behavior will result in the test running to "
17540 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017541
17542 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17543
17544 ASSERT_NO_FATAL_FAILURE(InitState());
17545
17546 // Image Case
17547 {
17548 m_errorMonitor->ExpectSuccess();
17549
17550 VkImage image;
17551 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17552 const int32_t tex_width = 32;
17553 const int32_t tex_height = 32;
17554 VkImageCreateInfo image_create_info = {};
17555 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17556 image_create_info.pNext = NULL;
17557 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17558 image_create_info.format = tex_format;
17559 image_create_info.extent.width = tex_width;
17560 image_create_info.extent.height = tex_height;
17561 image_create_info.extent.depth = 1;
17562 image_create_info.mipLevels = 1;
17563 image_create_info.arrayLayers = 1;
17564 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17565 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17566 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17567 image_create_info.flags = 0;
17568 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17569 ASSERT_VK_SUCCESS(err);
17570
17571 VkMemoryRequirements memory_reqs;
17572 VkDeviceMemory image_memory;
17573 bool pass;
17574 VkMemoryAllocateInfo memory_info = {};
17575 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17576 memory_info.pNext = NULL;
17577 memory_info.allocationSize = 0;
17578 memory_info.memoryTypeIndex = 0;
17579 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17580 memory_info.allocationSize = memory_reqs.size;
17581 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17582 ASSERT_TRUE(pass);
17583 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17584 ASSERT_VK_SUCCESS(err);
17585 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17586 ASSERT_VK_SUCCESS(err);
17587
17588 VkImageViewCreateInfo image_view_create_info = {};
17589 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17590 image_view_create_info.image = image;
17591 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17592 image_view_create_info.format = tex_format;
17593 image_view_create_info.subresourceRange.layerCount = 1;
17594 image_view_create_info.subresourceRange.baseMipLevel = 0;
17595 image_view_create_info.subresourceRange.levelCount = 1;
17596 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17597
17598 VkImageView view;
17599 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17600 ASSERT_VK_SUCCESS(err);
17601
17602 VkDescriptorPoolSize ds_type_count = {};
17603 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17604 ds_type_count.descriptorCount = 1;
17605
17606 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17607 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17608 ds_pool_ci.pNext = NULL;
17609 ds_pool_ci.maxSets = 1;
17610 ds_pool_ci.poolSizeCount = 1;
17611 ds_pool_ci.pPoolSizes = &ds_type_count;
17612
17613 VkDescriptorPool ds_pool;
17614 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17615 ASSERT_VK_SUCCESS(err);
17616
17617 VkDescriptorSetLayoutBinding dsl_binding = {};
17618 dsl_binding.binding = 0;
17619 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17620 dsl_binding.descriptorCount = 1;
17621 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17622 dsl_binding.pImmutableSamplers = NULL;
17623
17624 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17625 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17626 ds_layout_ci.pNext = NULL;
17627 ds_layout_ci.bindingCount = 1;
17628 ds_layout_ci.pBindings = &dsl_binding;
17629 VkDescriptorSetLayout ds_layout;
17630 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17631 ASSERT_VK_SUCCESS(err);
17632
17633 VkDescriptorSet descriptor_set;
17634 VkDescriptorSetAllocateInfo alloc_info = {};
17635 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17636 alloc_info.descriptorSetCount = 1;
17637 alloc_info.descriptorPool = ds_pool;
17638 alloc_info.pSetLayouts = &ds_layout;
17639 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17640 ASSERT_VK_SUCCESS(err);
17641
17642 VkDescriptorImageInfo image_info = {};
17643 image_info.imageView = view;
17644 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17645
17646 VkWriteDescriptorSet descriptor_write;
17647 memset(&descriptor_write, 0, sizeof(descriptor_write));
17648 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17649 descriptor_write.dstSet = descriptor_set;
17650 descriptor_write.dstBinding = 0;
17651 descriptor_write.descriptorCount = 1;
17652 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17653 descriptor_write.pImageInfo = &image_info;
17654
17655 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17656 // be
17657 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17658 // This will most likely produce a crash if the parameter_validation
17659 // layer
17660 // does not correctly ignore pBufferInfo.
17661 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17662 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17663
17664 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17665
17666 m_errorMonitor->VerifyNotFound();
17667
17668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17669 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17670 vkDestroyImageView(m_device->device(), view, NULL);
17671 vkDestroyImage(m_device->device(), image, NULL);
17672 vkFreeMemory(m_device->device(), image_memory, NULL);
17673 }
17674
17675 // Buffer Case
17676 {
17677 m_errorMonitor->ExpectSuccess();
17678
17679 VkBuffer buffer;
17680 uint32_t queue_family_index = 0;
17681 VkBufferCreateInfo buffer_create_info = {};
17682 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17683 buffer_create_info.size = 1024;
17684 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17685 buffer_create_info.queueFamilyIndexCount = 1;
17686 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17687
17688 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17689 ASSERT_VK_SUCCESS(err);
17690
17691 VkMemoryRequirements memory_reqs;
17692 VkDeviceMemory buffer_memory;
17693 bool pass;
17694 VkMemoryAllocateInfo memory_info = {};
17695 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17696 memory_info.pNext = NULL;
17697 memory_info.allocationSize = 0;
17698 memory_info.memoryTypeIndex = 0;
17699
17700 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17701 memory_info.allocationSize = memory_reqs.size;
17702 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17703 ASSERT_TRUE(pass);
17704
17705 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17706 ASSERT_VK_SUCCESS(err);
17707 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17708 ASSERT_VK_SUCCESS(err);
17709
17710 VkDescriptorPoolSize ds_type_count = {};
17711 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17712 ds_type_count.descriptorCount = 1;
17713
17714 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17715 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17716 ds_pool_ci.pNext = NULL;
17717 ds_pool_ci.maxSets = 1;
17718 ds_pool_ci.poolSizeCount = 1;
17719 ds_pool_ci.pPoolSizes = &ds_type_count;
17720
17721 VkDescriptorPool ds_pool;
17722 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17723 ASSERT_VK_SUCCESS(err);
17724
17725 VkDescriptorSetLayoutBinding dsl_binding = {};
17726 dsl_binding.binding = 0;
17727 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17728 dsl_binding.descriptorCount = 1;
17729 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17730 dsl_binding.pImmutableSamplers = NULL;
17731
17732 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17733 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17734 ds_layout_ci.pNext = NULL;
17735 ds_layout_ci.bindingCount = 1;
17736 ds_layout_ci.pBindings = &dsl_binding;
17737 VkDescriptorSetLayout ds_layout;
17738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17739 ASSERT_VK_SUCCESS(err);
17740
17741 VkDescriptorSet descriptor_set;
17742 VkDescriptorSetAllocateInfo alloc_info = {};
17743 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17744 alloc_info.descriptorSetCount = 1;
17745 alloc_info.descriptorPool = ds_pool;
17746 alloc_info.pSetLayouts = &ds_layout;
17747 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17748 ASSERT_VK_SUCCESS(err);
17749
17750 VkDescriptorBufferInfo buffer_info = {};
17751 buffer_info.buffer = buffer;
17752 buffer_info.offset = 0;
17753 buffer_info.range = 1024;
17754
17755 VkWriteDescriptorSet descriptor_write;
17756 memset(&descriptor_write, 0, sizeof(descriptor_write));
17757 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17758 descriptor_write.dstSet = descriptor_set;
17759 descriptor_write.dstBinding = 0;
17760 descriptor_write.descriptorCount = 1;
17761 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17762 descriptor_write.pBufferInfo = &buffer_info;
17763
17764 // Set pImageInfo and pTexelBufferView to invalid values, which should
17765 // be
17766 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
17767 // This will most likely produce a crash if the parameter_validation
17768 // layer
17769 // does not correctly ignore pImageInfo.
17770 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17771 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17772
17773 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17774
17775 m_errorMonitor->VerifyNotFound();
17776
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17778 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17779 vkDestroyBuffer(m_device->device(), buffer, NULL);
17780 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17781 }
17782
17783 // Texel Buffer Case
17784 {
17785 m_errorMonitor->ExpectSuccess();
17786
17787 VkBuffer buffer;
17788 uint32_t queue_family_index = 0;
17789 VkBufferCreateInfo buffer_create_info = {};
17790 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17791 buffer_create_info.size = 1024;
17792 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
17793 buffer_create_info.queueFamilyIndexCount = 1;
17794 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17795
17796 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17797 ASSERT_VK_SUCCESS(err);
17798
17799 VkMemoryRequirements memory_reqs;
17800 VkDeviceMemory buffer_memory;
17801 bool pass;
17802 VkMemoryAllocateInfo memory_info = {};
17803 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17804 memory_info.pNext = NULL;
17805 memory_info.allocationSize = 0;
17806 memory_info.memoryTypeIndex = 0;
17807
17808 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17809 memory_info.allocationSize = memory_reqs.size;
17810 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17811 ASSERT_TRUE(pass);
17812
17813 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17814 ASSERT_VK_SUCCESS(err);
17815 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17816 ASSERT_VK_SUCCESS(err);
17817
17818 VkBufferViewCreateInfo buff_view_ci = {};
17819 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
17820 buff_view_ci.buffer = buffer;
17821 buff_view_ci.format = VK_FORMAT_R8_UNORM;
17822 buff_view_ci.range = VK_WHOLE_SIZE;
17823 VkBufferView buffer_view;
17824 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
17825
17826 VkDescriptorPoolSize ds_type_count = {};
17827 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17828 ds_type_count.descriptorCount = 1;
17829
17830 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17831 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17832 ds_pool_ci.pNext = NULL;
17833 ds_pool_ci.maxSets = 1;
17834 ds_pool_ci.poolSizeCount = 1;
17835 ds_pool_ci.pPoolSizes = &ds_type_count;
17836
17837 VkDescriptorPool ds_pool;
17838 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17839 ASSERT_VK_SUCCESS(err);
17840
17841 VkDescriptorSetLayoutBinding dsl_binding = {};
17842 dsl_binding.binding = 0;
17843 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17844 dsl_binding.descriptorCount = 1;
17845 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17846 dsl_binding.pImmutableSamplers = NULL;
17847
17848 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17849 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17850 ds_layout_ci.pNext = NULL;
17851 ds_layout_ci.bindingCount = 1;
17852 ds_layout_ci.pBindings = &dsl_binding;
17853 VkDescriptorSetLayout ds_layout;
17854 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17855 ASSERT_VK_SUCCESS(err);
17856
17857 VkDescriptorSet descriptor_set;
17858 VkDescriptorSetAllocateInfo alloc_info = {};
17859 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17860 alloc_info.descriptorSetCount = 1;
17861 alloc_info.descriptorPool = ds_pool;
17862 alloc_info.pSetLayouts = &ds_layout;
17863 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17864 ASSERT_VK_SUCCESS(err);
17865
17866 VkWriteDescriptorSet descriptor_write;
17867 memset(&descriptor_write, 0, sizeof(descriptor_write));
17868 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17869 descriptor_write.dstSet = descriptor_set;
17870 descriptor_write.dstBinding = 0;
17871 descriptor_write.descriptorCount = 1;
17872 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17873 descriptor_write.pTexelBufferView = &buffer_view;
17874
17875 // Set pImageInfo and pBufferInfo to invalid values, which should be
17876 // ignored for descriptorType ==
17877 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
17878 // This will most likely produce a crash if the parameter_validation
17879 // layer
17880 // does not correctly ignore pImageInfo and pBufferInfo.
17881 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17882 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17883
17884 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17885
17886 m_errorMonitor->VerifyNotFound();
17887
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017888 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17889 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17890 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
17891 vkDestroyBuffer(m_device->device(), buffer, NULL);
17892 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17893 }
17894}
17895
Tobin Ehlisf7428442016-10-25 07:58:24 -060017896TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
17897 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
17898
17899 ASSERT_NO_FATAL_FAILURE(InitState());
17900 // Create layout where two binding #s are "1"
17901 static const uint32_t NUM_BINDINGS = 3;
17902 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17903 dsl_binding[0].binding = 1;
17904 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17905 dsl_binding[0].descriptorCount = 1;
17906 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17907 dsl_binding[0].pImmutableSamplers = NULL;
17908 dsl_binding[1].binding = 0;
17909 dsl_binding[1].descriptorCount = 1;
17910 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17911 dsl_binding[1].descriptorCount = 1;
17912 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17913 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017914 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060017915 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17916 dsl_binding[2].descriptorCount = 1;
17917 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17918 dsl_binding[2].pImmutableSamplers = NULL;
17919
17920 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17921 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17922 ds_layout_ci.pNext = NULL;
17923 ds_layout_ci.bindingCount = NUM_BINDINGS;
17924 ds_layout_ci.pBindings = dsl_binding;
17925 VkDescriptorSetLayout ds_layout;
17926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
17927 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17928 m_errorMonitor->VerifyFound();
17929}
17930
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017931TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017932 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
17933
17934 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017935
Tony Barbour552f6c02016-12-21 14:34:07 -070017936 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017937
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017938 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
17939
17940 {
17941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
17942 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
17943 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17944 m_errorMonitor->VerifyFound();
17945 }
17946
17947 {
17948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
17949 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
17950 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17951 m_errorMonitor->VerifyFound();
17952 }
17953
17954 {
17955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17956 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
17957 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17958 m_errorMonitor->VerifyFound();
17959 }
17960
17961 {
17962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17963 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
17964 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17965 m_errorMonitor->VerifyFound();
17966 }
17967
17968 {
17969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
17970 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
17971 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17972 m_errorMonitor->VerifyFound();
17973 }
17974
17975 {
17976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
17977 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
17978 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17979 m_errorMonitor->VerifyFound();
17980 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017981
17982 {
17983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17984 VkRect2D scissor = {{-1, 0}, {16, 16}};
17985 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17986 m_errorMonitor->VerifyFound();
17987 }
17988
17989 {
17990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17991 VkRect2D scissor = {{0, -2}, {16, 16}};
17992 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17993 m_errorMonitor->VerifyFound();
17994 }
17995
17996 {
17997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
17998 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17999 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18000 m_errorMonitor->VerifyFound();
18001 }
18002
18003 {
18004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18005 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18006 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18007 m_errorMonitor->VerifyFound();
18008 }
18009
Tony Barbour552f6c02016-12-21 14:34:07 -070018010 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018011}
18012
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018013// This is a positive test. No failures are expected.
18014TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18015 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18016 VkResult err;
18017
18018 ASSERT_NO_FATAL_FAILURE(InitState());
18019 m_errorMonitor->ExpectSuccess();
18020 VkDescriptorPoolSize ds_type_count = {};
18021 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18022 ds_type_count.descriptorCount = 2;
18023
18024 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18025 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18026 ds_pool_ci.pNext = NULL;
18027 ds_pool_ci.maxSets = 1;
18028 ds_pool_ci.poolSizeCount = 1;
18029 ds_pool_ci.pPoolSizes = &ds_type_count;
18030
18031 VkDescriptorPool ds_pool;
18032 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18033 ASSERT_VK_SUCCESS(err);
18034
18035 // Create layout with two uniform buffer descriptors w/ empty binding between them
18036 static const uint32_t NUM_BINDINGS = 3;
18037 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18038 dsl_binding[0].binding = 0;
18039 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18040 dsl_binding[0].descriptorCount = 1;
18041 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18042 dsl_binding[0].pImmutableSamplers = NULL;
18043 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018044 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018045 dsl_binding[2].binding = 2;
18046 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18047 dsl_binding[2].descriptorCount = 1;
18048 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18049 dsl_binding[2].pImmutableSamplers = NULL;
18050
18051 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18052 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18053 ds_layout_ci.pNext = NULL;
18054 ds_layout_ci.bindingCount = NUM_BINDINGS;
18055 ds_layout_ci.pBindings = dsl_binding;
18056 VkDescriptorSetLayout ds_layout;
18057 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18058 ASSERT_VK_SUCCESS(err);
18059
18060 VkDescriptorSet descriptor_set = {};
18061 VkDescriptorSetAllocateInfo alloc_info = {};
18062 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18063 alloc_info.descriptorSetCount = 1;
18064 alloc_info.descriptorPool = ds_pool;
18065 alloc_info.pSetLayouts = &ds_layout;
18066 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18067 ASSERT_VK_SUCCESS(err);
18068
18069 // Create a buffer to be used for update
18070 VkBufferCreateInfo buff_ci = {};
18071 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18072 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18073 buff_ci.size = 256;
18074 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18075 VkBuffer buffer;
18076 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18077 ASSERT_VK_SUCCESS(err);
18078 // Have to bind memory to buffer before descriptor update
18079 VkMemoryAllocateInfo mem_alloc = {};
18080 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18081 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018082 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018083 mem_alloc.memoryTypeIndex = 0;
18084
18085 VkMemoryRequirements mem_reqs;
18086 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18087 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18088 if (!pass) {
18089 vkDestroyBuffer(m_device->device(), buffer, NULL);
18090 return;
18091 }
18092
18093 VkDeviceMemory mem;
18094 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18095 ASSERT_VK_SUCCESS(err);
18096 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18097 ASSERT_VK_SUCCESS(err);
18098
18099 // Only update the descriptor at binding 2
18100 VkDescriptorBufferInfo buff_info = {};
18101 buff_info.buffer = buffer;
18102 buff_info.offset = 0;
18103 buff_info.range = VK_WHOLE_SIZE;
18104 VkWriteDescriptorSet descriptor_write = {};
18105 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18106 descriptor_write.dstBinding = 2;
18107 descriptor_write.descriptorCount = 1;
18108 descriptor_write.pTexelBufferView = nullptr;
18109 descriptor_write.pBufferInfo = &buff_info;
18110 descriptor_write.pImageInfo = nullptr;
18111 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18112 descriptor_write.dstSet = descriptor_set;
18113
18114 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18115
18116 m_errorMonitor->VerifyNotFound();
18117 // Cleanup
18118 vkFreeMemory(m_device->device(), mem, NULL);
18119 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18120 vkDestroyBuffer(m_device->device(), buffer, NULL);
18121 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18122}
18123
18124// This is a positive test. No failures are expected.
18125TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18126 VkResult err;
18127 bool pass;
18128
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018129 TEST_DESCRIPTION(
18130 "Create a buffer, allocate memory, bind memory, destroy "
18131 "the buffer, create an image, and bind the same memory to "
18132 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018133
18134 m_errorMonitor->ExpectSuccess();
18135
18136 ASSERT_NO_FATAL_FAILURE(InitState());
18137
18138 VkBuffer buffer;
18139 VkImage image;
18140 VkDeviceMemory mem;
18141 VkMemoryRequirements mem_reqs;
18142
18143 VkBufferCreateInfo buf_info = {};
18144 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18145 buf_info.pNext = NULL;
18146 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18147 buf_info.size = 256;
18148 buf_info.queueFamilyIndexCount = 0;
18149 buf_info.pQueueFamilyIndices = NULL;
18150 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18151 buf_info.flags = 0;
18152 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18153 ASSERT_VK_SUCCESS(err);
18154
18155 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18156
18157 VkMemoryAllocateInfo alloc_info = {};
18158 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18159 alloc_info.pNext = NULL;
18160 alloc_info.memoryTypeIndex = 0;
18161
18162 // Ensure memory is big enough for both bindings
18163 alloc_info.allocationSize = 0x10000;
18164
18165 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18166 if (!pass) {
18167 vkDestroyBuffer(m_device->device(), buffer, NULL);
18168 return;
18169 }
18170
18171 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18172 ASSERT_VK_SUCCESS(err);
18173
18174 uint8_t *pData;
18175 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18176 ASSERT_VK_SUCCESS(err);
18177
18178 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18179
18180 vkUnmapMemory(m_device->device(), mem);
18181
18182 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18183 ASSERT_VK_SUCCESS(err);
18184
18185 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18186 // memory. In fact, it was never used by the GPU.
18187 // Just be be sure, wait for idle.
18188 vkDestroyBuffer(m_device->device(), buffer, NULL);
18189 vkDeviceWaitIdle(m_device->device());
18190
Tobin Ehlis6a005702016-12-28 15:25:56 -070018191 // Use optimal as some platforms report linear support but then fail image creation
18192 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18193 VkImageFormatProperties image_format_properties;
18194 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18195 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18196 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018197 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018198 vkFreeMemory(m_device->device(), mem, NULL);
18199 return;
18200 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018201 VkImageCreateInfo image_create_info = {};
18202 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18203 image_create_info.pNext = NULL;
18204 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18205 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18206 image_create_info.extent.width = 64;
18207 image_create_info.extent.height = 64;
18208 image_create_info.extent.depth = 1;
18209 image_create_info.mipLevels = 1;
18210 image_create_info.arrayLayers = 1;
18211 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018212 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018213 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18214 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18215 image_create_info.queueFamilyIndexCount = 0;
18216 image_create_info.pQueueFamilyIndices = NULL;
18217 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18218 image_create_info.flags = 0;
18219
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018220 /* Create a mappable image. It will be the texture if linear images are ok
18221 * to be textures or it will be the staging image if they are not.
18222 */
18223 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18224 ASSERT_VK_SUCCESS(err);
18225
18226 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18227
Tobin Ehlis6a005702016-12-28 15:25:56 -070018228 VkMemoryAllocateInfo mem_alloc = {};
18229 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18230 mem_alloc.pNext = NULL;
18231 mem_alloc.allocationSize = 0;
18232 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018233 mem_alloc.allocationSize = mem_reqs.size;
18234
18235 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18236 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018237 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018238 vkDestroyImage(m_device->device(), image, NULL);
18239 return;
18240 }
18241
18242 // VALIDATION FAILURE:
18243 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18244 ASSERT_VK_SUCCESS(err);
18245
18246 m_errorMonitor->VerifyNotFound();
18247
18248 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018249 vkDestroyImage(m_device->device(), image, NULL);
18250}
18251
Tony Barbourab713912017-02-02 14:17:35 -070018252// This is a positive test. No failures are expected.
18253TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18254 VkResult err;
18255
18256 TEST_DESCRIPTION(
18257 "Call all applicable destroy and free routines with NULL"
18258 "handles, expecting no validation errors");
18259
18260 m_errorMonitor->ExpectSuccess();
18261
18262 ASSERT_NO_FATAL_FAILURE(InitState());
18263 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18264 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18265 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18266 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18267 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18268 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18269 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18270 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18271 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18272 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18273 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18274 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18275 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18276 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18277 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18278 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18279 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18280 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18281 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18282 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18283
18284 VkCommandPool command_pool;
18285 VkCommandPoolCreateInfo pool_create_info{};
18286 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18287 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18288 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18289 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18290 VkCommandBuffer command_buffers[3] = {};
18291 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18292 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18293 command_buffer_allocate_info.commandPool = command_pool;
18294 command_buffer_allocate_info.commandBufferCount = 1;
18295 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18296 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18297 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18298 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18299
18300 VkDescriptorPoolSize ds_type_count = {};
18301 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18302 ds_type_count.descriptorCount = 1;
18303
18304 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18305 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18306 ds_pool_ci.pNext = NULL;
18307 ds_pool_ci.maxSets = 1;
18308 ds_pool_ci.poolSizeCount = 1;
18309 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18310 ds_pool_ci.pPoolSizes = &ds_type_count;
18311
18312 VkDescriptorPool ds_pool;
18313 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18314 ASSERT_VK_SUCCESS(err);
18315
18316 VkDescriptorSetLayoutBinding dsl_binding = {};
18317 dsl_binding.binding = 2;
18318 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18319 dsl_binding.descriptorCount = 1;
18320 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18321 dsl_binding.pImmutableSamplers = NULL;
18322 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18323 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18324 ds_layout_ci.pNext = NULL;
18325 ds_layout_ci.bindingCount = 1;
18326 ds_layout_ci.pBindings = &dsl_binding;
18327 VkDescriptorSetLayout ds_layout;
18328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18329 ASSERT_VK_SUCCESS(err);
18330
18331 VkDescriptorSet descriptor_sets[3] = {};
18332 VkDescriptorSetAllocateInfo alloc_info = {};
18333 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18334 alloc_info.descriptorSetCount = 1;
18335 alloc_info.descriptorPool = ds_pool;
18336 alloc_info.pSetLayouts = &ds_layout;
18337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18338 ASSERT_VK_SUCCESS(err);
18339 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18340 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18341 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18342
18343 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18344
18345 m_errorMonitor->VerifyNotFound();
18346}
18347
Tony Barbour626994c2017-02-08 15:29:37 -070018348TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018349 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018350
18351 m_errorMonitor->ExpectSuccess();
18352
18353 ASSERT_NO_FATAL_FAILURE(InitState());
18354 VkCommandBuffer cmd_bufs[4];
18355 VkCommandBufferAllocateInfo alloc_info;
18356 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18357 alloc_info.pNext = NULL;
18358 alloc_info.commandBufferCount = 4;
18359 alloc_info.commandPool = m_commandPool;
18360 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18361 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18362 VkImageObj image(m_device);
18363 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18364 ASSERT_TRUE(image.initialized());
18365 VkCommandBufferBeginInfo cb_binfo;
18366 cb_binfo.pNext = NULL;
18367 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18368 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18369 cb_binfo.flags = 0;
18370 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18371 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18372 VkImageMemoryBarrier img_barrier = {};
18373 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18374 img_barrier.pNext = NULL;
18375 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18376 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18377 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18378 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18379 img_barrier.image = image.handle();
18380 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18381 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18382 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18383 img_barrier.subresourceRange.baseArrayLayer = 0;
18384 img_barrier.subresourceRange.baseMipLevel = 0;
18385 img_barrier.subresourceRange.layerCount = 1;
18386 img_barrier.subresourceRange.levelCount = 1;
18387 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18388 &img_barrier);
18389 vkEndCommandBuffer(cmd_bufs[0]);
18390 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18391 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18392 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18393 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18394 &img_barrier);
18395 vkEndCommandBuffer(cmd_bufs[1]);
18396 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18397 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18398 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18399 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18400 &img_barrier);
18401 vkEndCommandBuffer(cmd_bufs[2]);
18402 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18403 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18404 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18405 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18406 &img_barrier);
18407 vkEndCommandBuffer(cmd_bufs[3]);
18408
18409 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18410 VkSemaphore semaphore1, semaphore2;
18411 VkSemaphoreCreateInfo semaphore_create_info{};
18412 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18413 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18414 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18415 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18416 VkSubmitInfo submit_info[3];
18417 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18418 submit_info[0].pNext = nullptr;
18419 submit_info[0].commandBufferCount = 1;
18420 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18421 submit_info[0].signalSemaphoreCount = 1;
18422 submit_info[0].pSignalSemaphores = &semaphore1;
18423 submit_info[0].waitSemaphoreCount = 0;
18424 submit_info[0].pWaitDstStageMask = nullptr;
18425 submit_info[0].pWaitDstStageMask = flags;
18426 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18427 submit_info[1].pNext = nullptr;
18428 submit_info[1].commandBufferCount = 1;
18429 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18430 submit_info[1].waitSemaphoreCount = 1;
18431 submit_info[1].pWaitSemaphores = &semaphore1;
18432 submit_info[1].signalSemaphoreCount = 1;
18433 submit_info[1].pSignalSemaphores = &semaphore2;
18434 submit_info[1].pWaitDstStageMask = flags;
18435 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18436 submit_info[2].pNext = nullptr;
18437 submit_info[2].commandBufferCount = 2;
18438 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18439 submit_info[2].waitSemaphoreCount = 1;
18440 submit_info[2].pWaitSemaphores = &semaphore2;
18441 submit_info[2].signalSemaphoreCount = 0;
18442 submit_info[2].pSignalSemaphores = nullptr;
18443 submit_info[2].pWaitDstStageMask = flags;
18444 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18445 vkQueueWaitIdle(m_device->m_queue);
18446
18447 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18448 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18449 m_errorMonitor->VerifyNotFound();
18450}
18451
Tobin Ehlis953e8392016-11-17 10:54:13 -070018452TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18453 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18454 // We previously had a bug where dynamic offset of inactive bindings was still being used
18455 VkResult err;
18456 m_errorMonitor->ExpectSuccess();
18457
18458 ASSERT_NO_FATAL_FAILURE(InitState());
18459 ASSERT_NO_FATAL_FAILURE(InitViewport());
18460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18461
18462 VkDescriptorPoolSize ds_type_count = {};
18463 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18464 ds_type_count.descriptorCount = 3;
18465
18466 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18467 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18468 ds_pool_ci.pNext = NULL;
18469 ds_pool_ci.maxSets = 1;
18470 ds_pool_ci.poolSizeCount = 1;
18471 ds_pool_ci.pPoolSizes = &ds_type_count;
18472
18473 VkDescriptorPool ds_pool;
18474 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18475 ASSERT_VK_SUCCESS(err);
18476
18477 const uint32_t BINDING_COUNT = 3;
18478 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018479 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018480 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18481 dsl_binding[0].descriptorCount = 1;
18482 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18483 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018484 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018485 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18486 dsl_binding[1].descriptorCount = 1;
18487 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18488 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018489 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018490 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18491 dsl_binding[2].descriptorCount = 1;
18492 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18493 dsl_binding[2].pImmutableSamplers = NULL;
18494
18495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18497 ds_layout_ci.pNext = NULL;
18498 ds_layout_ci.bindingCount = BINDING_COUNT;
18499 ds_layout_ci.pBindings = dsl_binding;
18500 VkDescriptorSetLayout ds_layout;
18501 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18502 ASSERT_VK_SUCCESS(err);
18503
18504 VkDescriptorSet descriptor_set;
18505 VkDescriptorSetAllocateInfo alloc_info = {};
18506 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18507 alloc_info.descriptorSetCount = 1;
18508 alloc_info.descriptorPool = ds_pool;
18509 alloc_info.pSetLayouts = &ds_layout;
18510 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18511 ASSERT_VK_SUCCESS(err);
18512
18513 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18514 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18515 pipeline_layout_ci.pNext = NULL;
18516 pipeline_layout_ci.setLayoutCount = 1;
18517 pipeline_layout_ci.pSetLayouts = &ds_layout;
18518
18519 VkPipelineLayout pipeline_layout;
18520 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18521 ASSERT_VK_SUCCESS(err);
18522
18523 // Create two buffers to update the descriptors with
18524 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18525 uint32_t qfi = 0;
18526 VkBufferCreateInfo buffCI = {};
18527 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18528 buffCI.size = 2048;
18529 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18530 buffCI.queueFamilyIndexCount = 1;
18531 buffCI.pQueueFamilyIndices = &qfi;
18532
18533 VkBuffer dyub1;
18534 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18535 ASSERT_VK_SUCCESS(err);
18536 // buffer2
18537 buffCI.size = 1024;
18538 VkBuffer dyub2;
18539 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18540 ASSERT_VK_SUCCESS(err);
18541 // Allocate memory and bind to buffers
18542 VkMemoryAllocateInfo mem_alloc[2] = {};
18543 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18544 mem_alloc[0].pNext = NULL;
18545 mem_alloc[0].memoryTypeIndex = 0;
18546 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18547 mem_alloc[1].pNext = NULL;
18548 mem_alloc[1].memoryTypeIndex = 0;
18549
18550 VkMemoryRequirements mem_reqs1;
18551 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18552 VkMemoryRequirements mem_reqs2;
18553 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18554 mem_alloc[0].allocationSize = mem_reqs1.size;
18555 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18556 mem_alloc[1].allocationSize = mem_reqs2.size;
18557 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18558 if (!pass) {
18559 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18560 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18561 return;
18562 }
18563
18564 VkDeviceMemory mem1;
18565 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18566 ASSERT_VK_SUCCESS(err);
18567 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18568 ASSERT_VK_SUCCESS(err);
18569 VkDeviceMemory mem2;
18570 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18571 ASSERT_VK_SUCCESS(err);
18572 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18573 ASSERT_VK_SUCCESS(err);
18574 // Update descriptors
18575 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18576 buff_info[0].buffer = dyub1;
18577 buff_info[0].offset = 0;
18578 buff_info[0].range = 256;
18579 buff_info[1].buffer = dyub1;
18580 buff_info[1].offset = 256;
18581 buff_info[1].range = 512;
18582 buff_info[2].buffer = dyub2;
18583 buff_info[2].offset = 0;
18584 buff_info[2].range = 512;
18585
18586 VkWriteDescriptorSet descriptor_write;
18587 memset(&descriptor_write, 0, sizeof(descriptor_write));
18588 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18589 descriptor_write.dstSet = descriptor_set;
18590 descriptor_write.dstBinding = 0;
18591 descriptor_write.descriptorCount = BINDING_COUNT;
18592 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18593 descriptor_write.pBufferInfo = buff_info;
18594
18595 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18596
Tony Barbour552f6c02016-12-21 14:34:07 -070018597 m_commandBuffer->BeginCommandBuffer();
18598 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018599
18600 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018601 char const *vsSource =
18602 "#version 450\n"
18603 "\n"
18604 "out gl_PerVertex { \n"
18605 " vec4 gl_Position;\n"
18606 "};\n"
18607 "void main(){\n"
18608 " gl_Position = vec4(1);\n"
18609 "}\n";
18610 char const *fsSource =
18611 "#version 450\n"
18612 "\n"
18613 "layout(location=0) out vec4 x;\n"
18614 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18615 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18616 "void main(){\n"
18617 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18618 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018619 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18620 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18621 VkPipelineObj pipe(m_device);
18622 pipe.SetViewport(m_viewports);
18623 pipe.SetScissor(m_scissors);
18624 pipe.AddShader(&vs);
18625 pipe.AddShader(&fs);
18626 pipe.AddColorAttachment();
18627 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18628
18629 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18630 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18631 // we used to have a bug in this case.
18632 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18633 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18634 &descriptor_set, BINDING_COUNT, dyn_off);
18635 Draw(1, 0, 0, 0);
18636 m_errorMonitor->VerifyNotFound();
18637
18638 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18639 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18640 vkFreeMemory(m_device->device(), mem1, NULL);
18641 vkFreeMemory(m_device->device(), mem2, NULL);
18642
18643 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18644 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18645 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18646}
18647
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018648TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018649 TEST_DESCRIPTION(
18650 "Ensure that validations handling of non-coherent memory "
18651 "mapping while using VK_WHOLE_SIZE does not cause access "
18652 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018653 VkResult err;
18654 uint8_t *pData;
18655 ASSERT_NO_FATAL_FAILURE(InitState());
18656
18657 VkDeviceMemory mem;
18658 VkMemoryRequirements mem_reqs;
18659 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018660 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018661 VkMemoryAllocateInfo alloc_info = {};
18662 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18663 alloc_info.pNext = NULL;
18664 alloc_info.memoryTypeIndex = 0;
18665
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018666 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018667 alloc_info.allocationSize = allocation_size;
18668
18669 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
18670 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 -070018671 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018672 if (!pass) {
18673 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018674 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
18675 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018676 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018677 pass = m_device->phy().set_memory_type(
18678 mem_reqs.memoryTypeBits, &alloc_info,
18679 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
18680 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018681 if (!pass) {
18682 return;
18683 }
18684 }
18685 }
18686
18687 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18688 ASSERT_VK_SUCCESS(err);
18689
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018690 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018691 m_errorMonitor->ExpectSuccess();
18692 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
18693 ASSERT_VK_SUCCESS(err);
18694 VkMappedMemoryRange mmr = {};
18695 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18696 mmr.memory = mem;
18697 mmr.offset = 0;
18698 mmr.size = VK_WHOLE_SIZE;
18699 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18700 ASSERT_VK_SUCCESS(err);
18701 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18702 ASSERT_VK_SUCCESS(err);
18703 m_errorMonitor->VerifyNotFound();
18704 vkUnmapMemory(m_device->device(), mem);
18705
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018706 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018707 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018708 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018709 ASSERT_VK_SUCCESS(err);
18710 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18711 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018712 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018713 mmr.size = VK_WHOLE_SIZE;
18714 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18715 ASSERT_VK_SUCCESS(err);
18716 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18717 ASSERT_VK_SUCCESS(err);
18718 m_errorMonitor->VerifyNotFound();
18719 vkUnmapMemory(m_device->device(), mem);
18720
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018721 // Map with offset and size
18722 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018723 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018724 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018725 ASSERT_VK_SUCCESS(err);
18726 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18727 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018728 mmr.offset = 4 * atom_size;
18729 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018730 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18731 ASSERT_VK_SUCCESS(err);
18732 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18733 ASSERT_VK_SUCCESS(err);
18734 m_errorMonitor->VerifyNotFound();
18735 vkUnmapMemory(m_device->device(), mem);
18736
18737 // Map without offset and flush WHOLE_SIZE with two separate offsets
18738 m_errorMonitor->ExpectSuccess();
18739 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
18740 ASSERT_VK_SUCCESS(err);
18741 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18742 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018743 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018744 mmr.size = VK_WHOLE_SIZE;
18745 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18746 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018747 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018748 mmr.size = VK_WHOLE_SIZE;
18749 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18750 ASSERT_VK_SUCCESS(err);
18751 m_errorMonitor->VerifyNotFound();
18752 vkUnmapMemory(m_device->device(), mem);
18753
18754 vkFreeMemory(m_device->device(), mem, NULL);
18755}
18756
18757// This is a positive test. We used to expect error in this case but spec now allows it
18758TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
18759 m_errorMonitor->ExpectSuccess();
18760 vk_testing::Fence testFence;
18761 VkFenceCreateInfo fenceInfo = {};
18762 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18763 fenceInfo.pNext = NULL;
18764
18765 ASSERT_NO_FATAL_FAILURE(InitState());
18766 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018767 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018768 VkResult result = vkResetFences(m_device->device(), 1, fences);
18769 ASSERT_VK_SUCCESS(result);
18770
18771 m_errorMonitor->VerifyNotFound();
18772}
18773
18774TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
18775 m_errorMonitor->ExpectSuccess();
18776
18777 ASSERT_NO_FATAL_FAILURE(InitState());
18778 VkResult err;
18779
18780 // Record (empty!) command buffer that can be submitted multiple times
18781 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018782 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
18783 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018784 m_commandBuffer->BeginCommandBuffer(&cbbi);
18785 m_commandBuffer->EndCommandBuffer();
18786
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018787 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018788 VkFence fence;
18789 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
18790 ASSERT_VK_SUCCESS(err);
18791
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018792 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018793 VkSemaphore s1, s2;
18794 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
18795 ASSERT_VK_SUCCESS(err);
18796 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
18797 ASSERT_VK_SUCCESS(err);
18798
18799 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018800 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018801 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
18802 ASSERT_VK_SUCCESS(err);
18803
18804 // Submit CB again, signaling s2.
18805 si.pSignalSemaphores = &s2;
18806 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
18807 ASSERT_VK_SUCCESS(err);
18808
18809 // Wait for fence.
18810 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18811 ASSERT_VK_SUCCESS(err);
18812
18813 // CB is still in flight from second submission, but semaphore s1 is no
18814 // longer in flight. delete it.
18815 vkDestroySemaphore(m_device->device(), s1, nullptr);
18816
18817 m_errorMonitor->VerifyNotFound();
18818
18819 // Force device idle and clean up remaining objects
18820 vkDeviceWaitIdle(m_device->device());
18821 vkDestroySemaphore(m_device->device(), s2, nullptr);
18822 vkDestroyFence(m_device->device(), fence, nullptr);
18823}
18824
18825TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
18826 m_errorMonitor->ExpectSuccess();
18827
18828 ASSERT_NO_FATAL_FAILURE(InitState());
18829 VkResult err;
18830
18831 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018832 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018833 VkFence f1;
18834 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
18835 ASSERT_VK_SUCCESS(err);
18836
18837 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018838 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018839 VkFence f2;
18840 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
18841 ASSERT_VK_SUCCESS(err);
18842
18843 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018844 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018845 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
18846
18847 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018848 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018849 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
18850
18851 // Should have both retired!
18852 vkDestroyFence(m_device->device(), f1, nullptr);
18853 vkDestroyFence(m_device->device(), f2, nullptr);
18854
18855 m_errorMonitor->VerifyNotFound();
18856}
18857
18858TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018859 TEST_DESCRIPTION(
18860 "Verify that creating an image view from an image with valid usage "
18861 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018862
18863 ASSERT_NO_FATAL_FAILURE(InitState());
18864
18865 m_errorMonitor->ExpectSuccess();
18866 // Verify that we can create a view with usage INPUT_ATTACHMENT
18867 VkImageObj image(m_device);
18868 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18869 ASSERT_TRUE(image.initialized());
18870 VkImageView imageView;
18871 VkImageViewCreateInfo ivci = {};
18872 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18873 ivci.image = image.handle();
18874 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
18875 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
18876 ivci.subresourceRange.layerCount = 1;
18877 ivci.subresourceRange.baseMipLevel = 0;
18878 ivci.subresourceRange.levelCount = 1;
18879 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18880
18881 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
18882 m_errorMonitor->VerifyNotFound();
18883 vkDestroyImageView(m_device->device(), imageView, NULL);
18884}
18885
18886// This is a positive test. No failures are expected.
18887TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018888 TEST_DESCRIPTION(
18889 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
18890 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018891
18892 ASSERT_NO_FATAL_FAILURE(InitState());
18893
18894 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018895 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018896
18897 m_errorMonitor->ExpectSuccess();
18898
18899 VkImage image;
18900 VkImageCreateInfo image_create_info = {};
18901 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18902 image_create_info.pNext = NULL;
18903 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18904 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18905 image_create_info.extent.width = 64;
18906 image_create_info.extent.height = 64;
18907 image_create_info.extent.depth = 1;
18908 image_create_info.mipLevels = 1;
18909 image_create_info.arrayLayers = 1;
18910 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18911 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18912 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
18913 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
18914 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18915 ASSERT_VK_SUCCESS(err);
18916
18917 VkMemoryRequirements memory_reqs;
18918 VkDeviceMemory memory_one, memory_two;
18919 bool pass;
18920 VkMemoryAllocateInfo memory_info = {};
18921 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18922 memory_info.pNext = NULL;
18923 memory_info.allocationSize = 0;
18924 memory_info.memoryTypeIndex = 0;
18925 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18926 // Find an image big enough to allow sparse mapping of 2 memory regions
18927 // Increase the image size until it is at least twice the
18928 // size of the required alignment, to ensure we can bind both
18929 // allocated memory blocks to the image on aligned offsets.
18930 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
18931 vkDestroyImage(m_device->device(), image, nullptr);
18932 image_create_info.extent.width *= 2;
18933 image_create_info.extent.height *= 2;
18934 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
18935 ASSERT_VK_SUCCESS(err);
18936 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18937 }
18938 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
18939 // at the end of the first
18940 memory_info.allocationSize = memory_reqs.alignment;
18941 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18942 ASSERT_TRUE(pass);
18943 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
18944 ASSERT_VK_SUCCESS(err);
18945 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
18946 ASSERT_VK_SUCCESS(err);
18947 VkSparseMemoryBind binds[2];
18948 binds[0].flags = 0;
18949 binds[0].memory = memory_one;
18950 binds[0].memoryOffset = 0;
18951 binds[0].resourceOffset = 0;
18952 binds[0].size = memory_info.allocationSize;
18953 binds[1].flags = 0;
18954 binds[1].memory = memory_two;
18955 binds[1].memoryOffset = 0;
18956 binds[1].resourceOffset = memory_info.allocationSize;
18957 binds[1].size = memory_info.allocationSize;
18958
18959 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
18960 opaqueBindInfo.image = image;
18961 opaqueBindInfo.bindCount = 2;
18962 opaqueBindInfo.pBinds = binds;
18963
18964 VkFence fence = VK_NULL_HANDLE;
18965 VkBindSparseInfo bindSparseInfo = {};
18966 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
18967 bindSparseInfo.imageOpaqueBindCount = 1;
18968 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
18969
18970 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
18971 vkQueueWaitIdle(m_device->m_queue);
18972 vkDestroyImage(m_device->device(), image, NULL);
18973 vkFreeMemory(m_device->device(), memory_one, NULL);
18974 vkFreeMemory(m_device->device(), memory_two, NULL);
18975 m_errorMonitor->VerifyNotFound();
18976}
18977
18978TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018979 TEST_DESCRIPTION(
18980 "Ensure that CmdBeginRenderPass with an attachment's "
18981 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
18982 "the command buffer has prior knowledge of that "
18983 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018984
18985 m_errorMonitor->ExpectSuccess();
18986
18987 ASSERT_NO_FATAL_FAILURE(InitState());
18988
18989 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018990 VkAttachmentDescription attachment = {0,
18991 VK_FORMAT_R8G8B8A8_UNORM,
18992 VK_SAMPLE_COUNT_1_BIT,
18993 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18994 VK_ATTACHMENT_STORE_OP_STORE,
18995 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18996 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18997 VK_IMAGE_LAYOUT_UNDEFINED,
18998 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018999
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019000 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019001
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019002 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019003
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019004 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019005
19006 VkRenderPass rp;
19007 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19008 ASSERT_VK_SUCCESS(err);
19009
19010 // A compatible framebuffer.
19011 VkImageObj image(m_device);
19012 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19013 ASSERT_TRUE(image.initialized());
19014
19015 VkImageViewCreateInfo ivci = {
19016 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19017 nullptr,
19018 0,
19019 image.handle(),
19020 VK_IMAGE_VIEW_TYPE_2D,
19021 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019022 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19023 VK_COMPONENT_SWIZZLE_IDENTITY},
19024 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019025 };
19026 VkImageView view;
19027 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19028 ASSERT_VK_SUCCESS(err);
19029
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019030 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019031 VkFramebuffer fb;
19032 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19033 ASSERT_VK_SUCCESS(err);
19034
19035 // Record a single command buffer which uses this renderpass twice. The
19036 // bug is triggered at the beginning of the second renderpass, when the
19037 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019038 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 -070019039 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019040 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19041 vkCmdEndRenderPass(m_commandBuffer->handle());
19042 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19043
19044 m_errorMonitor->VerifyNotFound();
19045
19046 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019047 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019048
19049 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19050 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19051 vkDestroyImageView(m_device->device(), view, nullptr);
19052}
19053
19054TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019055 TEST_DESCRIPTION(
19056 "This test should pass. Create a Framebuffer and "
19057 "command buffer, bind them together, then destroy "
19058 "command pool and framebuffer and verify there are no "
19059 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019060
19061 m_errorMonitor->ExpectSuccess();
19062
19063 ASSERT_NO_FATAL_FAILURE(InitState());
19064
19065 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019066 VkAttachmentDescription attachment = {0,
19067 VK_FORMAT_R8G8B8A8_UNORM,
19068 VK_SAMPLE_COUNT_1_BIT,
19069 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19070 VK_ATTACHMENT_STORE_OP_STORE,
19071 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19072 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19073 VK_IMAGE_LAYOUT_UNDEFINED,
19074 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019075
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019076 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019077
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019078 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019079
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019080 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019081
19082 VkRenderPass rp;
19083 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19084 ASSERT_VK_SUCCESS(err);
19085
19086 // A compatible framebuffer.
19087 VkImageObj image(m_device);
19088 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19089 ASSERT_TRUE(image.initialized());
19090
19091 VkImageViewCreateInfo ivci = {
19092 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19093 nullptr,
19094 0,
19095 image.handle(),
19096 VK_IMAGE_VIEW_TYPE_2D,
19097 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019098 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19099 VK_COMPONENT_SWIZZLE_IDENTITY},
19100 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019101 };
19102 VkImageView view;
19103 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19104 ASSERT_VK_SUCCESS(err);
19105
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019106 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019107 VkFramebuffer fb;
19108 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19109 ASSERT_VK_SUCCESS(err);
19110
19111 // Explicitly create a command buffer to bind the FB to so that we can then
19112 // destroy the command pool in order to implicitly free command buffer
19113 VkCommandPool command_pool;
19114 VkCommandPoolCreateInfo pool_create_info{};
19115 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19116 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19117 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19118 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19119
19120 VkCommandBuffer command_buffer;
19121 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19122 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19123 command_buffer_allocate_info.commandPool = command_pool;
19124 command_buffer_allocate_info.commandBufferCount = 1;
19125 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19126 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19127
19128 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019129 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 -060019130 VkCommandBufferBeginInfo begin_info{};
19131 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19132 vkBeginCommandBuffer(command_buffer, &begin_info);
19133
19134 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19135 vkCmdEndRenderPass(command_buffer);
19136 vkEndCommandBuffer(command_buffer);
19137 vkDestroyImageView(m_device->device(), view, nullptr);
19138 // Destroy command pool to implicitly free command buffer
19139 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19140 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19141 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19142 m_errorMonitor->VerifyNotFound();
19143}
19144
19145TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019146 TEST_DESCRIPTION(
19147 "Ensure that CmdBeginRenderPass applies the layout "
19148 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019149
19150 m_errorMonitor->ExpectSuccess();
19151
19152 ASSERT_NO_FATAL_FAILURE(InitState());
19153
19154 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019155 VkAttachmentDescription attachment = {0,
19156 VK_FORMAT_R8G8B8A8_UNORM,
19157 VK_SAMPLE_COUNT_1_BIT,
19158 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19159 VK_ATTACHMENT_STORE_OP_STORE,
19160 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19161 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19162 VK_IMAGE_LAYOUT_UNDEFINED,
19163 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019164
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019165 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019166
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019167 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019168
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019169 VkSubpassDependency dep = {0,
19170 0,
19171 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19172 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19173 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19174 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19175 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019176
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019177 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019178
19179 VkResult err;
19180 VkRenderPass rp;
19181 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19182 ASSERT_VK_SUCCESS(err);
19183
19184 // A compatible framebuffer.
19185 VkImageObj image(m_device);
19186 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19187 ASSERT_TRUE(image.initialized());
19188
19189 VkImageViewCreateInfo ivci = {
19190 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19191 nullptr,
19192 0,
19193 image.handle(),
19194 VK_IMAGE_VIEW_TYPE_2D,
19195 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019196 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19197 VK_COMPONENT_SWIZZLE_IDENTITY},
19198 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019199 };
19200 VkImageView view;
19201 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19202 ASSERT_VK_SUCCESS(err);
19203
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019204 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019205 VkFramebuffer fb;
19206 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19207 ASSERT_VK_SUCCESS(err);
19208
19209 // Record a single command buffer which issues a pipeline barrier w/
19210 // image memory barrier for the attachment. This detects the previously
19211 // missing tracking of the subpass layout by throwing a validation error
19212 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019213 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 -070019214 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019215 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19216
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019217 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19218 nullptr,
19219 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19220 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19221 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19222 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19223 VK_QUEUE_FAMILY_IGNORED,
19224 VK_QUEUE_FAMILY_IGNORED,
19225 image.handle(),
19226 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019227 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019228 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19229 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019230
19231 vkCmdEndRenderPass(m_commandBuffer->handle());
19232 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019233 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019234
19235 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19236 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19237 vkDestroyImageView(m_device->device(), view, nullptr);
19238}
19239
19240TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019241 TEST_DESCRIPTION(
19242 "Validate that when an imageView of a depth/stencil image "
19243 "is used as a depth/stencil framebuffer attachment, the "
19244 "aspectMask is ignored and both depth and stencil image "
19245 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019246
19247 VkFormatProperties format_properties;
19248 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19249 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19250 return;
19251 }
19252
19253 m_errorMonitor->ExpectSuccess();
19254
19255 ASSERT_NO_FATAL_FAILURE(InitState());
19256
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019257 VkAttachmentDescription attachment = {0,
19258 VK_FORMAT_D32_SFLOAT_S8_UINT,
19259 VK_SAMPLE_COUNT_1_BIT,
19260 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19261 VK_ATTACHMENT_STORE_OP_STORE,
19262 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19263 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19264 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19265 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019266
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019267 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019268
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019269 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019270
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019271 VkSubpassDependency dep = {0,
19272 0,
19273 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19274 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19275 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19276 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19277 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019278
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019279 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019280
19281 VkResult err;
19282 VkRenderPass rp;
19283 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19284 ASSERT_VK_SUCCESS(err);
19285
19286 VkImageObj image(m_device);
19287 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019288 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019289 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019290 ASSERT_TRUE(image.initialized());
19291 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19292
19293 VkImageViewCreateInfo ivci = {
19294 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19295 nullptr,
19296 0,
19297 image.handle(),
19298 VK_IMAGE_VIEW_TYPE_2D,
19299 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019300 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19301 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019302 };
19303 VkImageView view;
19304 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19305 ASSERT_VK_SUCCESS(err);
19306
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019307 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019308 VkFramebuffer fb;
19309 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19310 ASSERT_VK_SUCCESS(err);
19311
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019312 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 -070019313 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019314 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19315
19316 VkImageMemoryBarrier imb = {};
19317 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19318 imb.pNext = nullptr;
19319 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19320 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19321 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19322 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19323 imb.srcQueueFamilyIndex = 0;
19324 imb.dstQueueFamilyIndex = 0;
19325 imb.image = image.handle();
19326 imb.subresourceRange.aspectMask = 0x6;
19327 imb.subresourceRange.baseMipLevel = 0;
19328 imb.subresourceRange.levelCount = 0x1;
19329 imb.subresourceRange.baseArrayLayer = 0;
19330 imb.subresourceRange.layerCount = 0x1;
19331
19332 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019333 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19334 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019335
19336 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019337 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019338 QueueCommandBuffer(false);
19339 m_errorMonitor->VerifyNotFound();
19340
19341 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19342 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19343 vkDestroyImageView(m_device->device(), view, nullptr);
19344}
19345
19346TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019347 TEST_DESCRIPTION(
19348 "Ensure that layout transitions work correctly without "
19349 "errors, when an attachment reference is "
19350 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019351
19352 m_errorMonitor->ExpectSuccess();
19353
19354 ASSERT_NO_FATAL_FAILURE(InitState());
19355
19356 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019357 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019358
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019359 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019360
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019361 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019362
19363 VkRenderPass rp;
19364 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19365 ASSERT_VK_SUCCESS(err);
19366
19367 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019368 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019369 VkFramebuffer fb;
19370 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19371 ASSERT_VK_SUCCESS(err);
19372
19373 // Record a command buffer which just begins and ends the renderpass. The
19374 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019375 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 -070019376 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019377 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19378 vkCmdEndRenderPass(m_commandBuffer->handle());
19379 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019380 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019381
19382 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19383 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19384}
19385
19386// This is a positive test. No errors are expected.
19387TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019388 TEST_DESCRIPTION(
19389 "Create a stencil-only attachment with a LOAD_OP set to "
19390 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019391 VkResult result = VK_SUCCESS;
19392 VkImageFormatProperties formatProps;
19393 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019394 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19395 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019396 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19397 return;
19398 }
19399
19400 ASSERT_NO_FATAL_FAILURE(InitState());
19401 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19402 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019403 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019404 VkAttachmentDescription att = {};
19405 VkAttachmentReference ref = {};
19406 att.format = depth_stencil_fmt;
19407 att.samples = VK_SAMPLE_COUNT_1_BIT;
19408 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19409 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19410 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19411 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19412 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19413 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19414
19415 VkClearValue clear;
19416 clear.depthStencil.depth = 1.0;
19417 clear.depthStencil.stencil = 0;
19418 ref.attachment = 0;
19419 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19420
19421 VkSubpassDescription subpass = {};
19422 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19423 subpass.flags = 0;
19424 subpass.inputAttachmentCount = 0;
19425 subpass.pInputAttachments = NULL;
19426 subpass.colorAttachmentCount = 0;
19427 subpass.pColorAttachments = NULL;
19428 subpass.pResolveAttachments = NULL;
19429 subpass.pDepthStencilAttachment = &ref;
19430 subpass.preserveAttachmentCount = 0;
19431 subpass.pPreserveAttachments = NULL;
19432
19433 VkRenderPass rp;
19434 VkRenderPassCreateInfo rp_info = {};
19435 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19436 rp_info.attachmentCount = 1;
19437 rp_info.pAttachments = &att;
19438 rp_info.subpassCount = 1;
19439 rp_info.pSubpasses = &subpass;
19440 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19441 ASSERT_VK_SUCCESS(result);
19442
19443 VkImageView *depthView = m_depthStencil->BindInfo();
19444 VkFramebufferCreateInfo fb_info = {};
19445 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19446 fb_info.pNext = NULL;
19447 fb_info.renderPass = rp;
19448 fb_info.attachmentCount = 1;
19449 fb_info.pAttachments = depthView;
19450 fb_info.width = 100;
19451 fb_info.height = 100;
19452 fb_info.layers = 1;
19453 VkFramebuffer fb;
19454 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19455 ASSERT_VK_SUCCESS(result);
19456
19457 VkRenderPassBeginInfo rpbinfo = {};
19458 rpbinfo.clearValueCount = 1;
19459 rpbinfo.pClearValues = &clear;
19460 rpbinfo.pNext = NULL;
19461 rpbinfo.renderPass = rp;
19462 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19463 rpbinfo.renderArea.extent.width = 100;
19464 rpbinfo.renderArea.extent.height = 100;
19465 rpbinfo.renderArea.offset.x = 0;
19466 rpbinfo.renderArea.offset.y = 0;
19467 rpbinfo.framebuffer = fb;
19468
19469 VkFence fence = {};
19470 VkFenceCreateInfo fence_ci = {};
19471 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19472 fence_ci.pNext = nullptr;
19473 fence_ci.flags = 0;
19474 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19475 ASSERT_VK_SUCCESS(result);
19476
19477 m_commandBuffer->BeginCommandBuffer();
19478 m_commandBuffer->BeginRenderPass(rpbinfo);
19479 m_commandBuffer->EndRenderPass();
19480 m_commandBuffer->EndCommandBuffer();
19481 m_commandBuffer->QueueCommandBuffer(fence);
19482
19483 VkImageObj destImage(m_device);
19484 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 -070019485 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019486 VkImageMemoryBarrier barrier = {};
19487 VkImageSubresourceRange range;
19488 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19489 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19490 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19491 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19492 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19493 barrier.image = m_depthStencil->handle();
19494 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19495 range.baseMipLevel = 0;
19496 range.levelCount = 1;
19497 range.baseArrayLayer = 0;
19498 range.layerCount = 1;
19499 barrier.subresourceRange = range;
19500 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19501 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19502 cmdbuf.BeginCommandBuffer();
19503 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 -070019504 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019505 barrier.srcAccessMask = 0;
19506 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19507 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19508 barrier.image = destImage.handle();
19509 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19510 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 -070019511 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019512 VkImageCopy cregion;
19513 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19514 cregion.srcSubresource.mipLevel = 0;
19515 cregion.srcSubresource.baseArrayLayer = 0;
19516 cregion.srcSubresource.layerCount = 1;
19517 cregion.srcOffset.x = 0;
19518 cregion.srcOffset.y = 0;
19519 cregion.srcOffset.z = 0;
19520 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19521 cregion.dstSubresource.mipLevel = 0;
19522 cregion.dstSubresource.baseArrayLayer = 0;
19523 cregion.dstSubresource.layerCount = 1;
19524 cregion.dstOffset.x = 0;
19525 cregion.dstOffset.y = 0;
19526 cregion.dstOffset.z = 0;
19527 cregion.extent.width = 100;
19528 cregion.extent.height = 100;
19529 cregion.extent.depth = 1;
19530 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019531 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019532 cmdbuf.EndCommandBuffer();
19533
19534 VkSubmitInfo submit_info;
19535 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19536 submit_info.pNext = NULL;
19537 submit_info.waitSemaphoreCount = 0;
19538 submit_info.pWaitSemaphores = NULL;
19539 submit_info.pWaitDstStageMask = NULL;
19540 submit_info.commandBufferCount = 1;
19541 submit_info.pCommandBuffers = &cmdbuf.handle();
19542 submit_info.signalSemaphoreCount = 0;
19543 submit_info.pSignalSemaphores = NULL;
19544
19545 m_errorMonitor->ExpectSuccess();
19546 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19547 m_errorMonitor->VerifyNotFound();
19548
19549 vkQueueWaitIdle(m_device->m_queue);
19550 vkDestroyFence(m_device->device(), fence, nullptr);
19551 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19552 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19553}
19554
19555// This is a positive test. No errors should be generated.
19556TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19557 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19558
19559 m_errorMonitor->ExpectSuccess();
19560 ASSERT_NO_FATAL_FAILURE(InitState());
19561
19562 VkEvent event;
19563 VkEventCreateInfo event_create_info{};
19564 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19565 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19566
19567 VkCommandPool command_pool;
19568 VkCommandPoolCreateInfo pool_create_info{};
19569 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19570 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19571 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19572 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19573
19574 VkCommandBuffer command_buffer;
19575 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19576 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19577 command_buffer_allocate_info.commandPool = command_pool;
19578 command_buffer_allocate_info.commandBufferCount = 1;
19579 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19580 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19581
19582 VkQueue queue = VK_NULL_HANDLE;
19583 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19584
19585 {
19586 VkCommandBufferBeginInfo begin_info{};
19587 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19588 vkBeginCommandBuffer(command_buffer, &begin_info);
19589
19590 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 -070019591 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019592 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19593 vkEndCommandBuffer(command_buffer);
19594 }
19595 {
19596 VkSubmitInfo submit_info{};
19597 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19598 submit_info.commandBufferCount = 1;
19599 submit_info.pCommandBuffers = &command_buffer;
19600 submit_info.signalSemaphoreCount = 0;
19601 submit_info.pSignalSemaphores = nullptr;
19602 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19603 }
19604 { vkSetEvent(m_device->device(), event); }
19605
19606 vkQueueWaitIdle(queue);
19607
19608 vkDestroyEvent(m_device->device(), event, nullptr);
19609 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19610 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19611
19612 m_errorMonitor->VerifyNotFound();
19613}
19614// This is a positive test. No errors should be generated.
19615TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19616 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19617
19618 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019619 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019620
19621 m_errorMonitor->ExpectSuccess();
19622
19623 VkQueryPool query_pool;
19624 VkQueryPoolCreateInfo query_pool_create_info{};
19625 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19626 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19627 query_pool_create_info.queryCount = 1;
19628 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19629
19630 VkCommandPool command_pool;
19631 VkCommandPoolCreateInfo pool_create_info{};
19632 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19633 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19634 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19635 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19636
19637 VkCommandBuffer command_buffer;
19638 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19639 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19640 command_buffer_allocate_info.commandPool = command_pool;
19641 command_buffer_allocate_info.commandBufferCount = 1;
19642 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19643 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19644
19645 VkCommandBuffer secondary_command_buffer;
19646 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19647 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
19648
19649 VkQueue queue = VK_NULL_HANDLE;
19650 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19651
19652 uint32_t qfi = 0;
19653 VkBufferCreateInfo buff_create_info = {};
19654 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19655 buff_create_info.size = 1024;
19656 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19657 buff_create_info.queueFamilyIndexCount = 1;
19658 buff_create_info.pQueueFamilyIndices = &qfi;
19659
19660 VkResult err;
19661 VkBuffer buffer;
19662 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19663 ASSERT_VK_SUCCESS(err);
19664 VkMemoryAllocateInfo mem_alloc = {};
19665 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19666 mem_alloc.pNext = NULL;
19667 mem_alloc.allocationSize = 1024;
19668 mem_alloc.memoryTypeIndex = 0;
19669
19670 VkMemoryRequirements memReqs;
19671 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19672 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19673 if (!pass) {
19674 vkDestroyBuffer(m_device->device(), buffer, NULL);
19675 return;
19676 }
19677
19678 VkDeviceMemory mem;
19679 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19680 ASSERT_VK_SUCCESS(err);
19681 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19682 ASSERT_VK_SUCCESS(err);
19683
19684 VkCommandBufferInheritanceInfo hinfo = {};
19685 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19686 hinfo.renderPass = VK_NULL_HANDLE;
19687 hinfo.subpass = 0;
19688 hinfo.framebuffer = VK_NULL_HANDLE;
19689 hinfo.occlusionQueryEnable = VK_FALSE;
19690 hinfo.queryFlags = 0;
19691 hinfo.pipelineStatistics = 0;
19692
19693 {
19694 VkCommandBufferBeginInfo begin_info{};
19695 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19696 begin_info.pInheritanceInfo = &hinfo;
19697 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
19698
19699 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
19700 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19701
19702 vkEndCommandBuffer(secondary_command_buffer);
19703
19704 begin_info.pInheritanceInfo = nullptr;
19705 vkBeginCommandBuffer(command_buffer, &begin_info);
19706
19707 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
19708 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
19709
19710 vkEndCommandBuffer(command_buffer);
19711 }
19712 {
19713 VkSubmitInfo submit_info{};
19714 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19715 submit_info.commandBufferCount = 1;
19716 submit_info.pCommandBuffers = &command_buffer;
19717 submit_info.signalSemaphoreCount = 0;
19718 submit_info.pSignalSemaphores = nullptr;
19719 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19720 }
19721
19722 vkQueueWaitIdle(queue);
19723
19724 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19725 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19726 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
19727 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19728 vkDestroyBuffer(m_device->device(), buffer, NULL);
19729 vkFreeMemory(m_device->device(), mem, NULL);
19730
19731 m_errorMonitor->VerifyNotFound();
19732}
19733
19734// This is a positive test. No errors should be generated.
19735TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
19736 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
19737
19738 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019739 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019740
19741 m_errorMonitor->ExpectSuccess();
19742
19743 VkQueryPool query_pool;
19744 VkQueryPoolCreateInfo query_pool_create_info{};
19745 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19746 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19747 query_pool_create_info.queryCount = 1;
19748 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19749
19750 VkCommandPool command_pool;
19751 VkCommandPoolCreateInfo pool_create_info{};
19752 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19753 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19754 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19755 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19756
19757 VkCommandBuffer command_buffer[2];
19758 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19759 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19760 command_buffer_allocate_info.commandPool = command_pool;
19761 command_buffer_allocate_info.commandBufferCount = 2;
19762 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19763 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19764
19765 VkQueue queue = VK_NULL_HANDLE;
19766 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19767
19768 uint32_t qfi = 0;
19769 VkBufferCreateInfo buff_create_info = {};
19770 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19771 buff_create_info.size = 1024;
19772 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19773 buff_create_info.queueFamilyIndexCount = 1;
19774 buff_create_info.pQueueFamilyIndices = &qfi;
19775
19776 VkResult err;
19777 VkBuffer buffer;
19778 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19779 ASSERT_VK_SUCCESS(err);
19780 VkMemoryAllocateInfo mem_alloc = {};
19781 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19782 mem_alloc.pNext = NULL;
19783 mem_alloc.allocationSize = 1024;
19784 mem_alloc.memoryTypeIndex = 0;
19785
19786 VkMemoryRequirements memReqs;
19787 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19788 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19789 if (!pass) {
19790 vkDestroyBuffer(m_device->device(), buffer, NULL);
19791 return;
19792 }
19793
19794 VkDeviceMemory mem;
19795 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19796 ASSERT_VK_SUCCESS(err);
19797 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19798 ASSERT_VK_SUCCESS(err);
19799
19800 {
19801 VkCommandBufferBeginInfo begin_info{};
19802 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19803 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19804
19805 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
19806 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19807
19808 vkEndCommandBuffer(command_buffer[0]);
19809
19810 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19811
19812 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
19813
19814 vkEndCommandBuffer(command_buffer[1]);
19815 }
19816 {
19817 VkSubmitInfo submit_info{};
19818 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19819 submit_info.commandBufferCount = 2;
19820 submit_info.pCommandBuffers = command_buffer;
19821 submit_info.signalSemaphoreCount = 0;
19822 submit_info.pSignalSemaphores = nullptr;
19823 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19824 }
19825
19826 vkQueueWaitIdle(queue);
19827
19828 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19829 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
19830 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19831 vkDestroyBuffer(m_device->device(), buffer, NULL);
19832 vkFreeMemory(m_device->device(), mem, NULL);
19833
19834 m_errorMonitor->VerifyNotFound();
19835}
19836
Tony Barbourc46924f2016-11-04 11:49:52 -060019837TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019838 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
19839
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019840 ASSERT_NO_FATAL_FAILURE(InitState());
19841 VkEvent event;
19842 VkEventCreateInfo event_create_info{};
19843 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19844 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19845
19846 VkCommandPool command_pool;
19847 VkCommandPoolCreateInfo pool_create_info{};
19848 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19849 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19850 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19851 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19852
19853 VkCommandBuffer command_buffer;
19854 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19855 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19856 command_buffer_allocate_info.commandPool = command_pool;
19857 command_buffer_allocate_info.commandBufferCount = 1;
19858 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19859 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19860
19861 VkQueue queue = VK_NULL_HANDLE;
19862 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19863
19864 {
19865 VkCommandBufferBeginInfo begin_info{};
19866 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19867 vkBeginCommandBuffer(command_buffer, &begin_info);
19868
19869 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019870 vkEndCommandBuffer(command_buffer);
19871 }
19872 {
19873 VkSubmitInfo submit_info{};
19874 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19875 submit_info.commandBufferCount = 1;
19876 submit_info.pCommandBuffers = &command_buffer;
19877 submit_info.signalSemaphoreCount = 0;
19878 submit_info.pSignalSemaphores = nullptr;
19879 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19880 }
19881 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19883 "that is already in use by a "
19884 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019885 vkSetEvent(m_device->device(), event);
19886 m_errorMonitor->VerifyFound();
19887 }
19888
19889 vkQueueWaitIdle(queue);
19890
19891 vkDestroyEvent(m_device->device(), event, nullptr);
19892 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19893 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19894}
19895
19896// This is a positive test. No errors should be generated.
19897TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019898 TEST_DESCRIPTION(
19899 "Two command buffers with two separate fences are each "
19900 "run through a Submit & WaitForFences cycle 3 times. This "
19901 "previously revealed a bug so running this positive test "
19902 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019903 m_errorMonitor->ExpectSuccess();
19904
19905 ASSERT_NO_FATAL_FAILURE(InitState());
19906 VkQueue queue = VK_NULL_HANDLE;
19907 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19908
19909 static const uint32_t NUM_OBJECTS = 2;
19910 static const uint32_t NUM_FRAMES = 3;
19911 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
19912 VkFence fences[NUM_OBJECTS] = {};
19913
19914 VkCommandPool cmd_pool;
19915 VkCommandPoolCreateInfo cmd_pool_ci = {};
19916 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19917 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
19918 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19919 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
19920 ASSERT_VK_SUCCESS(err);
19921
19922 VkCommandBufferAllocateInfo cmd_buf_info = {};
19923 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19924 cmd_buf_info.commandPool = cmd_pool;
19925 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19926 cmd_buf_info.commandBufferCount = 1;
19927
19928 VkFenceCreateInfo fence_ci = {};
19929 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19930 fence_ci.pNext = nullptr;
19931 fence_ci.flags = 0;
19932
19933 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19934 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
19935 ASSERT_VK_SUCCESS(err);
19936 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
19937 ASSERT_VK_SUCCESS(err);
19938 }
19939
19940 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
19941 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
19942 // Create empty cmd buffer
19943 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
19944 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19945
19946 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
19947 ASSERT_VK_SUCCESS(err);
19948 err = vkEndCommandBuffer(cmd_buffers[obj]);
19949 ASSERT_VK_SUCCESS(err);
19950
19951 VkSubmitInfo submit_info = {};
19952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19953 submit_info.commandBufferCount = 1;
19954 submit_info.pCommandBuffers = &cmd_buffers[obj];
19955 // Submit cmd buffer and wait for fence
19956 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
19957 ASSERT_VK_SUCCESS(err);
19958 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
19959 ASSERT_VK_SUCCESS(err);
19960 err = vkResetFences(m_device->device(), 1, &fences[obj]);
19961 ASSERT_VK_SUCCESS(err);
19962 }
19963 }
19964 m_errorMonitor->VerifyNotFound();
19965 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
19966 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19967 vkDestroyFence(m_device->device(), fences[i], nullptr);
19968 }
19969}
19970// This is a positive test. No errors should be generated.
19971TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019972 TEST_DESCRIPTION(
19973 "Two command buffers, each in a separate QueueSubmit call "
19974 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019975
19976 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019977 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019978
19979 m_errorMonitor->ExpectSuccess();
19980
19981 VkSemaphore semaphore;
19982 VkSemaphoreCreateInfo semaphore_create_info{};
19983 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19984 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19985
19986 VkCommandPool command_pool;
19987 VkCommandPoolCreateInfo pool_create_info{};
19988 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19989 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19990 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19991 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19992
19993 VkCommandBuffer command_buffer[2];
19994 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19995 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19996 command_buffer_allocate_info.commandPool = command_pool;
19997 command_buffer_allocate_info.commandBufferCount = 2;
19998 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19999 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20000
20001 VkQueue queue = VK_NULL_HANDLE;
20002 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20003
20004 {
20005 VkCommandBufferBeginInfo begin_info{};
20006 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20007 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20008
20009 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 -070020010 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020011
20012 VkViewport viewport{};
20013 viewport.maxDepth = 1.0f;
20014 viewport.minDepth = 0.0f;
20015 viewport.width = 512;
20016 viewport.height = 512;
20017 viewport.x = 0;
20018 viewport.y = 0;
20019 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20020 vkEndCommandBuffer(command_buffer[0]);
20021 }
20022 {
20023 VkCommandBufferBeginInfo begin_info{};
20024 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20025 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20026
20027 VkViewport viewport{};
20028 viewport.maxDepth = 1.0f;
20029 viewport.minDepth = 0.0f;
20030 viewport.width = 512;
20031 viewport.height = 512;
20032 viewport.x = 0;
20033 viewport.y = 0;
20034 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20035 vkEndCommandBuffer(command_buffer[1]);
20036 }
20037 {
20038 VkSubmitInfo submit_info{};
20039 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20040 submit_info.commandBufferCount = 1;
20041 submit_info.pCommandBuffers = &command_buffer[0];
20042 submit_info.signalSemaphoreCount = 1;
20043 submit_info.pSignalSemaphores = &semaphore;
20044 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20045 }
20046 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020047 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020048 VkSubmitInfo submit_info{};
20049 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20050 submit_info.commandBufferCount = 1;
20051 submit_info.pCommandBuffers = &command_buffer[1];
20052 submit_info.waitSemaphoreCount = 1;
20053 submit_info.pWaitSemaphores = &semaphore;
20054 submit_info.pWaitDstStageMask = flags;
20055 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20056 }
20057
20058 vkQueueWaitIdle(m_device->m_queue);
20059
20060 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20061 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20062 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20063
20064 m_errorMonitor->VerifyNotFound();
20065}
20066
20067// This is a positive test. No errors should be generated.
20068TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020069 TEST_DESCRIPTION(
20070 "Two command buffers, each in a separate QueueSubmit call "
20071 "submitted on separate queues, the second having a fence"
20072 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020073
20074 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020075 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020076
20077 m_errorMonitor->ExpectSuccess();
20078
20079 VkFence fence;
20080 VkFenceCreateInfo fence_create_info{};
20081 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20082 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20083
20084 VkSemaphore semaphore;
20085 VkSemaphoreCreateInfo semaphore_create_info{};
20086 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20087 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20088
20089 VkCommandPool command_pool;
20090 VkCommandPoolCreateInfo pool_create_info{};
20091 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20092 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20093 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20094 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20095
20096 VkCommandBuffer command_buffer[2];
20097 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20098 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20099 command_buffer_allocate_info.commandPool = command_pool;
20100 command_buffer_allocate_info.commandBufferCount = 2;
20101 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20102 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20103
20104 VkQueue queue = VK_NULL_HANDLE;
20105 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20106
20107 {
20108 VkCommandBufferBeginInfo begin_info{};
20109 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20110 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20111
20112 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 -070020113 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020114
20115 VkViewport viewport{};
20116 viewport.maxDepth = 1.0f;
20117 viewport.minDepth = 0.0f;
20118 viewport.width = 512;
20119 viewport.height = 512;
20120 viewport.x = 0;
20121 viewport.y = 0;
20122 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20123 vkEndCommandBuffer(command_buffer[0]);
20124 }
20125 {
20126 VkCommandBufferBeginInfo begin_info{};
20127 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20128 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20129
20130 VkViewport viewport{};
20131 viewport.maxDepth = 1.0f;
20132 viewport.minDepth = 0.0f;
20133 viewport.width = 512;
20134 viewport.height = 512;
20135 viewport.x = 0;
20136 viewport.y = 0;
20137 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20138 vkEndCommandBuffer(command_buffer[1]);
20139 }
20140 {
20141 VkSubmitInfo submit_info{};
20142 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20143 submit_info.commandBufferCount = 1;
20144 submit_info.pCommandBuffers = &command_buffer[0];
20145 submit_info.signalSemaphoreCount = 1;
20146 submit_info.pSignalSemaphores = &semaphore;
20147 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20148 }
20149 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020150 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020151 VkSubmitInfo submit_info{};
20152 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20153 submit_info.commandBufferCount = 1;
20154 submit_info.pCommandBuffers = &command_buffer[1];
20155 submit_info.waitSemaphoreCount = 1;
20156 submit_info.pWaitSemaphores = &semaphore;
20157 submit_info.pWaitDstStageMask = flags;
20158 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20159 }
20160
20161 vkQueueWaitIdle(m_device->m_queue);
20162
20163 vkDestroyFence(m_device->device(), fence, nullptr);
20164 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20165 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20166 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20167
20168 m_errorMonitor->VerifyNotFound();
20169}
20170
20171// This is a positive test. No errors should be generated.
20172TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020173 TEST_DESCRIPTION(
20174 "Two command buffers, each in a separate QueueSubmit call "
20175 "submitted on separate queues, the second having a fence"
20176 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020177
20178 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020179 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020180
20181 m_errorMonitor->ExpectSuccess();
20182
20183 VkFence fence;
20184 VkFenceCreateInfo fence_create_info{};
20185 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20186 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20187
20188 VkSemaphore semaphore;
20189 VkSemaphoreCreateInfo semaphore_create_info{};
20190 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20191 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20192
20193 VkCommandPool command_pool;
20194 VkCommandPoolCreateInfo pool_create_info{};
20195 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20196 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20197 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20198 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20199
20200 VkCommandBuffer command_buffer[2];
20201 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20202 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20203 command_buffer_allocate_info.commandPool = command_pool;
20204 command_buffer_allocate_info.commandBufferCount = 2;
20205 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20206 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20207
20208 VkQueue queue = VK_NULL_HANDLE;
20209 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20210
20211 {
20212 VkCommandBufferBeginInfo begin_info{};
20213 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20214 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20215
20216 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 -070020217 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020218
20219 VkViewport viewport{};
20220 viewport.maxDepth = 1.0f;
20221 viewport.minDepth = 0.0f;
20222 viewport.width = 512;
20223 viewport.height = 512;
20224 viewport.x = 0;
20225 viewport.y = 0;
20226 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20227 vkEndCommandBuffer(command_buffer[0]);
20228 }
20229 {
20230 VkCommandBufferBeginInfo begin_info{};
20231 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20232 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20233
20234 VkViewport viewport{};
20235 viewport.maxDepth = 1.0f;
20236 viewport.minDepth = 0.0f;
20237 viewport.width = 512;
20238 viewport.height = 512;
20239 viewport.x = 0;
20240 viewport.y = 0;
20241 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20242 vkEndCommandBuffer(command_buffer[1]);
20243 }
20244 {
20245 VkSubmitInfo submit_info{};
20246 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20247 submit_info.commandBufferCount = 1;
20248 submit_info.pCommandBuffers = &command_buffer[0];
20249 submit_info.signalSemaphoreCount = 1;
20250 submit_info.pSignalSemaphores = &semaphore;
20251 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20252 }
20253 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020254 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020255 VkSubmitInfo submit_info{};
20256 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20257 submit_info.commandBufferCount = 1;
20258 submit_info.pCommandBuffers = &command_buffer[1];
20259 submit_info.waitSemaphoreCount = 1;
20260 submit_info.pWaitSemaphores = &semaphore;
20261 submit_info.pWaitDstStageMask = flags;
20262 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20263 }
20264
20265 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20266 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20267
20268 vkDestroyFence(m_device->device(), fence, nullptr);
20269 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20270 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20271 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20272
20273 m_errorMonitor->VerifyNotFound();
20274}
20275
20276TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020277 ASSERT_NO_FATAL_FAILURE(InitState());
20278 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020279 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020280 return;
20281 }
20282
20283 VkResult err;
20284
20285 m_errorMonitor->ExpectSuccess();
20286
20287 VkQueue q0 = m_device->m_queue;
20288 VkQueue q1 = nullptr;
20289 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20290 ASSERT_NE(q1, nullptr);
20291
20292 // An (empty) command buffer. We must have work in the first submission --
20293 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020294 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020295 VkCommandPool pool;
20296 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20297 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020298 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20299 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020300 VkCommandBuffer cb;
20301 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20302 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020303 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020304 err = vkBeginCommandBuffer(cb, &cbbi);
20305 ASSERT_VK_SUCCESS(err);
20306 err = vkEndCommandBuffer(cb);
20307 ASSERT_VK_SUCCESS(err);
20308
20309 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020310 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020311 VkSemaphore s;
20312 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20313 ASSERT_VK_SUCCESS(err);
20314
20315 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020316 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020317
20318 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20319 ASSERT_VK_SUCCESS(err);
20320
20321 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020322 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020323 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020324
20325 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20326 ASSERT_VK_SUCCESS(err);
20327
20328 // Wait for q0 idle
20329 err = vkQueueWaitIdle(q0);
20330 ASSERT_VK_SUCCESS(err);
20331
20332 // Command buffer should have been completed (it was on q0); reset the pool.
20333 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20334
20335 m_errorMonitor->VerifyNotFound();
20336
20337 // Force device completely idle and clean up resources
20338 vkDeviceWaitIdle(m_device->device());
20339 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20340 vkDestroySemaphore(m_device->device(), s, nullptr);
20341}
20342
20343// This is a positive test. No errors should be generated.
20344TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020345 TEST_DESCRIPTION(
20346 "Two command buffers, each in a separate QueueSubmit call "
20347 "submitted on separate queues, the second having a fence, "
20348 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020349
20350 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020351 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020352
20353 m_errorMonitor->ExpectSuccess();
20354
20355 ASSERT_NO_FATAL_FAILURE(InitState());
20356 VkFence fence;
20357 VkFenceCreateInfo fence_create_info{};
20358 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20359 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20360
20361 VkSemaphore semaphore;
20362 VkSemaphoreCreateInfo semaphore_create_info{};
20363 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20364 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20365
20366 VkCommandPool command_pool;
20367 VkCommandPoolCreateInfo pool_create_info{};
20368 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20369 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20370 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20371 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20372
20373 VkCommandBuffer command_buffer[2];
20374 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20375 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20376 command_buffer_allocate_info.commandPool = command_pool;
20377 command_buffer_allocate_info.commandBufferCount = 2;
20378 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20379 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20380
20381 VkQueue queue = VK_NULL_HANDLE;
20382 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20383
20384 {
20385 VkCommandBufferBeginInfo begin_info{};
20386 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20387 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20388
20389 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 -070020390 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020391
20392 VkViewport viewport{};
20393 viewport.maxDepth = 1.0f;
20394 viewport.minDepth = 0.0f;
20395 viewport.width = 512;
20396 viewport.height = 512;
20397 viewport.x = 0;
20398 viewport.y = 0;
20399 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20400 vkEndCommandBuffer(command_buffer[0]);
20401 }
20402 {
20403 VkCommandBufferBeginInfo begin_info{};
20404 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20405 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20406
20407 VkViewport viewport{};
20408 viewport.maxDepth = 1.0f;
20409 viewport.minDepth = 0.0f;
20410 viewport.width = 512;
20411 viewport.height = 512;
20412 viewport.x = 0;
20413 viewport.y = 0;
20414 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20415 vkEndCommandBuffer(command_buffer[1]);
20416 }
20417 {
20418 VkSubmitInfo submit_info{};
20419 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20420 submit_info.commandBufferCount = 1;
20421 submit_info.pCommandBuffers = &command_buffer[0];
20422 submit_info.signalSemaphoreCount = 1;
20423 submit_info.pSignalSemaphores = &semaphore;
20424 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20425 }
20426 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020427 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020428 VkSubmitInfo submit_info{};
20429 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20430 submit_info.commandBufferCount = 1;
20431 submit_info.pCommandBuffers = &command_buffer[1];
20432 submit_info.waitSemaphoreCount = 1;
20433 submit_info.pWaitSemaphores = &semaphore;
20434 submit_info.pWaitDstStageMask = flags;
20435 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20436 }
20437
20438 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20439
20440 vkDestroyFence(m_device->device(), fence, nullptr);
20441 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20442 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20443 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20444
20445 m_errorMonitor->VerifyNotFound();
20446}
20447
20448// This is a positive test. No errors should be generated.
20449TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020450 TEST_DESCRIPTION(
20451 "Two command buffers, each in a separate QueueSubmit call "
20452 "on the same queue, sharing a signal/wait semaphore, the "
20453 "second having a fence, "
20454 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020455
20456 m_errorMonitor->ExpectSuccess();
20457
20458 ASSERT_NO_FATAL_FAILURE(InitState());
20459 VkFence fence;
20460 VkFenceCreateInfo fence_create_info{};
20461 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20462 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20463
20464 VkSemaphore semaphore;
20465 VkSemaphoreCreateInfo semaphore_create_info{};
20466 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20467 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20468
20469 VkCommandPool command_pool;
20470 VkCommandPoolCreateInfo pool_create_info{};
20471 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20472 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20473 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20474 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20475
20476 VkCommandBuffer command_buffer[2];
20477 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20478 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20479 command_buffer_allocate_info.commandPool = command_pool;
20480 command_buffer_allocate_info.commandBufferCount = 2;
20481 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20482 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20483
20484 {
20485 VkCommandBufferBeginInfo begin_info{};
20486 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20487 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20488
20489 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 -070020490 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020491
20492 VkViewport viewport{};
20493 viewport.maxDepth = 1.0f;
20494 viewport.minDepth = 0.0f;
20495 viewport.width = 512;
20496 viewport.height = 512;
20497 viewport.x = 0;
20498 viewport.y = 0;
20499 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20500 vkEndCommandBuffer(command_buffer[0]);
20501 }
20502 {
20503 VkCommandBufferBeginInfo begin_info{};
20504 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20505 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20506
20507 VkViewport viewport{};
20508 viewport.maxDepth = 1.0f;
20509 viewport.minDepth = 0.0f;
20510 viewport.width = 512;
20511 viewport.height = 512;
20512 viewport.x = 0;
20513 viewport.y = 0;
20514 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20515 vkEndCommandBuffer(command_buffer[1]);
20516 }
20517 {
20518 VkSubmitInfo submit_info{};
20519 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20520 submit_info.commandBufferCount = 1;
20521 submit_info.pCommandBuffers = &command_buffer[0];
20522 submit_info.signalSemaphoreCount = 1;
20523 submit_info.pSignalSemaphores = &semaphore;
20524 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20525 }
20526 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020527 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020528 VkSubmitInfo submit_info{};
20529 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20530 submit_info.commandBufferCount = 1;
20531 submit_info.pCommandBuffers = &command_buffer[1];
20532 submit_info.waitSemaphoreCount = 1;
20533 submit_info.pWaitSemaphores = &semaphore;
20534 submit_info.pWaitDstStageMask = flags;
20535 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20536 }
20537
20538 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20539
20540 vkDestroyFence(m_device->device(), fence, nullptr);
20541 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20542 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20543 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20544
20545 m_errorMonitor->VerifyNotFound();
20546}
20547
20548// This is a positive test. No errors should be generated.
20549TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020550 TEST_DESCRIPTION(
20551 "Two command buffers, each in a separate QueueSubmit call "
20552 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20553 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020554
20555 m_errorMonitor->ExpectSuccess();
20556
20557 ASSERT_NO_FATAL_FAILURE(InitState());
20558 VkFence fence;
20559 VkFenceCreateInfo fence_create_info{};
20560 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20561 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20562
20563 VkCommandPool command_pool;
20564 VkCommandPoolCreateInfo pool_create_info{};
20565 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20566 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20567 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20568 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20569
20570 VkCommandBuffer command_buffer[2];
20571 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20572 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20573 command_buffer_allocate_info.commandPool = command_pool;
20574 command_buffer_allocate_info.commandBufferCount = 2;
20575 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20576 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20577
20578 {
20579 VkCommandBufferBeginInfo begin_info{};
20580 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20581 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20582
20583 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 -070020584 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020585
20586 VkViewport viewport{};
20587 viewport.maxDepth = 1.0f;
20588 viewport.minDepth = 0.0f;
20589 viewport.width = 512;
20590 viewport.height = 512;
20591 viewport.x = 0;
20592 viewport.y = 0;
20593 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20594 vkEndCommandBuffer(command_buffer[0]);
20595 }
20596 {
20597 VkCommandBufferBeginInfo begin_info{};
20598 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20599 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20600
20601 VkViewport viewport{};
20602 viewport.maxDepth = 1.0f;
20603 viewport.minDepth = 0.0f;
20604 viewport.width = 512;
20605 viewport.height = 512;
20606 viewport.x = 0;
20607 viewport.y = 0;
20608 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20609 vkEndCommandBuffer(command_buffer[1]);
20610 }
20611 {
20612 VkSubmitInfo submit_info{};
20613 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20614 submit_info.commandBufferCount = 1;
20615 submit_info.pCommandBuffers = &command_buffer[0];
20616 submit_info.signalSemaphoreCount = 0;
20617 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20618 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20619 }
20620 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020621 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020622 VkSubmitInfo submit_info{};
20623 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20624 submit_info.commandBufferCount = 1;
20625 submit_info.pCommandBuffers = &command_buffer[1];
20626 submit_info.waitSemaphoreCount = 0;
20627 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20628 submit_info.pWaitDstStageMask = flags;
20629 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20630 }
20631
20632 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20633
20634 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20635 ASSERT_VK_SUCCESS(err);
20636
20637 vkDestroyFence(m_device->device(), fence, nullptr);
20638 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20639 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20640
20641 m_errorMonitor->VerifyNotFound();
20642}
20643
20644// This is a positive test. No errors should be generated.
20645TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020646 TEST_DESCRIPTION(
20647 "Two command buffers, each in a separate QueueSubmit call "
20648 "on the same queue, the second having a fence, followed "
20649 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020650
20651 m_errorMonitor->ExpectSuccess();
20652
20653 ASSERT_NO_FATAL_FAILURE(InitState());
20654 VkFence fence;
20655 VkFenceCreateInfo fence_create_info{};
20656 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20657 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20658
20659 VkCommandPool command_pool;
20660 VkCommandPoolCreateInfo pool_create_info{};
20661 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20662 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20663 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20664 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20665
20666 VkCommandBuffer command_buffer[2];
20667 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20668 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20669 command_buffer_allocate_info.commandPool = command_pool;
20670 command_buffer_allocate_info.commandBufferCount = 2;
20671 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20672 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20673
20674 {
20675 VkCommandBufferBeginInfo begin_info{};
20676 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20677 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20678
20679 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 -070020680 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020681
20682 VkViewport viewport{};
20683 viewport.maxDepth = 1.0f;
20684 viewport.minDepth = 0.0f;
20685 viewport.width = 512;
20686 viewport.height = 512;
20687 viewport.x = 0;
20688 viewport.y = 0;
20689 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20690 vkEndCommandBuffer(command_buffer[0]);
20691 }
20692 {
20693 VkCommandBufferBeginInfo begin_info{};
20694 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20695 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20696
20697 VkViewport viewport{};
20698 viewport.maxDepth = 1.0f;
20699 viewport.minDepth = 0.0f;
20700 viewport.width = 512;
20701 viewport.height = 512;
20702 viewport.x = 0;
20703 viewport.y = 0;
20704 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20705 vkEndCommandBuffer(command_buffer[1]);
20706 }
20707 {
20708 VkSubmitInfo submit_info{};
20709 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20710 submit_info.commandBufferCount = 1;
20711 submit_info.pCommandBuffers = &command_buffer[0];
20712 submit_info.signalSemaphoreCount = 0;
20713 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20714 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20715 }
20716 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020717 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020718 VkSubmitInfo submit_info{};
20719 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20720 submit_info.commandBufferCount = 1;
20721 submit_info.pCommandBuffers = &command_buffer[1];
20722 submit_info.waitSemaphoreCount = 0;
20723 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20724 submit_info.pWaitDstStageMask = flags;
20725 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20726 }
20727
20728 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20729
20730 vkDestroyFence(m_device->device(), fence, nullptr);
20731 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20732 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20733
20734 m_errorMonitor->VerifyNotFound();
20735}
20736
20737// This is a positive test. No errors should be generated.
20738TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020739 TEST_DESCRIPTION(
20740 "Two command buffers each in a separate SubmitInfo sent in a single "
20741 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020742 ASSERT_NO_FATAL_FAILURE(InitState());
20743
20744 m_errorMonitor->ExpectSuccess();
20745
20746 VkFence fence;
20747 VkFenceCreateInfo fence_create_info{};
20748 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20749 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20750
20751 VkSemaphore semaphore;
20752 VkSemaphoreCreateInfo semaphore_create_info{};
20753 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20754 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20755
20756 VkCommandPool command_pool;
20757 VkCommandPoolCreateInfo pool_create_info{};
20758 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20759 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20760 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20761 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20762
20763 VkCommandBuffer command_buffer[2];
20764 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20765 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20766 command_buffer_allocate_info.commandPool = command_pool;
20767 command_buffer_allocate_info.commandBufferCount = 2;
20768 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20769 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20770
20771 {
20772 VkCommandBufferBeginInfo begin_info{};
20773 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20774 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20775
20776 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 -070020777 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020778
20779 VkViewport viewport{};
20780 viewport.maxDepth = 1.0f;
20781 viewport.minDepth = 0.0f;
20782 viewport.width = 512;
20783 viewport.height = 512;
20784 viewport.x = 0;
20785 viewport.y = 0;
20786 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20787 vkEndCommandBuffer(command_buffer[0]);
20788 }
20789 {
20790 VkCommandBufferBeginInfo begin_info{};
20791 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20792 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20793
20794 VkViewport viewport{};
20795 viewport.maxDepth = 1.0f;
20796 viewport.minDepth = 0.0f;
20797 viewport.width = 512;
20798 viewport.height = 512;
20799 viewport.x = 0;
20800 viewport.y = 0;
20801 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20802 vkEndCommandBuffer(command_buffer[1]);
20803 }
20804 {
20805 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020806 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020807
20808 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20809 submit_info[0].pNext = NULL;
20810 submit_info[0].commandBufferCount = 1;
20811 submit_info[0].pCommandBuffers = &command_buffer[0];
20812 submit_info[0].signalSemaphoreCount = 1;
20813 submit_info[0].pSignalSemaphores = &semaphore;
20814 submit_info[0].waitSemaphoreCount = 0;
20815 submit_info[0].pWaitSemaphores = NULL;
20816 submit_info[0].pWaitDstStageMask = 0;
20817
20818 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20819 submit_info[1].pNext = NULL;
20820 submit_info[1].commandBufferCount = 1;
20821 submit_info[1].pCommandBuffers = &command_buffer[1];
20822 submit_info[1].waitSemaphoreCount = 1;
20823 submit_info[1].pWaitSemaphores = &semaphore;
20824 submit_info[1].pWaitDstStageMask = flags;
20825 submit_info[1].signalSemaphoreCount = 0;
20826 submit_info[1].pSignalSemaphores = NULL;
20827 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
20828 }
20829
20830 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20831
20832 vkDestroyFence(m_device->device(), fence, nullptr);
20833 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20834 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20835 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20836
20837 m_errorMonitor->VerifyNotFound();
20838}
20839
20840TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
20841 m_errorMonitor->ExpectSuccess();
20842
20843 ASSERT_NO_FATAL_FAILURE(InitState());
20844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20845
Tony Barbour552f6c02016-12-21 14:34:07 -070020846 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020847
20848 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
20849 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20850 m_errorMonitor->VerifyNotFound();
20851 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
20852 m_errorMonitor->VerifyNotFound();
20853 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20854 m_errorMonitor->VerifyNotFound();
20855
20856 m_commandBuffer->EndCommandBuffer();
20857 m_errorMonitor->VerifyNotFound();
20858}
20859
20860TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020861 TEST_DESCRIPTION(
20862 "Positive test where we create a renderpass with an "
20863 "attachment that uses LOAD_OP_CLEAR, the first subpass "
20864 "has a valid layout, and a second subpass then uses a "
20865 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020866 m_errorMonitor->ExpectSuccess();
20867 ASSERT_NO_FATAL_FAILURE(InitState());
20868
20869 VkAttachmentReference attach[2] = {};
20870 attach[0].attachment = 0;
20871 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20872 attach[1].attachment = 0;
20873 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20874 VkSubpassDescription subpasses[2] = {};
20875 // First subpass clears DS attach on load
20876 subpasses[0].pDepthStencilAttachment = &attach[0];
20877 // 2nd subpass reads in DS as input attachment
20878 subpasses[1].inputAttachmentCount = 1;
20879 subpasses[1].pInputAttachments = &attach[1];
20880 VkAttachmentDescription attach_desc = {};
20881 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
20882 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
20883 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
20884 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20885 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20886 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20887 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20888 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20889 VkRenderPassCreateInfo rpci = {};
20890 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20891 rpci.attachmentCount = 1;
20892 rpci.pAttachments = &attach_desc;
20893 rpci.subpassCount = 2;
20894 rpci.pSubpasses = subpasses;
20895
20896 // Now create RenderPass and verify no errors
20897 VkRenderPass rp;
20898 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
20899 m_errorMonitor->VerifyNotFound();
20900
20901 vkDestroyRenderPass(m_device->device(), rp, NULL);
20902}
20903
20904TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020905 TEST_DESCRIPTION(
20906 "Test that pipeline validation accepts matrices passed "
20907 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020908 m_errorMonitor->ExpectSuccess();
20909
20910 ASSERT_NO_FATAL_FAILURE(InitState());
20911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20912
20913 VkVertexInputBindingDescription input_binding;
20914 memset(&input_binding, 0, sizeof(input_binding));
20915
20916 VkVertexInputAttributeDescription input_attribs[2];
20917 memset(input_attribs, 0, sizeof(input_attribs));
20918
20919 for (int i = 0; i < 2; i++) {
20920 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20921 input_attribs[i].location = i;
20922 }
20923
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020924 char const *vsSource =
20925 "#version 450\n"
20926 "\n"
20927 "layout(location=0) in mat2x4 x;\n"
20928 "out gl_PerVertex {\n"
20929 " vec4 gl_Position;\n"
20930 "};\n"
20931 "void main(){\n"
20932 " gl_Position = x[0] + x[1];\n"
20933 "}\n";
20934 char const *fsSource =
20935 "#version 450\n"
20936 "\n"
20937 "layout(location=0) out vec4 color;\n"
20938 "void main(){\n"
20939 " color = vec4(1);\n"
20940 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020941
20942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20944
20945 VkPipelineObj pipe(m_device);
20946 pipe.AddColorAttachment();
20947 pipe.AddShader(&vs);
20948 pipe.AddShader(&fs);
20949
20950 pipe.AddVertexInputBindings(&input_binding, 1);
20951 pipe.AddVertexInputAttribs(input_attribs, 2);
20952
20953 VkDescriptorSetObj descriptorSet(m_device);
20954 descriptorSet.AppendDummy();
20955 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20956
20957 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20958
20959 /* expect success */
20960 m_errorMonitor->VerifyNotFound();
20961}
20962
20963TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
20964 m_errorMonitor->ExpectSuccess();
20965
20966 ASSERT_NO_FATAL_FAILURE(InitState());
20967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20968
20969 VkVertexInputBindingDescription input_binding;
20970 memset(&input_binding, 0, sizeof(input_binding));
20971
20972 VkVertexInputAttributeDescription input_attribs[2];
20973 memset(input_attribs, 0, sizeof(input_attribs));
20974
20975 for (int i = 0; i < 2; i++) {
20976 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20977 input_attribs[i].location = i;
20978 }
20979
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020980 char const *vsSource =
20981 "#version 450\n"
20982 "\n"
20983 "layout(location=0) in vec4 x[2];\n"
20984 "out gl_PerVertex {\n"
20985 " vec4 gl_Position;\n"
20986 "};\n"
20987 "void main(){\n"
20988 " gl_Position = x[0] + x[1];\n"
20989 "}\n";
20990 char const *fsSource =
20991 "#version 450\n"
20992 "\n"
20993 "layout(location=0) out vec4 color;\n"
20994 "void main(){\n"
20995 " color = vec4(1);\n"
20996 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020997
20998 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20999 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21000
21001 VkPipelineObj pipe(m_device);
21002 pipe.AddColorAttachment();
21003 pipe.AddShader(&vs);
21004 pipe.AddShader(&fs);
21005
21006 pipe.AddVertexInputBindings(&input_binding, 1);
21007 pipe.AddVertexInputAttribs(input_attribs, 2);
21008
21009 VkDescriptorSetObj descriptorSet(m_device);
21010 descriptorSet.AppendDummy();
21011 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21012
21013 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21014
21015 m_errorMonitor->VerifyNotFound();
21016}
21017
21018TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021019 TEST_DESCRIPTION(
21020 "Test that pipeline validation accepts consuming a vertex attribute "
21021 "through multiple vertex shader inputs, each consuming a different "
21022 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021023 m_errorMonitor->ExpectSuccess();
21024
21025 ASSERT_NO_FATAL_FAILURE(InitState());
21026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21027
21028 VkVertexInputBindingDescription input_binding;
21029 memset(&input_binding, 0, sizeof(input_binding));
21030
21031 VkVertexInputAttributeDescription input_attribs[3];
21032 memset(input_attribs, 0, sizeof(input_attribs));
21033
21034 for (int i = 0; i < 3; i++) {
21035 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21036 input_attribs[i].location = i;
21037 }
21038
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021039 char const *vsSource =
21040 "#version 450\n"
21041 "\n"
21042 "layout(location=0) in vec4 x;\n"
21043 "layout(location=1) in vec3 y1;\n"
21044 "layout(location=1, component=3) in float y2;\n"
21045 "layout(location=2) in vec4 z;\n"
21046 "out gl_PerVertex {\n"
21047 " vec4 gl_Position;\n"
21048 "};\n"
21049 "void main(){\n"
21050 " gl_Position = x + vec4(y1, y2) + z;\n"
21051 "}\n";
21052 char const *fsSource =
21053 "#version 450\n"
21054 "\n"
21055 "layout(location=0) out vec4 color;\n"
21056 "void main(){\n"
21057 " color = vec4(1);\n"
21058 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021059
21060 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21061 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21062
21063 VkPipelineObj pipe(m_device);
21064 pipe.AddColorAttachment();
21065 pipe.AddShader(&vs);
21066 pipe.AddShader(&fs);
21067
21068 pipe.AddVertexInputBindings(&input_binding, 1);
21069 pipe.AddVertexInputAttribs(input_attribs, 3);
21070
21071 VkDescriptorSetObj descriptorSet(m_device);
21072 descriptorSet.AppendDummy();
21073 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21074
21075 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21076
21077 m_errorMonitor->VerifyNotFound();
21078}
21079
21080TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21081 m_errorMonitor->ExpectSuccess();
21082
21083 ASSERT_NO_FATAL_FAILURE(InitState());
21084 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21085
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021086 char const *vsSource =
21087 "#version 450\n"
21088 "out gl_PerVertex {\n"
21089 " vec4 gl_Position;\n"
21090 "};\n"
21091 "void main(){\n"
21092 " gl_Position = vec4(0);\n"
21093 "}\n";
21094 char const *fsSource =
21095 "#version 450\n"
21096 "\n"
21097 "layout(location=0) out vec4 color;\n"
21098 "void main(){\n"
21099 " color = vec4(1);\n"
21100 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021101
21102 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21103 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21104
21105 VkPipelineObj pipe(m_device);
21106 pipe.AddColorAttachment();
21107 pipe.AddShader(&vs);
21108 pipe.AddShader(&fs);
21109
21110 VkDescriptorSetObj descriptorSet(m_device);
21111 descriptorSet.AppendDummy();
21112 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21113
21114 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21115
21116 m_errorMonitor->VerifyNotFound();
21117}
21118
21119TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021120 TEST_DESCRIPTION(
21121 "Test that pipeline validation accepts the relaxed type matching rules "
21122 "set out in 14.1.3: fundamental type must match, and producer side must "
21123 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021124 m_errorMonitor->ExpectSuccess();
21125
21126 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21127
21128 ASSERT_NO_FATAL_FAILURE(InitState());
21129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21130
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021131 char const *vsSource =
21132 "#version 450\n"
21133 "out gl_PerVertex {\n"
21134 " vec4 gl_Position;\n"
21135 "};\n"
21136 "layout(location=0) out vec3 x;\n"
21137 "layout(location=1) out ivec3 y;\n"
21138 "layout(location=2) out vec3 z;\n"
21139 "void main(){\n"
21140 " gl_Position = vec4(0);\n"
21141 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21142 "}\n";
21143 char const *fsSource =
21144 "#version 450\n"
21145 "\n"
21146 "layout(location=0) out vec4 color;\n"
21147 "layout(location=0) in float x;\n"
21148 "layout(location=1) flat in int y;\n"
21149 "layout(location=2) in vec2 z;\n"
21150 "void main(){\n"
21151 " color = vec4(1 + x + y + z.x);\n"
21152 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021153
21154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21156
21157 VkPipelineObj pipe(m_device);
21158 pipe.AddColorAttachment();
21159 pipe.AddShader(&vs);
21160 pipe.AddShader(&fs);
21161
21162 VkDescriptorSetObj descriptorSet(m_device);
21163 descriptorSet.AppendDummy();
21164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21165
21166 VkResult err = VK_SUCCESS;
21167 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21168 ASSERT_VK_SUCCESS(err);
21169
21170 m_errorMonitor->VerifyNotFound();
21171}
21172
21173TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021174 TEST_DESCRIPTION(
21175 "Test that pipeline validation accepts per-vertex variables "
21176 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021177 m_errorMonitor->ExpectSuccess();
21178
21179 ASSERT_NO_FATAL_FAILURE(InitState());
21180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21181
21182 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021183 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021184 return;
21185 }
21186
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021187 char const *vsSource =
21188 "#version 450\n"
21189 "void main(){}\n";
21190 char const *tcsSource =
21191 "#version 450\n"
21192 "layout(location=0) out int x[];\n"
21193 "layout(vertices=3) out;\n"
21194 "void main(){\n"
21195 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21196 " gl_TessLevelInner[0] = 1;\n"
21197 " x[gl_InvocationID] = gl_InvocationID;\n"
21198 "}\n";
21199 char const *tesSource =
21200 "#version 450\n"
21201 "layout(triangles, equal_spacing, cw) in;\n"
21202 "layout(location=0) in int x[];\n"
21203 "out gl_PerVertex { vec4 gl_Position; };\n"
21204 "void main(){\n"
21205 " gl_Position.xyz = gl_TessCoord;\n"
21206 " gl_Position.w = x[0] + x[1] + x[2];\n"
21207 "}\n";
21208 char const *fsSource =
21209 "#version 450\n"
21210 "layout(location=0) out vec4 color;\n"
21211 "void main(){\n"
21212 " color = vec4(1);\n"
21213 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021214
21215 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21216 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21217 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21218 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21219
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021220 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21221 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021222
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021223 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021224
21225 VkPipelineObj pipe(m_device);
21226 pipe.SetInputAssembly(&iasci);
21227 pipe.SetTessellation(&tsci);
21228 pipe.AddColorAttachment();
21229 pipe.AddShader(&vs);
21230 pipe.AddShader(&tcs);
21231 pipe.AddShader(&tes);
21232 pipe.AddShader(&fs);
21233
21234 VkDescriptorSetObj descriptorSet(m_device);
21235 descriptorSet.AppendDummy();
21236 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21237
21238 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21239
21240 m_errorMonitor->VerifyNotFound();
21241}
21242
21243TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021244 TEST_DESCRIPTION(
21245 "Test that pipeline validation accepts a user-defined "
21246 "interface block passed into the geometry shader. This "
21247 "is interesting because the 'extra' array level is not "
21248 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021249 m_errorMonitor->ExpectSuccess();
21250
21251 ASSERT_NO_FATAL_FAILURE(InitState());
21252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21253
21254 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021255 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021256 return;
21257 }
21258
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021259 char const *vsSource =
21260 "#version 450\n"
21261 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21262 "void main(){\n"
21263 " vs_out.x = vec4(1);\n"
21264 "}\n";
21265 char const *gsSource =
21266 "#version 450\n"
21267 "layout(triangles) in;\n"
21268 "layout(triangle_strip, max_vertices=3) out;\n"
21269 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21270 "out gl_PerVertex { vec4 gl_Position; };\n"
21271 "void main() {\n"
21272 " gl_Position = gs_in[0].x;\n"
21273 " EmitVertex();\n"
21274 "}\n";
21275 char const *fsSource =
21276 "#version 450\n"
21277 "layout(location=0) out vec4 color;\n"
21278 "void main(){\n"
21279 " color = vec4(1);\n"
21280 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021281
21282 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21283 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21285
21286 VkPipelineObj pipe(m_device);
21287 pipe.AddColorAttachment();
21288 pipe.AddShader(&vs);
21289 pipe.AddShader(&gs);
21290 pipe.AddShader(&fs);
21291
21292 VkDescriptorSetObj descriptorSet(m_device);
21293 descriptorSet.AppendDummy();
21294 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21295
21296 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21297
21298 m_errorMonitor->VerifyNotFound();
21299}
21300
21301TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021302 TEST_DESCRIPTION(
21303 "Test that pipeline validation accepts basic use of 64bit vertex "
21304 "attributes. This is interesting because they consume multiple "
21305 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021306 m_errorMonitor->ExpectSuccess();
21307
21308 ASSERT_NO_FATAL_FAILURE(InitState());
21309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21310
21311 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021312 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021313 return;
21314 }
21315
21316 VkVertexInputBindingDescription input_bindings[1];
21317 memset(input_bindings, 0, sizeof(input_bindings));
21318
21319 VkVertexInputAttributeDescription input_attribs[4];
21320 memset(input_attribs, 0, sizeof(input_attribs));
21321 input_attribs[0].location = 0;
21322 input_attribs[0].offset = 0;
21323 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21324 input_attribs[1].location = 2;
21325 input_attribs[1].offset = 32;
21326 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21327 input_attribs[2].location = 4;
21328 input_attribs[2].offset = 64;
21329 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21330 input_attribs[3].location = 6;
21331 input_attribs[3].offset = 96;
21332 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21333
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021334 char const *vsSource =
21335 "#version 450\n"
21336 "\n"
21337 "layout(location=0) in dmat4 x;\n"
21338 "out gl_PerVertex {\n"
21339 " vec4 gl_Position;\n"
21340 "};\n"
21341 "void main(){\n"
21342 " gl_Position = vec4(x[0][0]);\n"
21343 "}\n";
21344 char const *fsSource =
21345 "#version 450\n"
21346 "\n"
21347 "layout(location=0) out vec4 color;\n"
21348 "void main(){\n"
21349 " color = vec4(1);\n"
21350 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021351
21352 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21353 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21354
21355 VkPipelineObj pipe(m_device);
21356 pipe.AddColorAttachment();
21357 pipe.AddShader(&vs);
21358 pipe.AddShader(&fs);
21359
21360 pipe.AddVertexInputBindings(input_bindings, 1);
21361 pipe.AddVertexInputAttribs(input_attribs, 4);
21362
21363 VkDescriptorSetObj descriptorSet(m_device);
21364 descriptorSet.AppendDummy();
21365 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21366
21367 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21368
21369 m_errorMonitor->VerifyNotFound();
21370}
21371
21372TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21373 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21374 m_errorMonitor->ExpectSuccess();
21375
21376 ASSERT_NO_FATAL_FAILURE(InitState());
21377
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021378 char const *vsSource =
21379 "#version 450\n"
21380 "\n"
21381 "out gl_PerVertex {\n"
21382 " vec4 gl_Position;\n"
21383 "};\n"
21384 "void main(){\n"
21385 " gl_Position = vec4(1);\n"
21386 "}\n";
21387 char const *fsSource =
21388 "#version 450\n"
21389 "\n"
21390 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21391 "layout(location=0) out vec4 color;\n"
21392 "void main() {\n"
21393 " color = subpassLoad(x);\n"
21394 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021395
21396 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21397 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21398
21399 VkPipelineObj pipe(m_device);
21400 pipe.AddShader(&vs);
21401 pipe.AddShader(&fs);
21402 pipe.AddColorAttachment();
21403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21404
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021405 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21406 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021407 VkDescriptorSetLayout dsl;
21408 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21409 ASSERT_VK_SUCCESS(err);
21410
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021411 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021412 VkPipelineLayout pl;
21413 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21414 ASSERT_VK_SUCCESS(err);
21415
21416 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021417 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21418 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21419 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21420 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21421 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 -060021422 };
21423 VkAttachmentReference color = {
21424 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21425 };
21426 VkAttachmentReference input = {
21427 1, VK_IMAGE_LAYOUT_GENERAL,
21428 };
21429
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021430 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021431
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021432 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021433 VkRenderPass rp;
21434 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21435 ASSERT_VK_SUCCESS(err);
21436
21437 // should be OK. would go wrong here if it's going to...
21438 pipe.CreateVKPipeline(pl, rp);
21439
21440 m_errorMonitor->VerifyNotFound();
21441
21442 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21443 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21444 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21445}
21446
21447TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021448 TEST_DESCRIPTION(
21449 "Test that pipeline validation accepts a compute pipeline which declares a "
21450 "descriptor-backed resource which is not provided, but the shader does not "
21451 "statically use it. This is interesting because it requires compute pipelines "
21452 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021453 m_errorMonitor->ExpectSuccess();
21454
21455 ASSERT_NO_FATAL_FAILURE(InitState());
21456
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021457 char const *csSource =
21458 "#version 450\n"
21459 "\n"
21460 "layout(local_size_x=1) in;\n"
21461 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21462 "void main(){\n"
21463 " // x is not used.\n"
21464 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021465
21466 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21467
21468 VkDescriptorSetObj descriptorSet(m_device);
21469 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21470
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021471 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21472 nullptr,
21473 0,
21474 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21475 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21476 descriptorSet.GetPipelineLayout(),
21477 VK_NULL_HANDLE,
21478 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021479
21480 VkPipeline pipe;
21481 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21482
21483 m_errorMonitor->VerifyNotFound();
21484
21485 if (err == VK_SUCCESS) {
21486 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21487 }
21488}
21489
21490TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021491 TEST_DESCRIPTION(
21492 "Test that pipeline validation accepts a shader consuming only the "
21493 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021494 m_errorMonitor->ExpectSuccess();
21495
21496 ASSERT_NO_FATAL_FAILURE(InitState());
21497
21498 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021499 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21500 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21501 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021502 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021503 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021504 VkDescriptorSetLayout dsl;
21505 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21506 ASSERT_VK_SUCCESS(err);
21507
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021508 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021509 VkPipelineLayout pl;
21510 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21511 ASSERT_VK_SUCCESS(err);
21512
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021513 char const *csSource =
21514 "#version 450\n"
21515 "\n"
21516 "layout(local_size_x=1) in;\n"
21517 "layout(set=0, binding=0) uniform sampler s;\n"
21518 "layout(set=0, binding=1) uniform texture2D t;\n"
21519 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21520 "void main() {\n"
21521 " x = texture(sampler2D(t, s), vec2(0));\n"
21522 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021523 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21524
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021525 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21526 nullptr,
21527 0,
21528 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21529 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21530 pl,
21531 VK_NULL_HANDLE,
21532 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021533
21534 VkPipeline pipe;
21535 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21536
21537 m_errorMonitor->VerifyNotFound();
21538
21539 if (err == VK_SUCCESS) {
21540 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21541 }
21542
21543 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21544 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21545}
21546
21547TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021548 TEST_DESCRIPTION(
21549 "Test that pipeline validation accepts a shader consuming only the "
21550 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021551 m_errorMonitor->ExpectSuccess();
21552
21553 ASSERT_NO_FATAL_FAILURE(InitState());
21554
21555 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021556 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21557 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21558 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021559 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021560 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021561 VkDescriptorSetLayout dsl;
21562 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21563 ASSERT_VK_SUCCESS(err);
21564
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021565 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021566 VkPipelineLayout pl;
21567 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21568 ASSERT_VK_SUCCESS(err);
21569
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021570 char const *csSource =
21571 "#version 450\n"
21572 "\n"
21573 "layout(local_size_x=1) in;\n"
21574 "layout(set=0, binding=0) uniform texture2D t;\n"
21575 "layout(set=0, binding=1) uniform sampler s;\n"
21576 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21577 "void main() {\n"
21578 " x = texture(sampler2D(t, s), vec2(0));\n"
21579 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021580 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21581
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021582 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21583 nullptr,
21584 0,
21585 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21586 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21587 pl,
21588 VK_NULL_HANDLE,
21589 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021590
21591 VkPipeline pipe;
21592 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21593
21594 m_errorMonitor->VerifyNotFound();
21595
21596 if (err == VK_SUCCESS) {
21597 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21598 }
21599
21600 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21601 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21602}
21603
21604TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021605 TEST_DESCRIPTION(
21606 "Test that pipeline validation accepts a shader consuming "
21607 "both the sampler and the image of a combined image+sampler "
21608 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021609 m_errorMonitor->ExpectSuccess();
21610
21611 ASSERT_NO_FATAL_FAILURE(InitState());
21612
21613 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021614 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21615 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021616 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021617 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021618 VkDescriptorSetLayout dsl;
21619 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21620 ASSERT_VK_SUCCESS(err);
21621
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021622 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021623 VkPipelineLayout pl;
21624 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21625 ASSERT_VK_SUCCESS(err);
21626
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021627 char const *csSource =
21628 "#version 450\n"
21629 "\n"
21630 "layout(local_size_x=1) in;\n"
21631 "layout(set=0, binding=0) uniform texture2D t;\n"
21632 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
21633 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
21634 "void main() {\n"
21635 " x = texture(sampler2D(t, s), vec2(0));\n"
21636 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021637 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21638
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021639 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21640 nullptr,
21641 0,
21642 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21643 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21644 pl,
21645 VK_NULL_HANDLE,
21646 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021647
21648 VkPipeline pipe;
21649 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21650
21651 m_errorMonitor->VerifyNotFound();
21652
21653 if (err == VK_SUCCESS) {
21654 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21655 }
21656
21657 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21658 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21659}
21660
21661TEST_F(VkPositiveLayerTest, ValidStructPNext) {
21662 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
21663
21664 ASSERT_NO_FATAL_FAILURE(InitState());
21665
21666 // Positive test to check parameter_validation and unique_objects support
21667 // for NV_dedicated_allocation
21668 uint32_t extension_count = 0;
21669 bool supports_nv_dedicated_allocation = false;
21670 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
21671 ASSERT_VK_SUCCESS(err);
21672
21673 if (extension_count > 0) {
21674 std::vector<VkExtensionProperties> available_extensions(extension_count);
21675
21676 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
21677 ASSERT_VK_SUCCESS(err);
21678
21679 for (const auto &extension_props : available_extensions) {
21680 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
21681 supports_nv_dedicated_allocation = true;
21682 }
21683 }
21684 }
21685
21686 if (supports_nv_dedicated_allocation) {
21687 m_errorMonitor->ExpectSuccess();
21688
21689 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
21690 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
21691 dedicated_buffer_create_info.pNext = nullptr;
21692 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
21693
21694 uint32_t queue_family_index = 0;
21695 VkBufferCreateInfo buffer_create_info = {};
21696 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21697 buffer_create_info.pNext = &dedicated_buffer_create_info;
21698 buffer_create_info.size = 1024;
21699 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
21700 buffer_create_info.queueFamilyIndexCount = 1;
21701 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
21702
21703 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070021704 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021705 ASSERT_VK_SUCCESS(err);
21706
21707 VkMemoryRequirements memory_reqs;
21708 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
21709
21710 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
21711 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
21712 dedicated_memory_info.pNext = nullptr;
21713 dedicated_memory_info.buffer = buffer;
21714 dedicated_memory_info.image = VK_NULL_HANDLE;
21715
21716 VkMemoryAllocateInfo memory_info = {};
21717 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21718 memory_info.pNext = &dedicated_memory_info;
21719 memory_info.allocationSize = memory_reqs.size;
21720
21721 bool pass;
21722 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
21723 ASSERT_TRUE(pass);
21724
21725 VkDeviceMemory buffer_memory;
21726 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
21727 ASSERT_VK_SUCCESS(err);
21728
21729 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
21730 ASSERT_VK_SUCCESS(err);
21731
21732 vkDestroyBuffer(m_device->device(), buffer, NULL);
21733 vkFreeMemory(m_device->device(), buffer_memory, NULL);
21734
21735 m_errorMonitor->VerifyNotFound();
21736 }
21737}
21738
21739TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
21740 VkResult err;
21741
21742 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
21743
21744 ASSERT_NO_FATAL_FAILURE(InitState());
21745 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21746
21747 std::vector<const char *> device_extension_names;
21748 auto features = m_device->phy().features();
21749 // Artificially disable support for non-solid fill modes
21750 features.fillModeNonSolid = false;
21751 // The sacrificial device object
21752 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
21753
21754 VkRenderpassObj render_pass(&test_device);
21755
21756 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21757 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21758 pipeline_layout_ci.setLayoutCount = 0;
21759 pipeline_layout_ci.pSetLayouts = NULL;
21760
21761 VkPipelineLayout pipeline_layout;
21762 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21763 ASSERT_VK_SUCCESS(err);
21764
21765 VkPipelineRasterizationStateCreateInfo rs_ci = {};
21766 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
21767 rs_ci.pNext = nullptr;
21768 rs_ci.lineWidth = 1.0f;
21769 rs_ci.rasterizerDiscardEnable = true;
21770
21771 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
21772 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21773
21774 // Set polygonMode=FILL. No error is expected
21775 m_errorMonitor->ExpectSuccess();
21776 {
21777 VkPipelineObj pipe(&test_device);
21778 pipe.AddShader(&vs);
21779 pipe.AddShader(&fs);
21780 pipe.AddColorAttachment();
21781 // Set polygonMode to a good value
21782 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
21783 pipe.SetRasterization(&rs_ci);
21784 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
21785 }
21786 m_errorMonitor->VerifyNotFound();
21787
21788 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
21789}
21790
21791TEST_F(VkPositiveLayerTest, ValidPushConstants) {
21792 VkResult err;
21793 ASSERT_NO_FATAL_FAILURE(InitState());
21794 ASSERT_NO_FATAL_FAILURE(InitViewport());
21795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21796
21797 VkPipelineLayout pipeline_layout;
21798 VkPushConstantRange pc_range = {};
21799 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21800 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21801 pipeline_layout_ci.pushConstantRangeCount = 1;
21802 pipeline_layout_ci.pPushConstantRanges = &pc_range;
21803
21804 //
21805 // Check for invalid push constant ranges in pipeline layouts.
21806 //
21807 struct PipelineLayoutTestCase {
21808 VkPushConstantRange const range;
21809 char const *msg;
21810 };
21811
21812 // Check for overlapping ranges
21813 const uint32_t ranges_per_test = 5;
21814 struct OverlappingRangeTestCase {
21815 VkPushConstantRange const ranges[ranges_per_test];
21816 char const *msg;
21817 };
21818
21819 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021820 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
21821 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
21822 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
21823 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
21824 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
21825 ""},
21826 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
21827 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
21828 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
21829 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
21830 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
21831 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021832 for (const auto &iter : overlapping_range_tests_pos) {
21833 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
21834 m_errorMonitor->ExpectSuccess();
21835 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21836 m_errorMonitor->VerifyNotFound();
21837 if (VK_SUCCESS == err) {
21838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21839 }
21840 }
21841
21842 //
21843 // CmdPushConstants tests
21844 //
21845 const uint8_t dummy_values[100] = {};
21846
Tony Barbour552f6c02016-12-21 14:34:07 -070021847 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021848
21849 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021850 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
21851 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
21852 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
21853 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
21854 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
21855 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021856
21857 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
21858 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021859 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
21860 {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 -060021861 };
21862
21863 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
21864 pipeline_layout_ci.pPushConstantRanges = pc_range4;
21865 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21866 ASSERT_VK_SUCCESS(err);
21867 for (const auto &iter : cmd_overlap_tests_pos) {
21868 m_errorMonitor->ExpectSuccess();
21869 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021870 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021871 m_errorMonitor->VerifyNotFound();
21872 }
21873 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21874
Tony Barbour552f6c02016-12-21 14:34:07 -070021875 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021876}
21877
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021878#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021879TEST_F(VkPositiveLayerTest, LongFenceChain)
21880{
21881 m_errorMonitor->ExpectSuccess();
21882
21883 ASSERT_NO_FATAL_FAILURE(InitState());
21884 VkResult err;
21885
21886 std::vector<VkFence> fences;
21887
21888 const int chainLength = 32768;
21889
21890 for (int i = 0; i < chainLength; i++) {
21891 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
21892 VkFence fence;
21893 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21894 ASSERT_VK_SUCCESS(err);
21895
21896 fences.push_back(fence);
21897
21898 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
21899 0, nullptr, 0, nullptr };
21900 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21901 ASSERT_VK_SUCCESS(err);
21902
21903 }
21904
21905 // BOOM, stack overflow.
21906 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
21907
21908 for (auto fence : fences)
21909 vkDestroyFence(m_device->device(), fence, nullptr);
21910
21911 m_errorMonitor->VerifyNotFound();
21912}
21913#endif
21914
Cody Northrop1242dfd2016-07-13 17:24:59 -060021915#if defined(ANDROID) && defined(VALIDATION_APK)
21916static bool initialized = false;
21917static bool active = false;
21918
21919// Convert Intents to argv
21920// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021921std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021922 std::vector<std::string> args;
21923 JavaVM &vm = *app.activity->vm;
21924 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021925 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021926
21927 JNIEnv &env = *p_env;
21928 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021929 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021930 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021931 jmethodID get_string_extra_method =
21932 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021933 jvalue get_string_extra_args;
21934 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021935 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060021936
21937 std::string args_str;
21938 if (extra_str) {
21939 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
21940 args_str = extra_utf;
21941 env.ReleaseStringUTFChars(extra_str, extra_utf);
21942 env.DeleteLocalRef(extra_str);
21943 }
21944
21945 env.DeleteLocalRef(get_string_extra_args.l);
21946 env.DeleteLocalRef(intent);
21947 vm.DetachCurrentThread();
21948
21949 // split args_str
21950 std::stringstream ss(args_str);
21951 std::string arg;
21952 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021953 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021954 }
21955
21956 return args;
21957}
21958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021959static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021961static void processCommand(struct android_app *app, int32_t cmd) {
21962 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021963 case APP_CMD_INIT_WINDOW: {
21964 if (app->window) {
21965 initialized = true;
21966 }
21967 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021968 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021969 case APP_CMD_GAINED_FOCUS: {
21970 active = true;
21971 break;
21972 }
21973 case APP_CMD_LOST_FOCUS: {
21974 active = false;
21975 break;
21976 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021977 }
21978}
21979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021980void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021981 app_dummy();
21982
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021983 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060021984
21985 int vulkanSupport = InitVulkan();
21986 if (vulkanSupport == 0) {
21987 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
21988 return;
21989 }
21990
21991 app->onAppCmd = processCommand;
21992 app->onInputEvent = processInput;
21993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021994 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021995 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021996 struct android_poll_source *source;
21997 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021998 if (source) {
21999 source->process(app, source);
22000 }
22001
22002 if (app->destroyRequested != 0) {
22003 VkTestFramework::Finish();
22004 return;
22005 }
22006 }
22007
22008 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022009 // Use the following key to send arguments to gtest, i.e.
22010 // --es args "--gtest_filter=-VkLayerTest.foo"
22011 const char key[] = "args";
22012 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022014 std::string filter = "";
22015 if (args.size() > 0) {
22016 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22017 filter += args[0];
22018 } else {
22019 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22020 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022022 int argc = 2;
22023 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22024 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022025
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022026 // Route output to files until we can override the gtest output
22027 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22028 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022030 ::testing::InitGoogleTest(&argc, argv);
22031 VkTestFramework::InitArgs(&argc, argv);
22032 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022034 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022036 if (result != 0) {
22037 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22038 } else {
22039 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22040 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022042 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022043
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022044 fclose(stdout);
22045 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022047 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022049 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022050 }
22051 }
22052}
22053#endif
22054
Tony Barbour300a6082015-04-07 13:44:53 -060022055int main(int argc, char **argv) {
22056 int result;
22057
Cody Northrop8e54a402016-03-08 22:25:52 -070022058#ifdef ANDROID
22059 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022060 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022061#endif
22062
Tony Barbour300a6082015-04-07 13:44:53 -060022063 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022064 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022065
22066 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22067
22068 result = RUN_ALL_TESTS();
22069
Tony Barbour6918cd52015-04-09 12:58:51 -060022070 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022071 return result;
22072}