blob: c4c3c2943c332d216c169f9cbec3cfc71d77ebe0 [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");
Ian Elliotte48a1382016-04-28 14:22:58 -0600376 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700377 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600378
Ian Elliott2c1daf52016-05-12 09:41:46 -0600379 if (m_enableWSI) {
380 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
381 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
382#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
383#if defined(VK_USE_PLATFORM_ANDROID_KHR)
384 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700385#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600386#if defined(VK_USE_PLATFORM_MIR_KHR)
387 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700388#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600389#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
390 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700391#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600392#if defined(VK_USE_PLATFORM_WIN32_KHR)
393 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700394#endif // VK_USE_PLATFORM_WIN32_KHR
395#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600396#if defined(VK_USE_PLATFORM_XCB_KHR)
397 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
398#elif defined(VK_USE_PLATFORM_XLIB_KHR)
399 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700400#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600401 }
402
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600404 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800405 this->app_info.pApplicationName = "layer_tests";
406 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600407 this->app_info.pEngineName = "unittest";
408 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600409 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600410
Tony Barbour15524c32015-04-29 17:34:29 -0600411 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600412 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600413 }
414
415 virtual void TearDown() {
416 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600417 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600418 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600419 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600420
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600421 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600422};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600424void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 // Create identity matrix
426 int i;
427 struct vktriangle_vs_uniform data;
428
429 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700430 glm::mat4 View = glm::mat4(1.0f);
431 glm::mat4 Model = glm::mat4(1.0f);
432 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435
436 memcpy(&data.mvp, &MVP[0][0], matrixSize);
437
Karl Schultz6addd812016-02-02 17:17:23 -0700438 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600439 {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 -0500440 };
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 data.position[i][0] = tri_data[i].posX;
444 data.position[i][1] = tri_data[i].posY;
445 data.position[i][2] = tri_data[i].posZ;
446 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700447 data.color[i][0] = tri_data[i].r;
448 data.color[i][1] = tri_data[i].g;
449 data.color[i][2] = tri_data[i].b;
450 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451 }
452
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 ASSERT_NO_FATAL_FAILURE(InitViewport());
454
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200455 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
456 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Karl Schultz6addd812016-02-02 17:17:23 -0700458 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460
461 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800462 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500463 pipelineobj.AddShader(&vs);
464 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600465 if (failMask & BsoFailLineWidth) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
470 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600471 }
472 if (failMask & BsoFailDepthBias) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600475 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600476 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600477 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600479 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700480 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700481 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600482 if (failMask & BsoFailViewport) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
484 }
485 if (failMask & BsoFailScissor) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
487 }
488 if (failMask & BsoFailBlend) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600490 VkPipelineColorBlendAttachmentState att_state = {};
491 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
492 att_state.blendEnable = VK_TRUE;
493 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 }
495 if (failMask & BsoFailDepthBounds) {
496 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
497 }
498 if (failMask & BsoFailStencilReadMask) {
499 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
500 }
501 if (failMask & BsoFailStencilWriteMask) {
502 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
503 }
504 if (failMask & BsoFailStencilReference) {
505 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
508 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600509 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510
511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700512 m_commandBuffer->BeginCommandBuffer();
513 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
Tony Barbourfe3351b2015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
517 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600518 if (failMask & BsoFailIndexBuffer) {
519 // Use DrawIndexed w/o an index buffer bound
520 DrawIndexed(3, 1, 0, 0, 0);
521 } else {
522 Draw(3, 1, 0, 0);
523 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500524
Mark Muellerd4914412016-06-13 17:52:06 -0600525 if (failMask & BsoFailCmdClearAttachments) {
526 VkClearAttachment color_attachment = {};
527 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700528 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600529 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
530
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600531 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600532 }
533
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700535 m_commandBuffer->EndRenderPass();
536 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600537 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538}
539
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600540void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
541 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600543 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600545 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 }
547
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800548 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700549 // Make sure depthWriteEnable is set so that Depth fail test will work
550 // correctly
551 // Make sure stencilTestEnable is set so that Stencil fail test will work
552 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600553 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800554 stencil.failOp = VK_STENCIL_OP_KEEP;
555 stencil.passOp = VK_STENCIL_OP_KEEP;
556 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
557 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600558
559 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
560 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600561 ds_ci.pNext = NULL;
562 ds_ci.depthTestEnable = VK_FALSE;
563 ds_ci.depthWriteEnable = VK_TRUE;
564 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
565 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600566 if (failMask & BsoFailDepthBounds) {
567 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600568 ds_ci.maxDepthBounds = 0.0f;
569 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600571 ds_ci.stencilTestEnable = VK_TRUE;
572 ds_ci.front = stencil;
573 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600574
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600575 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600576 pipelineobj.SetViewport(m_viewports);
577 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800578 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600579 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800581 commandBuffer->BindPipeline(pipelineobj);
582 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500583}
584
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600585class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700586 public:
587 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600588};
589
Ian Elliott2c1daf52016-05-12 09:41:46 -0600590class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700591 public:
592 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600594};
595
Mark Muellerdfe37552016-07-07 14:47:42 -0600596class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700597 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 enum eTestEnFlags {
599 eDoubleDelete,
600 eInvalidDeviceOffset,
601 eInvalidMemoryOffset,
602 eBindNullBuffer,
603 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600604 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600605 };
606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600608
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600609 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
610 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600611 return true;
612 }
613 VkDeviceSize offset_limit = 0;
614 if (eInvalidMemoryOffset == aTestFlag) {
615 VkBuffer vulkanBuffer;
616 VkBufferCreateInfo buffer_create_info = {};
617 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
618 buffer_create_info.size = 32;
619 buffer_create_info.usage = aBufferUsage;
620
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600622 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
626 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
628 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600633 }
634 if (eOffsetAlignment < offset_limit) {
635 return true;
636 }
637 return false;
638 }
639
640 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
642 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 if (eBindNullBuffer == aTestFlag) {
644 VulkanMemory = 0;
645 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
646 } else {
647 VkBufferCreateInfo buffer_create_info = {};
648 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
649 buffer_create_info.size = 32;
650 buffer_create_info.usage = aBufferUsage;
651
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600653
654 CreateCurrent = true;
655
656 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658
659 VkMemoryAllocateInfo memory_allocate_info = {};
660 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
661 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
663 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 if (!pass) {
665 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
666 return;
667 }
668
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600669 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600670 AllocateCurrent = true;
671 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
673 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 BoundCurrent = true;
675
676 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
677 }
678 }
679
680 ~VkBufferTest() {
681 if (CreateCurrent) {
682 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
683 }
684 if (AllocateCurrent) {
685 if (InvalidDeleteEn) {
686 union {
687 VkDeviceMemory device_memory;
688 unsigned long long index_access;
689 } bad_index;
690
691 bad_index.device_memory = VulkanMemory;
692 bad_index.index_access++;
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 }
696 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
697 }
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
704 void TestDoubleDestroy() {
705 // Destroy the buffer but leave the flag set, which will cause
706 // the buffer to be destroyed again in the destructor.
707 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
708 }
709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700710 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600711 bool AllocateCurrent;
712 bool BoundCurrent;
713 bool CreateCurrent;
714 bool InvalidDeleteEn;
715
716 VkBuffer VulkanBuffer;
717 VkDevice VulkanDevice;
718 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719};
720
721class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700722 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700725 : BoundCurrent(false),
726 AttributeCount(aAttributeCount),
727 BindingCount(aBindingCount),
728 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600729 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600730 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
731 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
735 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600736
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
738 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
739 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
740 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
741 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600742
743 unsigned i = 0;
744 do {
745 VertexInputAttributeDescription[i].binding = BindId;
746 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
748 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600749 i++;
750 } while (AttributeCount < i);
751
752 i = 0;
753 do {
754 VertexInputBindingDescription[i].binding = BindId;
755 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600756 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600757 i++;
758 } while (BindingCount < i);
759 }
760
761 ~VkVerticesObj() {
762 if (VertexInputAttributeDescription) {
763 delete[] VertexInputAttributeDescription;
764 }
765 if (VertexInputBindingDescription) {
766 delete[] VertexInputBindingDescription;
767 }
768 }
769
770 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
772 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 return true;
774 }
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600777 VkDeviceSize *offsetList;
778 unsigned offsetCount;
779
780 if (aOffsetCount) {
781 offsetList = aOffsetList;
782 offsetCount = aOffsetCount;
783 } else {
784 offsetList = new VkDeviceSize[1]();
785 offsetCount = 1;
786 }
787
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600788 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600789 BoundCurrent = true;
790
791 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600793 }
794 }
795
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700796 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 static uint32_t BindIdGenerator;
798
799 bool BoundCurrent;
800 unsigned AttributeCount;
801 unsigned BindingCount;
802 uint32_t BindId;
803
804 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
805 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
806 VkVertexInputBindingDescription *VertexInputBindingDescription;
807 VkConstantBufferObj VulkanMemoryBuffer;
808};
809
810uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500811// ********************************************************************************************************************
812// ********************************************************************************************************************
813// ********************************************************************************************************************
814// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700816 TEST_DESCRIPTION(
817 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
818 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600823 // Specify NULL for a pointer to a handle
824 // Expected to trigger an error with
825 // parameter_validation::validate_required_pointer
826 vkGetPhysicalDeviceFeatures(gpu(), NULL);
827 m_errorMonitor->VerifyFound();
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
830 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for pointer to array count
832 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600833 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify 0 for a required array count
838 // Expected to trigger an error with parameter_validation::validate_array
839 VkViewport view_port = {};
840 m_commandBuffer->SetViewport(0, 0, &view_port);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 // Specify NULL for a required array
845 // Expected to trigger an error with parameter_validation::validate_array
846 m_commandBuffer->SetViewport(0, 1, NULL);
847 m_errorMonitor->VerifyFound();
848
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600850 // Specify VK_NULL_HANDLE for a required handle
851 // Expected to trigger an error with
852 // parameter_validation::validate_required_handle
853 vkUnmapMemory(device(), VK_NULL_HANDLE);
854 m_errorMonitor->VerifyFound();
855
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
857 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 // Specify VK_NULL_HANDLE for a required handle array entry
859 // Expected to trigger an error with
860 // parameter_validation::validate_required_handle_array
861 VkFence fence = VK_NULL_HANDLE;
862 vkResetFences(device(), 1, &fence);
863 m_errorMonitor->VerifyFound();
864
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600866 // Specify NULL for a required struct pointer
867 // Expected to trigger an error with
868 // parameter_validation::validate_struct_type
869 VkDeviceMemory memory = VK_NULL_HANDLE;
870 vkAllocateMemory(device(), NULL, NULL, &memory);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify 0 for a required VkFlags parameter
875 // Expected to trigger an error with parameter_validation::validate_flags
876 m_commandBuffer->SetStencilReference(0, 0);
877 m_errorMonitor->VerifyFound();
878
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600879 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 -0600880 // Specify 0 for a required VkFlags array entry
881 // Expected to trigger an error with
882 // parameter_validation::validate_flags_array
883 VkSemaphore semaphore = VK_NULL_HANDLE;
884 VkPipelineStageFlags stageFlags = 0;
885 VkSubmitInfo submitInfo = {};
886 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
887 submitInfo.waitSemaphoreCount = 1;
888 submitInfo.pWaitSemaphores = &semaphore;
889 submitInfo.pWaitDstStageMask = &stageFlags;
890 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
891 m_errorMonitor->VerifyFound();
892}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600893
Dustin Gravesfce74c02016-05-10 11:42:58 -0600894TEST_F(VkLayerTest, ReservedParameter) {
895 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
896
897 ASSERT_NO_FATAL_FAILURE(InitState());
898
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600900 // Specify 0 for a reserved VkFlags parameter
901 // Expected to trigger an error with
902 // parameter_validation::validate_reserved_flags
903 VkEvent event_handle = VK_NULL_HANDLE;
904 VkEventCreateInfo event_info = {};
905 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
906 event_info.flags = 1;
907 vkCreateEvent(device(), &event_info, NULL, &event_handle);
908 m_errorMonitor->VerifyFound();
909}
910
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600911TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700912 TEST_DESCRIPTION(
913 "Specify an invalid VkStructureType for a Vulkan "
914 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915
916 ASSERT_NO_FATAL_FAILURE(InitState());
917
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 // Zero struct memory, effectively setting sType to
920 // VK_STRUCTURE_TYPE_APPLICATION_INFO
921 // Expected to trigger an error with
922 // parameter_validation::validate_struct_type
923 VkMemoryAllocateInfo alloc_info = {};
924 VkDeviceMemory memory = VK_NULL_HANDLE;
925 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
926 m_errorMonitor->VerifyFound();
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type_array
933 VkSubmitInfo submit_info = {};
934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
935 m_errorMonitor->VerifyFound();
936}
937
938TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600945 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600946 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600947 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600948 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600949 // Zero-initialization will provide the correct sType
950 VkApplicationInfo app_info = {};
951 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
952 event_alloc_info.pNext = &app_info;
953 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
954 m_errorMonitor->VerifyFound();
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
957 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600958 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
959 // a function that has allowed pNext structure types and specify
960 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600961 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600962 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600963 VkMemoryAllocateInfo memory_alloc_info = {};
964 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
965 memory_alloc_info.pNext = &app_info;
966 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600967 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
976 "does not fall within the begin..end "
977 "range of the core VkFormat "
978 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkFormat value
980 // Expected to trigger an error with
981 // parameter_validation::validate_ranged_enum
982 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600983 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600984 m_errorMonitor->VerifyFound();
985
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 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 -0600987 // Specify an invalid VkFlags bitmask value
988 // Expected to trigger an error with parameter_validation::validate_flags
989 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600990 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
991 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600992 m_errorMonitor->VerifyFound();
993
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600994 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 -0600995 // Specify an invalid VkFlags array entry
996 // Expected to trigger an error with
997 // parameter_validation::validate_flags_array
998 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600999 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001000 VkSubmitInfo submit_info = {};
1001 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1002 submit_info.waitSemaphoreCount = 1;
1003 submit_info.pWaitSemaphores = &semaphore;
1004 submit_info.pWaitDstStageMask = &stage_flags;
1005 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1006 m_errorMonitor->VerifyFound();
1007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001009 // Specify an invalid VkBool32 value
1010 // Expected to trigger a warning with
1011 // parameter_validation::validate_bool32
1012 VkSampler sampler = VK_NULL_HANDLE;
1013 VkSamplerCreateInfo sampler_info = {};
1014 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1015 sampler_info.pNext = NULL;
1016 sampler_info.magFilter = VK_FILTER_NEAREST;
1017 sampler_info.minFilter = VK_FILTER_NEAREST;
1018 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1019 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.mipLodBias = 1.0;
1023 sampler_info.maxAnisotropy = 1;
1024 sampler_info.compareEnable = VK_FALSE;
1025 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1026 sampler_info.minLod = 1.0;
1027 sampler_info.maxLod = 1.0;
1028 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1029 sampler_info.unnormalizedCoordinates = VK_FALSE;
1030 // Not VK_TRUE or VK_FALSE
1031 sampler_info.anisotropyEnable = 3;
1032 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1033 m_errorMonitor->VerifyFound();
1034}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035
1036TEST_F(VkLayerTest, FailedReturnValue) {
1037 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 // Find an unsupported image format
1042 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1044 VkFormat format = static_cast<VkFormat>(f);
1045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 unsupported = format;
1048 break;
1049 }
1050 }
1051
1052 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1054 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001055 // Specify an unsupported VkFormat value to generate a
1056 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1057 // Expected to trigger a warning from
1058 // parameter_validation::validate_result
1059 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1061 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1063 m_errorMonitor->VerifyFound();
1064 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001065}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066
1067TEST_F(VkLayerTest, UpdateBufferAlignment) {
1068 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
Tony Barbour552f6c02016-12-21 14:34:07 -07001077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1081 m_errorMonitor->VerifyFound();
1082
1083 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 // Introduce failure by using dataSize that is < 0
1089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is > 65536
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1098 m_errorMonitor->VerifyFound();
1099
Tony Barbour552f6c02016-12-21 14:34:07 -07001100 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101}
1102
1103TEST_F(VkLayerTest, FillBufferAlignment) {
1104 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1105
1106 ASSERT_NO_FATAL_FAILURE(InitState());
1107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
Tony Barbour552f6c02016-12-21 14:34:07 -07001112 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001113
1114 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1117 m_errorMonitor->VerifyFound();
1118
1119 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1122 m_errorMonitor->VerifyFound();
1123
1124 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
Tony Barbour552f6c02016-12-21 14:34:07 -07001129 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130}
Dustin Graves40f35822016-06-23 11:12:53 -06001131
Cortd889ff92016-07-27 09:51:27 -07001132TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1133 VkResult err;
1134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001135 TEST_DESCRIPTION(
1136 "Attempt to use a non-solid polygon fill mode in a "
1137 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001138
1139 ASSERT_NO_FATAL_FAILURE(InitState());
1140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1141
1142 std::vector<const char *> device_extension_names;
1143 auto features = m_device->phy().features();
1144 // Artificially disable support for non-solid fill modes
1145 features.fillModeNonSolid = false;
1146 // The sacrificial device object
1147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1148
1149 VkRenderpassObj render_pass(&test_device);
1150
1151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1153 pipeline_layout_ci.setLayoutCount = 0;
1154 pipeline_layout_ci.pSetLayouts = NULL;
1155
1156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001158 ASSERT_VK_SUCCESS(err);
1159
1160 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1161 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1162 rs_ci.pNext = nullptr;
1163 rs_ci.lineWidth = 1.0f;
1164 rs_ci.rasterizerDiscardEnable = true;
1165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1167 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001168
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001169 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1171 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001172 {
1173 VkPipelineObj pipe(&test_device);
1174 pipe.AddShader(&vs);
1175 pipe.AddShader(&fs);
1176 pipe.AddColorAttachment();
1177 // Introduce failure by setting unsupported polygon mode
1178 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1179 pipe.SetRasterization(&rs_ci);
1180 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1181 }
1182 m_errorMonitor->VerifyFound();
1183
1184 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1186 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001187 {
1188 VkPipelineObj pipe(&test_device);
1189 pipe.AddShader(&vs);
1190 pipe.AddShader(&fs);
1191 pipe.AddColorAttachment();
1192 // Introduce failure by setting unsupported polygon mode
1193 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1194 pipe.SetRasterization(&rs_ci);
1195 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1196 }
1197 m_errorMonitor->VerifyFound();
1198
Cortd889ff92016-07-27 09:51:27 -07001199 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1200}
1201
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001202#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001203TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001204{
1205 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206 VkFenceCreateInfo fenceInfo = {};
1207 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1208 fenceInfo.pNext = NULL;
1209 fenceInfo.flags = 0;
1210
Mike Weiblencce7ec72016-10-17 19:33:05 -06001211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001212
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001213 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001214
1215 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1216 vk_testing::Buffer buffer;
1217 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001244 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245}
1246
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001247TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001248{
1249 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001250 VkFenceCreateInfo fenceInfo = {};
1251 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1252 fenceInfo.pNext = NULL;
1253 fenceInfo.flags = 0;
1254
Mike Weiblencce7ec72016-10-17 19:33:05 -06001255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001256
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257 ASSERT_NO_FATAL_FAILURE(InitState());
1258 ASSERT_NO_FATAL_FAILURE(InitViewport());
1259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1260
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001263 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001264
1265 testFence.init(*m_device, fenceInfo);
1266
1267 // Bypass framework since it does the waits automatically
1268 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001269 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001270 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1271 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001272 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001273 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001274 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001275 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001277 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001278 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001279
1280 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001281 ASSERT_VK_SUCCESS( err );
1282
Jon Ashburnf19916e2016-01-11 13:12:43 -07001283 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 VkCommandBufferBeginInfo info = {};
1285 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1286 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001287 info.renderPass = VK_NULL_HANDLE;
1288 info.subpass = 0;
1289 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001290 info.occlusionQueryEnable = VK_FALSE;
1291 info.queryFlags = 0;
1292 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001293
1294 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001295 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001297 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001299#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001300
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001301TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1302 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1303
1304 ASSERT_NO_FATAL_FAILURE(InitState());
1305
1306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1307 VkBuffer buffer;
1308 VkBufferCreateInfo buf_info = {};
1309 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1310 buf_info.pNext = NULL;
1311 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1312 buf_info.size = 2048;
1313 buf_info.queueFamilyIndexCount = 0;
1314 buf_info.pQueueFamilyIndices = NULL;
1315 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1316 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1317 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1318 m_errorMonitor->VerifyFound();
1319
1320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1321 VkImage image;
1322 VkImageCreateInfo image_create_info = {};
1323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1324 image_create_info.pNext = NULL;
1325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1326 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1327 image_create_info.extent.width = 512;
1328 image_create_info.extent.height = 64;
1329 image_create_info.extent.depth = 1;
1330 image_create_info.mipLevels = 1;
1331 image_create_info.arrayLayers = 1;
1332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1334 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1336 image_create_info.queueFamilyIndexCount = 0;
1337 image_create_info.pQueueFamilyIndices = NULL;
1338 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1339 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1340 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1341 m_errorMonitor->VerifyFound();
1342}
1343
Dave Houlton829c0d82017-01-24 15:09:17 -07001344TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1345 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1346
1347 // Determine which device feature are available
1348 VkPhysicalDeviceFeatures available_features;
1349 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1350
1351 // Mask out device features we don't want
1352 VkPhysicalDeviceFeatures desired_features = available_features;
1353 desired_features.sparseResidencyImage2D = VK_FALSE;
1354 desired_features.sparseResidencyImage3D = VK_FALSE;
1355 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1356
1357 VkImage image = VK_NULL_HANDLE;
1358 VkResult result = VK_RESULT_MAX_ENUM;
1359 VkImageCreateInfo image_create_info = {};
1360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1361 image_create_info.pNext = NULL;
1362 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1363 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1364 image_create_info.extent.width = 512;
1365 image_create_info.extent.height = 1;
1366 image_create_info.extent.depth = 1;
1367 image_create_info.mipLevels = 1;
1368 image_create_info.arrayLayers = 1;
1369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1370 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1373 image_create_info.queueFamilyIndexCount = 0;
1374 image_create_info.pQueueFamilyIndices = NULL;
1375 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1376 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1377
1378 // 1D image w/ sparse residency is an error
1379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1380 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1381 m_errorMonitor->VerifyFound();
1382 if (VK_SUCCESS == result) {
1383 vkDestroyImage(m_device->device(), image, NULL);
1384 image = VK_NULL_HANDLE;
1385 }
1386
1387 // 2D image w/ sparse residency when feature isn't available
1388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1389 image_create_info.extent.height = 64;
1390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1391 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1392 m_errorMonitor->VerifyFound();
1393 if (VK_SUCCESS == result) {
1394 vkDestroyImage(m_device->device(), image, NULL);
1395 image = VK_NULL_HANDLE;
1396 }
1397
1398 // 3D image w/ sparse residency when feature isn't available
1399 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1400 image_create_info.extent.depth = 8;
1401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1402 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1403 m_errorMonitor->VerifyFound();
1404 if (VK_SUCCESS == result) {
1405 vkDestroyImage(m_device->device(), image, NULL);
1406 image = VK_NULL_HANDLE;
1407 }
1408}
1409
1410TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1411 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1412
1413 // Determine which device feature are available
1414 VkPhysicalDeviceFeatures available_features;
1415 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1416
1417 // These tests all require that the device support sparse residency for 2D images
1418 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1419 return;
1420 }
1421
1422 // Mask out device features we don't want
1423 VkPhysicalDeviceFeatures desired_features = available_features;
1424 desired_features.sparseResidency2Samples = VK_FALSE;
1425 desired_features.sparseResidency4Samples = VK_FALSE;
1426 desired_features.sparseResidency8Samples = VK_FALSE;
1427 desired_features.sparseResidency16Samples = VK_FALSE;
1428 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1429
1430 VkImage image = VK_NULL_HANDLE;
1431 VkResult result = VK_RESULT_MAX_ENUM;
1432 VkImageCreateInfo image_create_info = {};
1433 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1434 image_create_info.pNext = NULL;
1435 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1436 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1437 image_create_info.extent.width = 64;
1438 image_create_info.extent.height = 64;
1439 image_create_info.extent.depth = 1;
1440 image_create_info.mipLevels = 1;
1441 image_create_info.arrayLayers = 1;
1442 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1443 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1446 image_create_info.queueFamilyIndexCount = 0;
1447 image_create_info.pQueueFamilyIndices = NULL;
1448 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1449 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1450
1451 // 2D image w/ sparse residency and linear tiling is an error
1452 m_errorMonitor->SetDesiredFailureMsg(
1453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1455 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1456 m_errorMonitor->VerifyFound();
1457 if (VK_SUCCESS == result) {
1458 vkDestroyImage(m_device->device(), image, NULL);
1459 image = VK_NULL_HANDLE;
1460 }
1461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1462
1463 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1464 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1466 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1467 m_errorMonitor->VerifyFound();
1468 if (VK_SUCCESS == result) {
1469 vkDestroyImage(m_device->device(), image, NULL);
1470 image = VK_NULL_HANDLE;
1471 }
1472
1473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1475 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1476 m_errorMonitor->VerifyFound();
1477 if (VK_SUCCESS == result) {
1478 vkDestroyImage(m_device->device(), image, NULL);
1479 image = VK_NULL_HANDLE;
1480 }
1481
1482 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1484 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1485 m_errorMonitor->VerifyFound();
1486 if (VK_SUCCESS == result) {
1487 vkDestroyImage(m_device->device(), image, NULL);
1488 image = VK_NULL_HANDLE;
1489 }
1490
1491 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499}
1500
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001502 TEST_DESCRIPTION(
1503 "Create a buffer and image, allocate memory, and bind the "
1504 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001505 VkResult err;
1506 bool pass;
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508
Tobin Ehlis077ded32016-05-12 17:39:13 -06001509 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001510 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001511 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 VkDeviceMemory mem; // buffer will be bound first
1513 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001514 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001515 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001516
1517 VkBufferCreateInfo buf_info = {};
1518 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1519 buf_info.pNext = NULL;
1520 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1521 buf_info.size = 256;
1522 buf_info.queueFamilyIndexCount = 0;
1523 buf_info.pQueueFamilyIndices = NULL;
1524 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1525 buf_info.flags = 0;
1526 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1527 ASSERT_VK_SUCCESS(err);
1528
Tobin Ehlis077ded32016-05-12 17:39:13 -06001529 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001530
1531 VkImageCreateInfo image_create_info = {};
1532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1533 image_create_info.pNext = NULL;
1534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1535 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1536 image_create_info.extent.width = 64;
1537 image_create_info.extent.height = 64;
1538 image_create_info.extent.depth = 1;
1539 image_create_info.mipLevels = 1;
1540 image_create_info.arrayLayers = 1;
1541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001542 // Image tiling must be optimal to trigger error when aliasing linear buffer
1543 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001544 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1545 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1546 image_create_info.queueFamilyIndexCount = 0;
1547 image_create_info.pQueueFamilyIndices = NULL;
1548 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1549 image_create_info.flags = 0;
1550
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001553 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1554 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1557
1558 VkMemoryAllocateInfo alloc_info = {};
1559 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1560 alloc_info.pNext = NULL;
1561 alloc_info.memoryTypeIndex = 0;
1562 // Ensure memory is big enough for both bindings
1563 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001564 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1565 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001569 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570 return;
1571 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001572 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1573 ASSERT_VK_SUCCESS(err);
1574 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1575 ASSERT_VK_SUCCESS(err);
1576
Rene Lindsayd14f5572016-12-16 14:57:18 -07001577 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1578
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001580 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001581 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1582 m_errorMonitor->VerifyFound();
1583
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001584 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001585 // aliasing buffer2
1586 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1587 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001588 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001590 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001593 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 m_errorMonitor->VerifyFound();
1596
1597 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001598 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001599 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 vkFreeMemory(m_device->device(), mem, NULL);
1602 vkFreeMemory(m_device->device(), mem_img, NULL);
1603}
1604
Tobin Ehlis35372522016-05-12 08:32:31 -06001605TEST_F(VkLayerTest, InvalidMemoryMapping) {
1606 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1607 VkResult err;
1608 bool pass;
1609 ASSERT_NO_FATAL_FAILURE(InitState());
1610
1611 VkBuffer buffer;
1612 VkDeviceMemory mem;
1613 VkMemoryRequirements mem_reqs;
1614
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001615 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1616
Tobin Ehlis35372522016-05-12 08:32:31 -06001617 VkBufferCreateInfo buf_info = {};
1618 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1619 buf_info.pNext = NULL;
1620 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1621 buf_info.size = 256;
1622 buf_info.queueFamilyIndexCount = 0;
1623 buf_info.pQueueFamilyIndices = NULL;
1624 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1625 buf_info.flags = 0;
1626 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1627 ASSERT_VK_SUCCESS(err);
1628
1629 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1630 VkMemoryAllocateInfo alloc_info = {};
1631 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1632 alloc_info.pNext = NULL;
1633 alloc_info.memoryTypeIndex = 0;
1634
1635 // Ensure memory is big enough for both bindings
1636 static const VkDeviceSize allocation_size = 0x10000;
1637 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 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 -06001639 if (!pass) {
1640 vkDestroyBuffer(m_device->device(), buffer, NULL);
1641 return;
1642 }
1643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1644 ASSERT_VK_SUCCESS(err);
1645
1646 uint8_t *pData;
1647 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 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 -06001649 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1650 m_errorMonitor->VerifyFound();
1651 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001652 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001653 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1655 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1656 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001657 m_errorMonitor->VerifyFound();
1658
1659 // Unmap the memory to avoid re-map error
1660 vkUnmapMemory(m_device->device(), mem);
1661 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1663 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1664 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 m_errorMonitor->VerifyFound();
1666 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1668 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001669 m_errorMonitor->VerifyFound();
1670 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001672 vkUnmapMemory(m_device->device(), mem);
1673 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001674
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001676 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001677 ASSERT_VK_SUCCESS(err);
1678 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001679 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001681 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001683 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1684 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001685
Tobin Ehlis35372522016-05-12 08:32:31 -06001686 // Now flush range that oversteps mapped range
1687 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001688 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001689 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001690 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
1695
1696 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001701 mmr.size = VK_WHOLE_SIZE;
1702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001706#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001707 // Some platforms have an atomsize of 1 which makes the test meaningless
1708 if (atom_size > 3) {
1709 // Now with an offset NOT a multiple of the device limit
1710 vkUnmapMemory(m_device->device(), mem);
1711 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1712 ASSERT_VK_SUCCESS(err);
1713 mmr.offset = 3; // Not a multiple of atom_size
1714 mmr.size = VK_WHOLE_SIZE;
1715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1716 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1717 m_errorMonitor->VerifyFound();
1718
1719 // Now with a size NOT a multiple of the device limit
1720 vkUnmapMemory(m_device->device(), mem);
1721 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1722 ASSERT_VK_SUCCESS(err);
1723 mmr.offset = atom_size;
1724 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001729#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1731 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001732 if (!pass) {
1733 vkFreeMemory(m_device->device(), mem, NULL);
1734 vkDestroyBuffer(m_device->device(), buffer, NULL);
1735 return;
1736 }
1737 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1738 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1739
1740 vkDestroyBuffer(m_device->device(), buffer, NULL);
1741 vkFreeMemory(m_device->device(), mem, NULL);
1742}
1743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001745TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1746 VkResult err;
1747 bool pass;
1748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1750 // following declaration (which is temporarily being moved below):
1751 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001753 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001754 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001756 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001758
1759 ASSERT_NO_FATAL_FAILURE(InitState());
1760
Ian Elliott3f06ce52016-04-29 14:46:21 -06001761#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1762#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1763 // Use the functions from the VK_KHR_android_surface extension without
1764 // enabling that extension:
1765
1766 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001767 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1769 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001770 pass = (err != VK_SUCCESS);
1771 ASSERT_TRUE(pass);
1772 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001773#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001774
Ian Elliott3f06ce52016-04-29 14:46:21 -06001775#if defined(VK_USE_PLATFORM_MIR_KHR)
1776 // Use the functions from the VK_KHR_mir_surface extension without enabling
1777 // that extension:
1778
1779 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001780 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001782 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1783 pass = (err != VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785 m_errorMonitor->VerifyFound();
1786
1787 // Tell whether an mir_connection supports presentation:
1788 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1790 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001791 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001792#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001793
Ian Elliott3f06ce52016-04-29 14:46:21 -06001794#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1795 // Use the functions from the VK_KHR_wayland_surface extension without
1796 // enabling that extension:
1797
1798 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001799 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1801 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001802 pass = (err != VK_SUCCESS);
1803 ASSERT_TRUE(pass);
1804 m_errorMonitor->VerifyFound();
1805
1806 // Tell whether an wayland_display supports presentation:
1807 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1809 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001810 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001811#endif // VK_USE_PLATFORM_WAYLAND_KHR
1812#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001813
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001815 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1816 // TO NON-LINUX PLATFORMS:
1817 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001818 // Use the functions from the VK_KHR_win32_surface extension without
1819 // enabling that extension:
1820
1821 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001822 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1824 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001825 pass = (err != VK_SUCCESS);
1826 ASSERT_TRUE(pass);
1827 m_errorMonitor->VerifyFound();
1828
1829 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001831 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001832 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001833// Set this (for now, until all platforms are supported and tested):
1834#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001835#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001836#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001837 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1838 // TO NON-LINUX PLATFORMS:
1839 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001840#endif
1841#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001842 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1843 // that extension:
1844
1845 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001846 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001848 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1849 pass = (err != VK_SUCCESS);
1850 ASSERT_TRUE(pass);
1851 m_errorMonitor->VerifyFound();
1852
1853 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001854 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001855 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1857 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001859// Set this (for now, until all platforms are supported and tested):
1860#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001861#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001862
Ian Elliott12630812016-04-29 14:35:43 -06001863#if defined(VK_USE_PLATFORM_XLIB_KHR)
1864 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1865 // that extension:
1866
1867 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001868 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001870 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1871 pass = (err != VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873 m_errorMonitor->VerifyFound();
1874
1875 // Tell whether an Xlib VisualID supports presentation:
1876 Display *dpy = NULL;
1877 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001879 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1880 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001881// Set this (for now, until all platforms are supported and tested):
1882#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001883#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001885// Use the functions from the VK_KHR_surface extension without enabling
1886// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001887
Ian Elliott489eec02016-05-05 14:12:44 -06001888#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001889 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001891 vkDestroySurfaceKHR(instance(), surface, NULL);
1892 m_errorMonitor->VerifyFound();
1893
1894 // Check if surface supports presentation:
1895 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001897 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
1901
1902 // Check surface capabilities:
1903 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1905 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 pass = (err != VK_SUCCESS);
1907 ASSERT_TRUE(pass);
1908 m_errorMonitor->VerifyFound();
1909
1910 // Check surface formats:
1911 uint32_t format_count = 0;
1912 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1914 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001915 pass = (err != VK_SUCCESS);
1916 ASSERT_TRUE(pass);
1917 m_errorMonitor->VerifyFound();
1918
1919 // Check surface present modes:
1920 uint32_t present_mode_count = 0;
1921 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1923 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001927#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001928
Ian Elliott1c32c772016-04-28 14:47:13 -06001929 // Use the functions from the VK_KHR_swapchain extension without enabling
1930 // that extension:
1931
1932 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1935 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001937 pass = (err != VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1943 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 pass = (err != VK_SUCCESS);
1945 ASSERT_TRUE(pass);
1946 m_errorMonitor->VerifyFound();
1947
Chris Forbeseb7d5502016-09-13 18:19:21 +12001948 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1949 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1950 VkFence fence;
1951 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1952
Ian Elliott1c32c772016-04-28 14:47:13 -06001953 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001955 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001956 pass = (err != VK_SUCCESS);
1957 ASSERT_TRUE(pass);
1958 m_errorMonitor->VerifyFound();
1959
Chris Forbeseb7d5502016-09-13 18:19:21 +12001960 vkDestroyFence(m_device->device(), fence, nullptr);
1961
Ian Elliott1c32c772016-04-28 14:47:13 -06001962 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001963 //
1964 // NOTE: Currently can't test this because a real swapchain is needed (as
1965 // opposed to the fake one we created) in order for the layer to lookup the
1966 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001967
1968 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001970 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1971 m_errorMonitor->VerifyFound();
1972}
Chris Forbes09368e42016-10-13 11:59:22 +13001973#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001974
Karl Schultz6addd812016-02-02 17:17:23 -07001975TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1976 VkResult err;
1977 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1980 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001981
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001982 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001983
1984 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001985 VkImage image;
1986 VkDeviceMemory mem;
1987 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Karl Schultz6addd812016-02-02 17:17:23 -07001989 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1990 const int32_t tex_width = 32;
1991 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992
Tony Barboureb254902015-07-15 12:50:33 -06001993 VkImageCreateInfo image_create_info = {};
1994 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001995 image_create_info.pNext = NULL;
1996 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1997 image_create_info.format = tex_format;
1998 image_create_info.extent.width = tex_width;
1999 image_create_info.extent.height = tex_height;
2000 image_create_info.extent.depth = 1;
2001 image_create_info.mipLevels = 1;
2002 image_create_info.arrayLayers = 1;
2003 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2004 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2005 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2006 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002007 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002008
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002009 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002010 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002011 mem_alloc.pNext = NULL;
2012 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002013
Chia-I Wuf7458c52015-10-26 21:10:41 +08002014 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002015 ASSERT_VK_SUCCESS(err);
2016
Karl Schultz6addd812016-02-02 17:17:23 -07002017 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002018
Mark Lobodzinski23065352015-05-29 09:32:35 -05002019 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002021 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 -07002022 if (!pass) { // If we can't find any unmappable memory this test doesn't
2023 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002025 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002026 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002027
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002029 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
2032 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002033 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002034 ASSERT_VK_SUCCESS(err);
2035
2036 // Map memory as if to initialize the image
2037 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002040 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002041
Chia-I Wuf7458c52015-10-26 21:10:41 +08002042 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002043 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044}
2045
Karl Schultz6addd812016-02-02 17:17:23 -07002046TEST_F(VkLayerTest, RebindMemory) {
2047 VkResult err;
2048 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002051
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002053
2054 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002055 VkImage image;
2056 VkDeviceMemory mem1;
2057 VkDeviceMemory mem2;
2058 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Karl Schultz6addd812016-02-02 17:17:23 -07002060 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2061 const int32_t tex_width = 32;
2062 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
Tony Barboureb254902015-07-15 12:50:33 -06002064 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002065 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2066 image_create_info.pNext = NULL;
2067 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2068 image_create_info.format = tex_format;
2069 image_create_info.extent.width = tex_width;
2070 image_create_info.extent.height = tex_height;
2071 image_create_info.extent.depth = 1;
2072 image_create_info.mipLevels = 1;
2073 image_create_info.arrayLayers = 1;
2074 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2075 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2076 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2077 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002079 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002080 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2081 mem_alloc.pNext = NULL;
2082 mem_alloc.allocationSize = 0;
2083 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002084
Karl Schultz6addd812016-02-02 17:17:23 -07002085 // Introduce failure, do NOT set memProps to
2086 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002087 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002088 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002089 ASSERT_VK_SUCCESS(err);
2090
Karl Schultz6addd812016-02-02 17:17:23 -07002091 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
2093 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002095 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002096
2097 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002098 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002100 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101 ASSERT_VK_SUCCESS(err);
2102
2103 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002104 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002105 ASSERT_VK_SUCCESS(err);
2106
Karl Schultz6addd812016-02-02 17:17:23 -07002107 // Introduce validation failure, try to bind a different memory object to
2108 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002109 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002110
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002111 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002112
Chia-I Wuf7458c52015-10-26 21:10:41 +08002113 vkDestroyImage(m_device->device(), image, NULL);
2114 vkFreeMemory(m_device->device(), mem1, NULL);
2115 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002117
Karl Schultz6addd812016-02-02 17:17:23 -07002118TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002119 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002120
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2122 "submitted in SIGNALED state. Fences "
2123 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002124
2125 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002126 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2127 fenceInfo.pNext = NULL;
2128 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002129
Tony Barbour300a6082015-04-07 13:44:53 -06002130 ASSERT_NO_FATAL_FAILURE(InitState());
2131 ASSERT_NO_FATAL_FAILURE(InitViewport());
2132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2133
Tony Barbour552f6c02016-12-21 14:34:07 -07002134 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002136 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002137
2138 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002139
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002140 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002141 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2142 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002143 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002144 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002145 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002146 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002148 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002149 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002150
2151 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002152 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002153
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002154 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002155}
Chris Forbes4e44c912016-06-16 10:20:00 +12002156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002158 TEST_DESCRIPTION(
2159 "Specify wrong usage for image then create conflicting view of image "
2160 "Initialize buffer with wrong usage then perform copy expecting errors "
2161 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002163
2164 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002165
2166 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2167
Tony Barbourf92621a2016-05-02 14:28:12 -06002168 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002169 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002170 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002171 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002172
Tony Barbourf92621a2016-05-02 14:28:12 -06002173 VkImageView dsv;
2174 VkImageViewCreateInfo dsvci = {};
2175 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2176 dsvci.image = image.handle();
2177 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002178 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002179 dsvci.subresourceRange.layerCount = 1;
2180 dsvci.subresourceRange.baseMipLevel = 0;
2181 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002182 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002183
Tony Barbourf92621a2016-05-02 14:28:12 -06002184 // Create a view with depth / stencil aspect for image with different usage
2185 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002187 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002188
2189 // Initialize buffer with TRANSFER_DST usage
2190 vk_testing::Buffer buffer;
2191 VkMemoryPropertyFlags reqs = 0;
2192 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2193 VkBufferImageCopy region = {};
2194 region.bufferRowLength = 128;
2195 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002196 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002197 region.imageSubresource.layerCount = 1;
2198 region.imageExtent.height = 16;
2199 region.imageExtent.width = 16;
2200 region.imageExtent.depth = 1;
2201
Mark Lobodzinski80871462017-02-16 10:37:27 -07002202 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002203 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002204
Chris Forbesda581202016-10-06 18:25:26 +13002205 // two separate errors from this call:
2206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2210 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002212}
Tony Barbour75d79f02016-08-30 09:39:07 -06002213
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002214TEST_F(VkLayerTest, LeakAnObject) {
2215 VkResult err;
2216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218
2219 // Note that we have to create a new device since destroying the
2220 // framework's device causes Teardown() to fail and just calling Teardown
2221 // will destroy the errorMonitor.
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002224
2225 ASSERT_NO_FATAL_FAILURE(InitState());
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228 std::vector<VkDeviceQueueCreateInfo> queue_info;
2229 queue_info.reserve(queue_props.size());
2230 std::vector<std::vector<float>> queue_priorities;
2231 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2232 VkDeviceQueueCreateInfo qi = {};
2233 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2234 qi.pNext = NULL;
2235 qi.queueFamilyIndex = i;
2236 qi.queueCount = queue_props[i].queueCount;
2237 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2238 qi.pQueuePriorities = queue_priorities[i].data();
2239 queue_info.push_back(qi);
2240 }
2241
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002243
2244 // The sacrificial device object
2245 VkDevice testDevice;
2246 VkDeviceCreateInfo device_create_info = {};
2247 auto features = m_device->phy().features();
2248 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2249 device_create_info.pNext = NULL;
2250 device_create_info.queueCreateInfoCount = queue_info.size();
2251 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002252 device_create_info.enabledLayerCount = 0;
2253 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254 device_create_info.pEnabledFeatures = &features;
2255 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2256 ASSERT_VK_SUCCESS(err);
2257
2258 VkFence fence;
2259 VkFenceCreateInfo fence_create_info = {};
2260 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2261 fence_create_info.pNext = NULL;
2262 fence_create_info.flags = 0;
2263 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2264 ASSERT_VK_SUCCESS(err);
2265
2266 // Induce failure by not calling vkDestroyFence
2267 vkDestroyDevice(testDevice, NULL);
2268 m_errorMonitor->VerifyFound();
2269}
2270
2271TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002272 TEST_DESCRIPTION(
2273 "Allocate command buffers from one command pool and "
2274 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002277
Cody Northropc31a84f2016-08-22 10:41:47 -06002278 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279 VkCommandPool command_pool_one;
2280 VkCommandPool command_pool_two;
2281
2282 VkCommandPoolCreateInfo pool_create_info{};
2283 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2284 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2285 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002289 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002290
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002291 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002295 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002299 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300
2301 m_errorMonitor->VerifyFound();
2302
2303 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2304 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2305}
2306
2307TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2308 VkResult err;
2309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002310 TEST_DESCRIPTION(
2311 "Allocate descriptor sets from one DS pool and "
2312 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002315
2316 ASSERT_NO_FATAL_FAILURE(InitState());
2317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2318
2319 VkDescriptorPoolSize ds_type_count = {};
2320 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2321 ds_type_count.descriptorCount = 1;
2322
2323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2325 ds_pool_ci.pNext = NULL;
2326 ds_pool_ci.flags = 0;
2327 ds_pool_ci.maxSets = 1;
2328 ds_pool_ci.poolSizeCount = 1;
2329 ds_pool_ci.pPoolSizes = &ds_type_count;
2330
2331 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333 ASSERT_VK_SUCCESS(err);
2334
2335 // Create a second descriptor pool
2336 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002337 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002338 ASSERT_VK_SUCCESS(err);
2339
2340 VkDescriptorSetLayoutBinding dsl_binding = {};
2341 dsl_binding.binding = 0;
2342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2343 dsl_binding.descriptorCount = 1;
2344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2345 dsl_binding.pImmutableSamplers = NULL;
2346
2347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2349 ds_layout_ci.pNext = NULL;
2350 ds_layout_ci.bindingCount = 1;
2351 ds_layout_ci.pBindings = &dsl_binding;
2352
2353 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002355 ASSERT_VK_SUCCESS(err);
2356
2357 VkDescriptorSet descriptorSet;
2358 VkDescriptorSetAllocateInfo alloc_info = {};
2359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2360 alloc_info.descriptorSetCount = 1;
2361 alloc_info.descriptorPool = ds_pool_one;
2362 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002364 ASSERT_VK_SUCCESS(err);
2365
2366 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2371 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2372 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2373}
2374
2375TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002379
2380 ASSERT_NO_FATAL_FAILURE(InitState());
2381
2382 // Pass bogus handle into GetImageMemoryRequirements
2383 VkMemoryRequirements mem_reqs;
2384 uint64_t fakeImageHandle = 0xCADECADE;
2385 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2386
2387 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2388
2389 m_errorMonitor->VerifyFound();
2390}
2391
Mike Schuchardt17838902017-02-21 09:48:06 -07002392TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2393 TEST_DESCRIPTION(
2394 "Try to destroy a render pass object using a device other than the one it was created on. "
2395 "This should generate a distinct error from the invalid handle error.");
2396 // Create first device and renderpass
2397 ASSERT_NO_FATAL_FAILURE(InitState());
2398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2399
2400 // Create second device
2401 float priorities[] = {1.0f};
2402 VkDeviceQueueCreateInfo queue_info{};
2403 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2404 queue_info.pNext = NULL;
2405 queue_info.flags = 0;
2406 queue_info.queueFamilyIndex = 0;
2407 queue_info.queueCount = 1;
2408 queue_info.pQueuePriorities = &priorities[0];
2409
2410 VkDeviceCreateInfo device_create_info = {};
2411 auto features = m_device->phy().features();
2412 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2413 device_create_info.pNext = NULL;
2414 device_create_info.queueCreateInfoCount = 1;
2415 device_create_info.pQueueCreateInfos = &queue_info;
2416 device_create_info.enabledLayerCount = 0;
2417 device_create_info.ppEnabledLayerNames = NULL;
2418 device_create_info.pEnabledFeatures = &features;
2419
2420 VkDevice second_device;
2421 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2422
2423 // Try to destroy the renderpass from the first device using the second device
2424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2425 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2426 m_errorMonitor->VerifyFound();
2427
2428 vkDestroyDevice(second_device, NULL);
2429}
2430
Karl Schultz6addd812016-02-02 17:17:23 -07002431TEST_F(VkLayerTest, PipelineNotBound) {
2432 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002434 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002435
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002437
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002438 ASSERT_NO_FATAL_FAILURE(InitState());
2439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002440
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002441 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002442 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2443 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002444
2445 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002446 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2447 ds_pool_ci.pNext = NULL;
2448 ds_pool_ci.maxSets = 1;
2449 ds_pool_ci.poolSizeCount = 1;
2450 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002451
2452 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002453 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454 ASSERT_VK_SUCCESS(err);
2455
2456 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002457 dsl_binding.binding = 0;
2458 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2459 dsl_binding.descriptorCount = 1;
2460 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2461 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002462
2463 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002464 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2465 ds_layout_ci.pNext = NULL;
2466 ds_layout_ci.bindingCount = 1;
2467 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468
2469 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002471 ASSERT_VK_SUCCESS(err);
2472
2473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002474 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002476 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002477 alloc_info.descriptorPool = ds_pool;
2478 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002480 ASSERT_VK_SUCCESS(err);
2481
2482 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002483 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2484 pipeline_layout_ci.pNext = NULL;
2485 pipeline_layout_ci.setLayoutCount = 1;
2486 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002487
2488 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002490 ASSERT_VK_SUCCESS(err);
2491
Mark Youngad779052016-01-06 14:26:04 -07002492 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002493
Tony Barbour552f6c02016-12-21 14:34:07 -07002494 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002496
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002497 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002498
Chia-I Wuf7458c52015-10-26 21:10:41 +08002499 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002502}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002503
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002504TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2505 VkResult err;
2506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002507 TEST_DESCRIPTION(
2508 "Test validation check for an invalid memory type index "
2509 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002510
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002511 ASSERT_NO_FATAL_FAILURE(InitState());
2512
2513 // Create an image, allocate memory, set a bad typeIndex and then try to
2514 // bind it
2515 VkImage image;
2516 VkDeviceMemory mem;
2517 VkMemoryRequirements mem_reqs;
2518 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2519 const int32_t tex_width = 32;
2520 const int32_t tex_height = 32;
2521
2522 VkImageCreateInfo image_create_info = {};
2523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2524 image_create_info.pNext = NULL;
2525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2526 image_create_info.format = tex_format;
2527 image_create_info.extent.width = tex_width;
2528 image_create_info.extent.height = tex_height;
2529 image_create_info.extent.depth = 1;
2530 image_create_info.mipLevels = 1;
2531 image_create_info.arrayLayers = 1;
2532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2533 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2535 image_create_info.flags = 0;
2536
2537 VkMemoryAllocateInfo mem_alloc = {};
2538 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2539 mem_alloc.pNext = NULL;
2540 mem_alloc.allocationSize = 0;
2541 mem_alloc.memoryTypeIndex = 0;
2542
2543 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2544 ASSERT_VK_SUCCESS(err);
2545
2546 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2547 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002548
2549 // Introduce Failure, select invalid TypeIndex
2550 VkPhysicalDeviceMemoryProperties memory_info;
2551
2552 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2553 unsigned int i;
2554 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2555 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2556 mem_alloc.memoryTypeIndex = i;
2557 break;
2558 }
2559 }
2560 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002561 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562 vkDestroyImage(m_device->device(), image, NULL);
2563 return;
2564 }
2565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002566 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 -06002567
2568 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2569 ASSERT_VK_SUCCESS(err);
2570
2571 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2572 (void)err;
2573
2574 m_errorMonitor->VerifyFound();
2575
2576 vkDestroyImage(m_device->device(), image, NULL);
2577 vkFreeMemory(m_device->device(), mem, NULL);
2578}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002579
Karl Schultz6addd812016-02-02 17:17:23 -07002580TEST_F(VkLayerTest, BindInvalidMemory) {
2581 VkResult err;
2582 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002583
2584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002585
Cortf801b982017-01-17 18:10:21 -08002586 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -07002587 const int32_t tex_width = 32;
2588 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
2590 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002591 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2592 image_create_info.pNext = NULL;
2593 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2594 image_create_info.format = tex_format;
2595 image_create_info.extent.width = tex_width;
2596 image_create_info.extent.height = tex_height;
2597 image_create_info.extent.depth = 1;
2598 image_create_info.mipLevels = 1;
2599 image_create_info.arrayLayers = 1;
2600 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002601 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002602 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2603 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002604
Cortf801b982017-01-17 18:10:21 -08002605 VkBufferCreateInfo buffer_create_info = {};
2606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2607 buffer_create_info.pNext = NULL;
2608 buffer_create_info.flags = 0;
2609 buffer_create_info.size = tex_width;
2610 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2611 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002612
Cortf801b982017-01-17 18:10:21 -08002613 // Create an image/buffer, allocate memory, free it, and then try to bind it
2614 {
2615 VkImage image = VK_NULL_HANDLE;
2616 VkBuffer buffer = VK_NULL_HANDLE;
2617 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2618 ASSERT_VK_SUCCESS(err);
2619 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2620 ASSERT_VK_SUCCESS(err);
2621 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2622 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2623 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002624
Cortf801b982017-01-17 18:10:21 -08002625 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2626 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2627 image_mem_alloc.allocationSize = image_mem_reqs.size;
2628 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2629 ASSERT_TRUE(pass);
2630 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2631 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2632 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2633 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002634
Cortf801b982017-01-17 18:10:21 -08002635 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2636 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2637 ASSERT_VK_SUCCESS(err);
2638 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2639 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002640
Cortf801b982017-01-17 18:10:21 -08002641 vkFreeMemory(device(), image_mem, NULL);
2642 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002643
Cortf801b982017-01-17 18:10:21 -08002644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2645 err = vkBindImageMemory(device(), image, image_mem, 0);
2646 (void)err; // This may very well return an error.
2647 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2650 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2651 (void)err; // This may very well return an error.
2652 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002653
Cortf801b982017-01-17 18:10:21 -08002654 vkDestroyImage(m_device->device(), image, NULL);
2655 vkDestroyBuffer(m_device->device(), buffer, NULL);
2656 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002657
2658 // Try to bind memory to an object that already has a memory binding
2659 {
2660 VkImage image = VK_NULL_HANDLE;
2661 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2662 ASSERT_VK_SUCCESS(err);
2663 VkBuffer buffer = VK_NULL_HANDLE;
2664 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2665 ASSERT_VK_SUCCESS(err);
2666 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2667 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2668 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2669 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2670 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2671 image_alloc_info.allocationSize = image_mem_reqs.size;
2672 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2673 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2674 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2675 ASSERT_TRUE(pass);
2676 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2677 ASSERT_TRUE(pass);
2678 VkDeviceMemory image_mem, buffer_mem;
2679 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2680 ASSERT_VK_SUCCESS(err);
2681 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2682 ASSERT_VK_SUCCESS(err);
2683
2684 err = vkBindImageMemory(device(), image, image_mem, 0);
2685 ASSERT_VK_SUCCESS(err);
2686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2687 err = vkBindImageMemory(device(), image, image_mem, 0);
2688 (void)err; // This may very well return an error.
2689 m_errorMonitor->VerifyFound();
2690
2691 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2692 ASSERT_VK_SUCCESS(err);
2693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2694 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2695 (void)err; // This may very well return an error.
2696 m_errorMonitor->VerifyFound();
2697
2698 vkFreeMemory(device(), image_mem, NULL);
2699 vkFreeMemory(device(), buffer_mem, NULL);
2700 vkDestroyImage(device(), image, NULL);
2701 vkDestroyBuffer(device(), buffer, NULL);
2702 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002703
Cort6c7dff72017-01-27 18:34:50 -08002704 // Try to bind memory to an object with an out-of-range memoryOffset
2705 {
2706 VkImage image = VK_NULL_HANDLE;
2707 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2708 ASSERT_VK_SUCCESS(err);
2709 VkBuffer buffer = VK_NULL_HANDLE;
2710 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2711 ASSERT_VK_SUCCESS(err);
2712 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2713 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2714 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2715 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2716 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2717 image_alloc_info.allocationSize = image_mem_reqs.size;
2718 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2719 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2720 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2721 ASSERT_TRUE(pass);
2722 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2723 ASSERT_TRUE(pass);
2724 VkDeviceMemory image_mem, buffer_mem;
2725 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2726 ASSERT_VK_SUCCESS(err);
2727 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2728 ASSERT_VK_SUCCESS(err);
2729
2730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2731 VkDeviceSize image_offset = (image_mem_reqs.size + (image_mem_reqs.alignment - 1)) & ~(image_mem_reqs.alignment - 1);
2732 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2733 (void)err; // This may very well return an error.
2734 m_errorMonitor->VerifyFound();
2735
2736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2737 VkDeviceSize buffer_offset = (buffer_mem_reqs.size + (buffer_mem_reqs.alignment - 1)) & ~(buffer_mem_reqs.alignment - 1);
2738 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2739 (void)err; // This may very well return an error.
2740 m_errorMonitor->VerifyFound();
2741
2742 vkFreeMemory(device(), image_mem, NULL);
2743 vkFreeMemory(device(), buffer_mem, NULL);
2744 vkDestroyImage(device(), image, NULL);
2745 vkDestroyBuffer(device(), buffer, NULL);
2746 }
2747
Cort Stratton4c38bb52017-01-28 13:33:10 -08002748 // Try to bind memory to an object with an invalid memory type
2749 {
2750 VkImage image = VK_NULL_HANDLE;
2751 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2752 ASSERT_VK_SUCCESS(err);
2753 VkBuffer buffer = VK_NULL_HANDLE;
2754 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2755 ASSERT_VK_SUCCESS(err);
2756 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2757 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2758 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2759 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2760 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2761 image_alloc_info.allocationSize = image_mem_reqs.size;
2762 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2763 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002764 // Create a mask of available memory types *not* supported by these resources,
2765 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002766 VkPhysicalDeviceMemoryProperties memory_properties = {};
2767 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002768 VkDeviceMemory image_mem, buffer_mem;
2769
Cort Stratton4c38bb52017-01-28 13:33:10 -08002770 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002771 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002772 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2773 ASSERT_TRUE(pass);
2774 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2775 ASSERT_VK_SUCCESS(err);
2776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2777 err = vkBindImageMemory(device(), image, image_mem, 0);
2778 (void)err; // This may very well return an error.
2779 m_errorMonitor->VerifyFound();
2780 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002781 }
2782
Cort Stratton4c38bb52017-01-28 13:33:10 -08002783 uint32_t buffer_unsupported_mem_type_bits =
2784 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002785 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002786 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2787 ASSERT_TRUE(pass);
2788 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2789 ASSERT_VK_SUCCESS(err);
2790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2791 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2792 (void)err; // This may very well return an error.
2793 m_errorMonitor->VerifyFound();
2794 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002795 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002796
Cort Stratton4c38bb52017-01-28 13:33:10 -08002797 vkDestroyImage(device(), image, NULL);
2798 vkDestroyBuffer(device(), buffer, NULL);
2799 }
2800
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002801 // Try to bind memory to an image created with sparse memory flags
2802 {
2803 VkImageCreateInfo sparse_image_create_info = image_create_info;
2804 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2805 VkImageFormatProperties image_format_properties = {};
2806 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2807 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2808 sparse_image_create_info.usage, sparse_image_create_info.flags,
2809 &image_format_properties);
2810 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2811 // most likely means sparse formats aren't supported here; skip this test.
2812 } else {
2813 ASSERT_VK_SUCCESS(err);
2814 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002815 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002816 return;
2817 } else {
2818 VkImage sparse_image = VK_NULL_HANDLE;
2819 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2820 ASSERT_VK_SUCCESS(err);
2821 VkMemoryRequirements sparse_mem_reqs = {};
2822 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2823 if (sparse_mem_reqs.memoryTypeBits != 0) {
2824 VkMemoryAllocateInfo sparse_mem_alloc = {};
2825 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2826 sparse_mem_alloc.pNext = NULL;
2827 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2828 sparse_mem_alloc.memoryTypeIndex = 0;
2829 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2830 ASSERT_TRUE(pass);
2831 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2832 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2833 ASSERT_VK_SUCCESS(err);
2834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2835 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2836 // This may very well return an error.
2837 (void)err;
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2840 }
2841 vkDestroyImage(m_device->device(), sparse_image, NULL);
2842 }
2843 }
2844 }
2845
2846 // Try to bind memory to a buffer created with sparse memory flags
2847 {
2848 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2849 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2850 if (!m_device->phy().features().sparseResidencyBuffer) {
2851 // most likely means sparse formats aren't supported here; skip this test.
2852 } else {
2853 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2854 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2855 ASSERT_VK_SUCCESS(err);
2856 VkMemoryRequirements sparse_mem_reqs = {};
2857 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2858 if (sparse_mem_reqs.memoryTypeBits != 0) {
2859 VkMemoryAllocateInfo sparse_mem_alloc = {};
2860 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2861 sparse_mem_alloc.pNext = NULL;
2862 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2863 sparse_mem_alloc.memoryTypeIndex = 0;
2864 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2865 ASSERT_TRUE(pass);
2866 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2867 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2868 ASSERT_VK_SUCCESS(err);
2869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2870 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2871 // This may very well return an error.
2872 (void)err;
2873 m_errorMonitor->VerifyFound();
2874 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2875 }
2876 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2877 }
2878 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002879}
2880
Karl Schultz6addd812016-02-02 17:17:23 -07002881TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2882 VkResult err;
2883 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002884
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002886
Tobin Ehlisec598302015-09-15 15:02:17 -06002887 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002888
Karl Schultz6addd812016-02-02 17:17:23 -07002889 // Create an image object, allocate memory, destroy the object and then try
2890 // to bind it
2891 VkImage image;
2892 VkDeviceMemory mem;
2893 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002894
Karl Schultz6addd812016-02-02 17:17:23 -07002895 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2896 const int32_t tex_width = 32;
2897 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002898
2899 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002900 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2901 image_create_info.pNext = NULL;
2902 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2903 image_create_info.format = tex_format;
2904 image_create_info.extent.width = tex_width;
2905 image_create_info.extent.height = tex_height;
2906 image_create_info.extent.depth = 1;
2907 image_create_info.mipLevels = 1;
2908 image_create_info.arrayLayers = 1;
2909 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2910 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2911 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2912 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002913
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002914 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002915 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2916 mem_alloc.pNext = NULL;
2917 mem_alloc.allocationSize = 0;
2918 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002919
Chia-I Wuf7458c52015-10-26 21:10:41 +08002920 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002921 ASSERT_VK_SUCCESS(err);
2922
Karl Schultz6addd812016-02-02 17:17:23 -07002923 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002924
2925 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002926 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002927 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002928
2929 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002930 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002931 ASSERT_VK_SUCCESS(err);
2932
2933 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002934 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002935 ASSERT_VK_SUCCESS(err);
2936
2937 // Now Try to bind memory to this destroyed object
2938 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2939 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002940 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002941
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002942 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002943
Chia-I Wuf7458c52015-10-26 21:10:41 +08002944 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002945}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002946
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002947TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2948 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2949
2950 ASSERT_NO_FATAL_FAILURE(InitState());
2951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2952
2953 VkVertexInputBindingDescription input_binding;
2954 memset(&input_binding, 0, sizeof(input_binding));
2955
2956 VkVertexInputAttributeDescription input_attribs;
2957 memset(&input_attribs, 0, sizeof(input_attribs));
2958
2959 // Pick a really bad format for this purpose and make sure it should fail
2960 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2961 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2962 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002963 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002964 return;
2965 }
2966
2967 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002968 char const *vsSource =
2969 "#version 450\n"
2970 "\n"
2971 "out gl_PerVertex {\n"
2972 " vec4 gl_Position;\n"
2973 "};\n"
2974 "void main(){\n"
2975 " gl_Position = vec4(1);\n"
2976 "}\n";
2977 char const *fsSource =
2978 "#version 450\n"
2979 "\n"
2980 "layout(location=0) out vec4 color;\n"
2981 "void main(){\n"
2982 " color = vec4(1);\n"
2983 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002984
2985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2986 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2987 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2988
2989 VkPipelineObj pipe(m_device);
2990 pipe.AddColorAttachment();
2991 pipe.AddShader(&vs);
2992 pipe.AddShader(&fs);
2993
2994 pipe.AddVertexInputBindings(&input_binding, 1);
2995 pipe.AddVertexInputAttribs(&input_attribs, 1);
2996
2997 VkDescriptorSetObj descriptorSet(m_device);
2998 descriptorSet.AppendDummy();
2999 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3000
3001 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3002
3003 m_errorMonitor->VerifyFound();
3004}
3005
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003006TEST_F(VkLayerTest, ImageSampleCounts) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003007 TEST_DESCRIPTION(
3008 "Use bad sample counts in image transfer calls to trigger "
3009 "validation errors.");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003010 ASSERT_NO_FATAL_FAILURE(InitState());
3011
3012 VkMemoryPropertyFlags reqs = 0;
3013 VkImageCreateInfo image_create_info = {};
3014 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3015 image_create_info.pNext = NULL;
3016 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3017 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3018 image_create_info.extent.width = 256;
3019 image_create_info.extent.height = 256;
3020 image_create_info.extent.depth = 1;
3021 image_create_info.mipLevels = 1;
3022 image_create_info.arrayLayers = 1;
3023 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3024 image_create_info.flags = 0;
3025
3026 VkImageBlit blit_region = {};
3027 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3028 blit_region.srcSubresource.baseArrayLayer = 0;
3029 blit_region.srcSubresource.layerCount = 1;
3030 blit_region.srcSubresource.mipLevel = 0;
3031 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3032 blit_region.dstSubresource.baseArrayLayer = 0;
3033 blit_region.dstSubresource.layerCount = 1;
3034 blit_region.dstSubresource.mipLevel = 0;
3035
3036 // Create two images, the source with sampleCount = 2, and attempt to blit
3037 // between them
3038 {
3039 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003040 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003041 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003042 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003043 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003044 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003045 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003046 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003047 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003048 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3050 "was created with a sample count "
3051 "of VK_SAMPLE_COUNT_2_BIT but "
3052 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003053 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3054 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003055 m_errorMonitor->VerifyFound();
3056 m_commandBuffer->EndCommandBuffer();
3057 }
3058
3059 // Create two images, the dest with sampleCount = 4, and attempt to blit
3060 // between them
3061 {
3062 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003063 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003064 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003065 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003066 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003067 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003068 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003069 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003070 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003071 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3073 "was created with a sample count "
3074 "of VK_SAMPLE_COUNT_4_BIT but "
3075 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003076 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3077 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003078 m_errorMonitor->VerifyFound();
3079 m_commandBuffer->EndCommandBuffer();
3080 }
3081
3082 VkBufferImageCopy copy_region = {};
3083 copy_region.bufferRowLength = 128;
3084 copy_region.bufferImageHeight = 128;
3085 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3086 copy_region.imageSubresource.layerCount = 1;
3087 copy_region.imageExtent.height = 64;
3088 copy_region.imageExtent.width = 64;
3089 copy_region.imageExtent.depth = 1;
3090
3091 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3092 // buffer to image
3093 {
3094 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003095 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3096 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003097 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003098 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003099 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003100 m_errorMonitor->SetUnexpectedError(
3101 "If commandBuffer was allocated from a VkCommandPool which did not have the "
3102 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003103 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3105 "was created with a sample count "
3106 "of VK_SAMPLE_COUNT_8_BIT but "
3107 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3109 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003110 m_errorMonitor->VerifyFound();
3111 m_commandBuffer->EndCommandBuffer();
3112 }
3113
3114 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3115 // image to buffer
3116 {
3117 vk_testing::Buffer dst_buffer;
3118 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3119 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003121 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003123 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003124 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3126 "was created with a sample count "
3127 "of VK_SAMPLE_COUNT_2_BIT but "
3128 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003129 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003130 dst_buffer.handle(), 1, &copy_region);
3131 m_errorMonitor->VerifyFound();
3132 m_commandBuffer->EndCommandBuffer();
3133 }
3134}
3135
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003136TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003137 ASSERT_NO_FATAL_FAILURE(InitState());
3138
3139 VkImageObj src_image(m_device);
3140 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3141 VkImageObj dst_image(m_device);
3142 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3143 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003144 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 -06003145
3146 VkImageBlit blitRegion = {};
3147 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3148 blitRegion.srcSubresource.baseArrayLayer = 0;
3149 blitRegion.srcSubresource.layerCount = 1;
3150 blitRegion.srcSubresource.mipLevel = 0;
3151 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3152 blitRegion.dstSubresource.baseArrayLayer = 0;
3153 blitRegion.dstSubresource.layerCount = 1;
3154 blitRegion.dstSubresource.mipLevel = 0;
3155
Dave Houlton34df4cb2016-12-01 16:43:06 -07003156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3157
3158 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3159 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003160
3161 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003162 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003163 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3164 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003165
3166 m_errorMonitor->VerifyFound();
3167
Dave Houlton34df4cb2016-12-01 16:43:06 -07003168 // Test should generate 2 VU failures
3169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003171
3172 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003173 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3174 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003175
Dave Houlton34df4cb2016-12-01 16:43:06 -07003176 // TODO: Note that this only verifies that at least one of the VU enums was found
3177 // 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 -06003178 m_errorMonitor->VerifyFound();
3179
Tony Barbour552f6c02016-12-21 14:34:07 -07003180 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003181}
3182
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003183TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3184 VkResult err;
3185 bool pass;
3186
3187 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3188 ASSERT_NO_FATAL_FAILURE(InitState());
3189
3190 // If w/d/h granularity is 1, test is not meaningful
3191 // TODO: When virtual device limits are available, create a set of limits for this test that
3192 // will always have a granularity of > 1 for w, h, and d
3193 auto index = m_device->graphics_queue_node_index_;
3194 auto queue_family_properties = m_device->phy().queue_properties();
3195
3196 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3197 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3198 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3199 return;
3200 }
3201
3202 // Create two images of different types and try to copy between them
3203 VkImage srcImage;
3204 VkImage dstImage;
3205 VkDeviceMemory srcMem;
3206 VkDeviceMemory destMem;
3207 VkMemoryRequirements memReqs;
3208
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003209 VkImageCreateInfo image_create_info = {};
3210 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3211 image_create_info.pNext = NULL;
3212 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3213 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3214 image_create_info.extent.width = 32;
3215 image_create_info.extent.height = 32;
3216 image_create_info.extent.depth = 1;
3217 image_create_info.mipLevels = 1;
3218 image_create_info.arrayLayers = 4;
3219 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3220 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3221 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3222 image_create_info.flags = 0;
3223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003224 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003225 ASSERT_VK_SUCCESS(err);
3226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003228 ASSERT_VK_SUCCESS(err);
3229
3230 // Allocate memory
3231 VkMemoryAllocateInfo memAlloc = {};
3232 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3233 memAlloc.pNext = NULL;
3234 memAlloc.allocationSize = 0;
3235 memAlloc.memoryTypeIndex = 0;
3236
3237 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3238 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003239 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003240 ASSERT_TRUE(pass);
3241 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3242 ASSERT_VK_SUCCESS(err);
3243
3244 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3245 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003247 ASSERT_VK_SUCCESS(err);
3248 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3249 ASSERT_VK_SUCCESS(err);
3250
3251 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3252 ASSERT_VK_SUCCESS(err);
3253 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3254 ASSERT_VK_SUCCESS(err);
3255
Tony Barbour552f6c02016-12-21 14:34:07 -07003256 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003257 VkImageCopy copyRegion;
3258 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3259 copyRegion.srcSubresource.mipLevel = 0;
3260 copyRegion.srcSubresource.baseArrayLayer = 0;
3261 copyRegion.srcSubresource.layerCount = 1;
3262 copyRegion.srcOffset.x = 0;
3263 copyRegion.srcOffset.y = 0;
3264 copyRegion.srcOffset.z = 0;
3265 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3266 copyRegion.dstSubresource.mipLevel = 0;
3267 copyRegion.dstSubresource.baseArrayLayer = 0;
3268 copyRegion.dstSubresource.layerCount = 1;
3269 copyRegion.dstOffset.x = 0;
3270 copyRegion.dstOffset.y = 0;
3271 copyRegion.dstOffset.z = 0;
3272 copyRegion.extent.width = 1;
3273 copyRegion.extent.height = 1;
3274 copyRegion.extent.depth = 1;
3275
3276 // Introduce failure by setting srcOffset to a bad granularity value
3277 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3279 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003280 m_errorMonitor->VerifyFound();
3281
3282 // Introduce failure by setting extent to a bad granularity value
3283 copyRegion.srcOffset.y = 0;
3284 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3286 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003287 m_errorMonitor->VerifyFound();
3288
3289 // Now do some buffer/image copies
3290 vk_testing::Buffer buffer;
3291 VkMemoryPropertyFlags reqs = 0;
3292 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3293 VkBufferImageCopy region = {};
3294 region.bufferOffset = 0;
3295 region.bufferRowLength = 3;
3296 region.bufferImageHeight = 128;
3297 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3298 region.imageSubresource.layerCount = 1;
3299 region.imageExtent.height = 16;
3300 region.imageExtent.width = 16;
3301 region.imageExtent.depth = 1;
3302 region.imageOffset.x = 0;
3303 region.imageOffset.y = 0;
3304 region.imageOffset.z = 0;
3305
3306 // Introduce failure by setting bufferRowLength to a bad granularity value
3307 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3309 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3310 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003311 m_errorMonitor->VerifyFound();
3312 region.bufferRowLength = 128;
3313
3314 // Introduce failure by setting bufferOffset to a bad granularity value
3315 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3317 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3318 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003319 m_errorMonitor->VerifyFound();
3320 region.bufferOffset = 0;
3321
3322 // Introduce failure by setting bufferImageHeight to a bad granularity value
3323 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3325 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3326 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003327 m_errorMonitor->VerifyFound();
3328 region.bufferImageHeight = 128;
3329
3330 // Introduce failure by setting imageExtent to a bad granularity value
3331 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3333 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3334 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003335 m_errorMonitor->VerifyFound();
3336 region.imageExtent.width = 16;
3337
3338 // Introduce failure by setting imageOffset to a bad granularity value
3339 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3341 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3342 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003343 m_errorMonitor->VerifyFound();
3344
Tony Barbour552f6c02016-12-21 14:34:07 -07003345 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003346
3347 vkDestroyImage(m_device->device(), srcImage, NULL);
3348 vkDestroyImage(m_device->device(), dstImage, NULL);
3349 vkFreeMemory(m_device->device(), srcMem, NULL);
3350 vkFreeMemory(m_device->device(), destMem, NULL);
3351}
3352
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003353TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003354 TEST_DESCRIPTION(
3355 "Submit command buffer created using one queue family and "
3356 "attempt to submit them on a queue created in a different "
3357 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003358
Cody Northropc31a84f2016-08-22 10:41:47 -06003359 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003360
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003361 // This test is meaningless unless we have multiple queue families
3362 auto queue_family_properties = m_device->phy().queue_properties();
3363 if (queue_family_properties.size() < 2) {
3364 return;
3365 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003367 // Get safe index of another queue family
3368 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3369 ASSERT_NO_FATAL_FAILURE(InitState());
3370 // Create a second queue using a different queue family
3371 VkQueue other_queue;
3372 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3373
3374 // Record an empty cmd buffer
3375 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3376 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3377 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3378 vkEndCommandBuffer(m_commandBuffer->handle());
3379
3380 // And submit on the wrong queue
3381 VkSubmitInfo submit_info = {};
3382 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3383 submit_info.commandBufferCount = 1;
3384 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003385 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003386
3387 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003388}
3389
Chris Forbes4c24a922016-11-16 08:59:10 +13003390TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3391 ASSERT_NO_FATAL_FAILURE(InitState());
3392
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003393 // There are no attachments, but refer to attachment 0.
3394 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003395 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003396 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003397 };
3398
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003399 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003400 VkRenderPass rp;
3401
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003402 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003404 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3405 m_errorMonitor->VerifyFound();
3406}
3407
Chris Forbesa58c4522016-09-28 15:19:39 +13003408TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3409 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3410 ASSERT_NO_FATAL_FAILURE(InitState());
3411
3412 // A renderpass with two subpasses, both writing the same attachment.
3413 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003414 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3415 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3416 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003417 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003418 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003419 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003420 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3421 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003422 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003423 VkSubpassDependency dep = {0,
3424 1,
3425 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3426 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3427 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3428 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3429 VK_DEPENDENCY_BY_REGION_BIT};
3430 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003431 VkRenderPass rp;
3432 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3433 ASSERT_VK_SUCCESS(err);
3434
3435 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003436 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 +13003437 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3438
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003439 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003440 VkFramebuffer fb;
3441 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3442 ASSERT_VK_SUCCESS(err);
3443
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003444 char const *vsSource =
3445 "#version 450\n"
3446 "void main() { gl_Position = vec4(1); }\n";
3447 char const *fsSource =
3448 "#version 450\n"
3449 "layout(location=0) out vec4 color;\n"
3450 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003451
3452 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3453 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3454 VkPipelineObj pipe(m_device);
3455 pipe.AddColorAttachment();
3456 pipe.AddShader(&vs);
3457 pipe.AddShader(&fs);
3458 VkViewport view_port = {};
3459 m_viewports.push_back(view_port);
3460 pipe.SetViewport(m_viewports);
3461 VkRect2D rect = {};
3462 m_scissors.push_back(rect);
3463 pipe.SetScissor(m_scissors);
3464
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003465 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003466 VkPipelineLayout pl;
3467 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3468 ASSERT_VK_SUCCESS(err);
3469 pipe.CreateVKPipeline(pl, rp);
3470
Tony Barbour552f6c02016-12-21 14:34:07 -07003471 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003472
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003473 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3474 nullptr,
3475 rp,
3476 fb,
3477 {{
3478 0, 0,
3479 },
3480 {32, 32}},
3481 0,
3482 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003483
3484 // subtest 1: bind in the wrong subpass
3485 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3486 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003487 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 +13003488 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3489 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3490 m_errorMonitor->VerifyFound();
3491
3492 vkCmdEndRenderPass(m_commandBuffer->handle());
3493
3494 // subtest 2: bind in correct subpass, then transition to next subpass
3495 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3496 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3497 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003498 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 +13003499 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3500 m_errorMonitor->VerifyFound();
3501
3502 vkCmdEndRenderPass(m_commandBuffer->handle());
3503
Tony Barbour552f6c02016-12-21 14:34:07 -07003504 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003505
3506 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3507 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3508 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3509}
3510
Tony Barbour4e919972016-08-09 13:27:40 -06003511TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003512 TEST_DESCRIPTION(
3513 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3514 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003515 ASSERT_NO_FATAL_FAILURE(InitState());
3516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3517
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3519 "Cannot execute a render pass with renderArea "
3520 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003521
3522 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3523 m_renderPassBeginInfo.renderArea.extent.width = 257;
3524 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003525 m_commandBuffer->BeginCommandBuffer();
3526 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003527 m_errorMonitor->VerifyFound();
3528}
3529
3530TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003531 TEST_DESCRIPTION(
3532 "Generate INDEPENDENT_BLEND by disabling independent "
3533 "blend and then specifying different blend states for two "
3534 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003535 VkPhysicalDeviceFeatures features = {};
3536 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003537 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003538
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3540 "Invalid Pipeline CreateInfo: If independent blend feature not "
3541 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003542
Cody Northropc31a84f2016-08-22 10:41:47 -06003543 VkDescriptorSetObj descriptorSet(m_device);
3544 descriptorSet.AppendDummy();
3545 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003546
Cody Northropc31a84f2016-08-22 10:41:47 -06003547 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003548 // Create a renderPass with two color attachments
3549 VkAttachmentReference attachments[2] = {};
3550 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3551 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3552
3553 VkSubpassDescription subpass = {};
3554 subpass.pColorAttachments = attachments;
3555 subpass.colorAttachmentCount = 2;
3556
3557 VkRenderPassCreateInfo rpci = {};
3558 rpci.subpassCount = 1;
3559 rpci.pSubpasses = &subpass;
3560 rpci.attachmentCount = 1;
3561
3562 VkAttachmentDescription attach_desc = {};
3563 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3564 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3565 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3566 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3567
3568 rpci.pAttachments = &attach_desc;
3569 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3570
3571 VkRenderPass renderpass;
3572 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003573 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003574 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003575
Cody Northropc31a84f2016-08-22 10:41:47 -06003576 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3577 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3578 att_state1.blendEnable = VK_TRUE;
3579 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3580 att_state2.blendEnable = VK_FALSE;
3581 pipeline.AddColorAttachment(0, &att_state1);
3582 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003583 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003584 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003585 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003586}
3587
Mike Weiblen40b160e2017-02-06 19:21:52 -07003588// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3589TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3590 TEST_DESCRIPTION(
3591 "Create a graphics pipeline that is incompatible with the requirements "
3592 "of its contained Renderpass/subpasses.");
3593 ASSERT_NO_FATAL_FAILURE(InitState());
3594
3595 VkDescriptorSetObj ds_obj(m_device);
3596 ds_obj.AppendDummy();
3597 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3598
3599 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3600
3601 VkPipelineColorBlendAttachmentState att_state1 = {};
3602 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3603 att_state1.blendEnable = VK_TRUE;
3604
3605 VkRenderpassObj rp_obj(m_device);
3606
3607 {
3608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3609 VkPipelineObj pipeline(m_device);
3610 pipeline.AddShader(&vs_obj);
3611 pipeline.AddColorAttachment(0, &att_state1);
3612
3613 VkGraphicsPipelineCreateInfo info = {};
3614 pipeline.InitGraphicsPipelineCreateInfo(&info);
3615 info.pColorBlendState = nullptr;
3616
3617 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3618 m_errorMonitor->VerifyFound();
3619 }
3620}
3621
Chris Forbes26ec2122016-11-29 08:58:33 +13003622#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003623TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3624 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3625 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003626 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003627
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3629 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003630
3631 // Create a renderPass with a single color attachment
3632 VkAttachmentReference attach = {};
3633 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3634 VkSubpassDescription subpass = {};
3635 VkRenderPassCreateInfo rpci = {};
3636 rpci.subpassCount = 1;
3637 rpci.pSubpasses = &subpass;
3638 rpci.attachmentCount = 1;
3639 VkAttachmentDescription attach_desc = {};
3640 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3641 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3642 rpci.pAttachments = &attach_desc;
3643 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3644 VkRenderPass rp;
3645 subpass.pDepthStencilAttachment = &attach;
3646 subpass.pColorAttachments = NULL;
3647 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3648 m_errorMonitor->VerifyFound();
3649}
Chris Forbes26ec2122016-11-29 08:58:33 +13003650#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003651
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003652TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003653 TEST_DESCRIPTION(
3654 "Create a framebuffer where a subpass has a preserve "
3655 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003656
3657 ASSERT_NO_FATAL_FAILURE(InitState());
3658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3659
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003661
3662 VkAttachmentReference color_attach = {};
3663 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3664 color_attach.attachment = 0;
3665 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3666 VkSubpassDescription subpass = {};
3667 subpass.colorAttachmentCount = 1;
3668 subpass.pColorAttachments = &color_attach;
3669 subpass.preserveAttachmentCount = 1;
3670 subpass.pPreserveAttachments = &preserve_attachment;
3671
3672 VkRenderPassCreateInfo rpci = {};
3673 rpci.subpassCount = 1;
3674 rpci.pSubpasses = &subpass;
3675 rpci.attachmentCount = 1;
3676 VkAttachmentDescription attach_desc = {};
3677 attach_desc.format = VK_FORMAT_UNDEFINED;
3678 rpci.pAttachments = &attach_desc;
3679 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3680 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003681 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003682
3683 m_errorMonitor->VerifyFound();
3684
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003685 if (result == VK_SUCCESS) {
3686 vkDestroyRenderPass(m_device->device(), rp, NULL);
3687 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003688}
3689
Chris Forbesc5389742016-06-29 11:49:23 +12003690TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003691 TEST_DESCRIPTION(
3692 "Ensure that CreateRenderPass produces a validation error "
3693 "when the source of a subpass multisample resolve "
3694 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003695
Chris Forbesc5389742016-06-29 11:49:23 +12003696 ASSERT_NO_FATAL_FAILURE(InitState());
3697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3699 "Subpass 0 requests multisample resolve from attachment 0 which has "
3700 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003701
3702 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003703 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3704 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3705 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3706 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3707 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3708 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003709 };
3710
3711 VkAttachmentReference color = {
3712 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3713 };
3714
3715 VkAttachmentReference resolve = {
3716 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3717 };
3718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003719 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003721 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003722
3723 VkRenderPass rp;
3724 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3725
3726 m_errorMonitor->VerifyFound();
3727
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003728 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003729}
3730
3731TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003732 TEST_DESCRIPTION(
3733 "Ensure CreateRenderPass produces a validation error "
3734 "when a subpass multisample resolve operation is "
3735 "requested, and the destination of that resolve has "
3736 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003737
Chris Forbesc5389742016-06-29 11:49:23 +12003738 ASSERT_NO_FATAL_FAILURE(InitState());
3739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3741 "Subpass 0 requests multisample resolve into attachment 1, which "
3742 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003743
3744 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003745 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3746 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3747 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3748 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3749 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3750 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003751 };
3752
3753 VkAttachmentReference color = {
3754 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3755 };
3756
3757 VkAttachmentReference resolve = {
3758 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3759 };
3760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003761 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003763 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003764
3765 VkRenderPass rp;
3766 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3767
3768 m_errorMonitor->VerifyFound();
3769
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003770 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003771}
3772
Chris Forbes3f128ef2016-06-29 14:58:53 +12003773TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003774 TEST_DESCRIPTION(
3775 "Ensure CreateRenderPass produces a validation error "
3776 "when the color and depth attachments used by a subpass "
3777 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003778
Chris Forbes3f128ef2016-06-29 14:58:53 +12003779 ASSERT_NO_FATAL_FAILURE(InitState());
3780
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3782 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003783
3784 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003785 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3786 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3787 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3788 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3789 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3790 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003791 };
3792
3793 VkAttachmentReference color[] = {
3794 {
3795 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3796 },
3797 {
3798 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3799 },
3800 };
3801
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003802 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003804 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003805
3806 VkRenderPass rp;
3807 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3808
3809 m_errorMonitor->VerifyFound();
3810
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003811 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003812}
3813
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003814TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003815 TEST_DESCRIPTION(
3816 "Hit errors when attempting to create a framebuffer :\n"
3817 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3818 " 2. Use a color image as depthStencil attachment\n"
3819 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3820 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3821 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3822 " 6. Framebuffer attachment where dimensions don't match\n"
3823 " 7. Framebuffer attachment w/o identity swizzle\n"
3824 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003825
3826 ASSERT_NO_FATAL_FAILURE(InitState());
3827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3828
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3830 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3831 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003832
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003833 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003834 VkAttachmentReference attach = {};
3835 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3836 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003837 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003838 VkRenderPassCreateInfo rpci = {};
3839 rpci.subpassCount = 1;
3840 rpci.pSubpasses = &subpass;
3841 rpci.attachmentCount = 1;
3842 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003843 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003844 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003845 rpci.pAttachments = &attach_desc;
3846 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3847 VkRenderPass rp;
3848 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3849 ASSERT_VK_SUCCESS(err);
3850
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003851 VkImageView ivs[2];
3852 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3853 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003854 VkFramebufferCreateInfo fb_info = {};
3855 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3856 fb_info.pNext = NULL;
3857 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003858 // Set mis-matching attachmentCount
3859 fb_info.attachmentCount = 2;
3860 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003861 fb_info.width = 100;
3862 fb_info.height = 100;
3863 fb_info.layers = 1;
3864
3865 VkFramebuffer fb;
3866 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3867
3868 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003869 if (err == VK_SUCCESS) {
3870 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3871 }
3872 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003873
3874 // Create a renderPass with a depth-stencil attachment created with
3875 // IMAGE_USAGE_COLOR_ATTACHMENT
3876 // Add our color attachment to pDepthStencilAttachment
3877 subpass.pDepthStencilAttachment = &attach;
3878 subpass.pColorAttachments = NULL;
3879 VkRenderPass rp_ds;
3880 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3881 ASSERT_VK_SUCCESS(err);
3882 // Set correct attachment count, but attachment has COLOR usage bit set
3883 fb_info.attachmentCount = 1;
3884 fb_info.renderPass = rp_ds;
3885
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003887 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3888
3889 m_errorMonitor->VerifyFound();
3890 if (err == VK_SUCCESS) {
3891 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3892 }
3893 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003894
3895 // Create new renderpass with alternate attachment format from fb
3896 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3897 subpass.pDepthStencilAttachment = NULL;
3898 subpass.pColorAttachments = &attach;
3899 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3900 ASSERT_VK_SUCCESS(err);
3901
3902 // Cause error due to mis-matched formats between rp & fb
3903 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3904 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3906 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003907 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3908
3909 m_errorMonitor->VerifyFound();
3910 if (err == VK_SUCCESS) {
3911 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3912 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003913 vkDestroyRenderPass(m_device->device(), rp, NULL);
3914
3915 // Create new renderpass with alternate sample count from fb
3916 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3917 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3918 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3919 ASSERT_VK_SUCCESS(err);
3920
3921 // Cause error due to mis-matched sample count between rp & fb
3922 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3924 " has VK_SAMPLE_COUNT_1_BIT samples "
3925 "that do not match the "
3926 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003927 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3928
3929 m_errorMonitor->VerifyFound();
3930 if (err == VK_SUCCESS) {
3931 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3932 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003933
3934 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003935
3936 // Create a custom imageView with non-1 mip levels
3937 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003938 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 -06003939 ASSERT_TRUE(image.initialized());
3940
3941 VkImageView view;
3942 VkImageViewCreateInfo ivci = {};
3943 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3944 ivci.image = image.handle();
3945 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3946 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3947 ivci.subresourceRange.layerCount = 1;
3948 ivci.subresourceRange.baseMipLevel = 0;
3949 // Set level count 2 (only 1 is allowed for FB attachment)
3950 ivci.subresourceRange.levelCount = 2;
3951 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3952 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3953 ASSERT_VK_SUCCESS(err);
3954 // Re-create renderpass to have matching sample count
3955 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3956 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3957 ASSERT_VK_SUCCESS(err);
3958
3959 fb_info.renderPass = rp;
3960 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003962 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3963
3964 m_errorMonitor->VerifyFound();
3965 if (err == VK_SUCCESS) {
3966 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3967 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003968 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003969 // Update view to original color buffer and grow FB dimensions too big
3970 fb_info.pAttachments = ivs;
3971 fb_info.height = 1024;
3972 fb_info.width = 1024;
3973 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3975 " Attachment dimensions must be at "
3976 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003977 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3978
3979 m_errorMonitor->VerifyFound();
3980 if (err == VK_SUCCESS) {
3981 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3982 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003983 // Create view attachment with non-identity swizzle
3984 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3985 ivci.image = image.handle();
3986 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3987 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3988 ivci.subresourceRange.layerCount = 1;
3989 ivci.subresourceRange.baseMipLevel = 0;
3990 ivci.subresourceRange.levelCount = 1;
3991 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3992 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3993 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3994 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3995 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3996 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3997 ASSERT_VK_SUCCESS(err);
3998
3999 fb_info.pAttachments = &view;
4000 fb_info.height = 100;
4001 fb_info.width = 100;
4002 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4004 " has non-identy swizzle. All "
4005 "framebuffer attachments must have "
4006 "been created with the identity "
4007 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004008 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4009
4010 m_errorMonitor->VerifyFound();
4011 if (err == VK_SUCCESS) {
4012 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4013 }
4014 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004015 // reset attachment to color attachment
4016 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004017
4018 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004019 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004020 fb_info.height = 100;
4021 fb_info.layers = 1;
4022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004023 m_errorMonitor->SetUnexpectedError(
4024 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4025 "Here are the respective dimensions for attachment");
4026
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004027 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4028
4029 m_errorMonitor->VerifyFound();
4030 if (err == VK_SUCCESS) {
4031 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4032 }
4033
4034 // Request fb that exceeds max height
4035 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004036 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004037 fb_info.layers = 1;
4038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004039 m_errorMonitor->SetUnexpectedError(
4040 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4041 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004042 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4043
4044 m_errorMonitor->VerifyFound();
4045 if (err == VK_SUCCESS) {
4046 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4047 }
4048
4049 // Request fb that exceeds max layers
4050 fb_info.width = 100;
4051 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004052 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004054 m_errorMonitor->SetUnexpectedError(
4055 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4056 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004057 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4058
4059 m_errorMonitor->VerifyFound();
4060 if (err == VK_SUCCESS) {
4061 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4062 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004063
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004064 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004065}
4066
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004067TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004068 TEST_DESCRIPTION(
4069 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4070 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004071
Cody Northropc31a84f2016-08-22 10:41:47 -06004072 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004073 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4075 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004076 m_errorMonitor->VerifyFound();
4077}
4078
4079TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004080 TEST_DESCRIPTION(
4081 "Run a simple draw calls to validate failure when Line Width dynamic "
4082 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004083
Cody Northropc31a84f2016-08-22 10:41:47 -06004084 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004085 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4087 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004088 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004089}
4090
4091TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004092 TEST_DESCRIPTION(
4093 "Run a simple draw calls to validate failure when Viewport dynamic "
4094 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004095
Cody Northropc31a84f2016-08-22 10:41:47 -06004096 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004097 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4099 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004100 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004101 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004102}
4103
4104TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004105 TEST_DESCRIPTION(
4106 "Run a simple draw calls to validate failure when Scissor dynamic "
4107 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004108
Cody Northropc31a84f2016-08-22 10:41:47 -06004109 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004110 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4112 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004113 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004114 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004115}
4116
Cortd713fe82016-07-27 09:51:27 -07004117TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004118 TEST_DESCRIPTION(
4119 "Run a simple draw calls to validate failure when Blend Constants "
4120 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004121
4122 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004123 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4125 "Dynamic blend constants state not set for this command buffer");
4126 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004127 m_errorMonitor->VerifyFound();
4128}
4129
4130TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004131 TEST_DESCRIPTION(
4132 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4133 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004134
4135 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004136 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004137 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004138 return;
4139 }
4140 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4142 "Dynamic depth bounds state not set for this command buffer");
4143 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004144 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004145}
4146
4147TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004148 TEST_DESCRIPTION(
4149 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4150 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004151
4152 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004153 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4155 "Dynamic stencil read mask state not set for this command buffer");
4156 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004157 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004158}
4159
4160TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004161 TEST_DESCRIPTION(
4162 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4163 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004164
4165 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004166 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4168 "Dynamic stencil write mask state not set for this command buffer");
4169 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004170 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004171}
4172
4173TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004174 TEST_DESCRIPTION(
4175 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4176 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004177
4178 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004179 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4181 "Dynamic stencil reference state not set for this command buffer");
4182 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004183 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004184}
4185
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004186TEST_F(VkLayerTest, IndexBufferNotBound) {
4187 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004188
4189 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4191 "Index buffer object not bound to this command buffer when Indexed ");
4192 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004193 m_errorMonitor->VerifyFound();
4194}
4195
Karl Schultz6addd812016-02-02 17:17:23 -07004196TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4198 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4199 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004200
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004201 ASSERT_NO_FATAL_FAILURE(InitState());
4202 ASSERT_NO_FATAL_FAILURE(InitViewport());
4203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4204
Karl Schultz6addd812016-02-02 17:17:23 -07004205 // We luck out b/c by default the framework creates CB w/ the
4206 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004207 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004208 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004209 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004210
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004211 // Bypass framework since it does the waits automatically
4212 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004213 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004214 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4215 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004216 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004217 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004218 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004219 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004220 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004221 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004222 submit_info.pSignalSemaphores = NULL;
4223
Chris Forbes40028e22016-06-13 09:59:34 +12004224 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004225 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004226 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004227
Karl Schultz6addd812016-02-02 17:17:23 -07004228 // Cause validation error by re-submitting cmd buffer that should only be
4229 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004230 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004231 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004232
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004233 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004234}
4235
Karl Schultz6addd812016-02-02 17:17:23 -07004236TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004237 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004238 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004239
4240 ASSERT_NO_FATAL_FAILURE(InitState());
4241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004242
Karl Schultz6addd812016-02-02 17:17:23 -07004243 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4244 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004245 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004246 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004247 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004248
4249 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004250 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4251 ds_pool_ci.pNext = NULL;
4252 ds_pool_ci.flags = 0;
4253 ds_pool_ci.maxSets = 1;
4254 ds_pool_ci.poolSizeCount = 1;
4255 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004256
4257 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004258 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004259 ASSERT_VK_SUCCESS(err);
4260
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004261 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4262 dsl_binding_samp.binding = 0;
4263 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4264 dsl_binding_samp.descriptorCount = 1;
4265 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4266 dsl_binding_samp.pImmutableSamplers = NULL;
4267
4268 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4269 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4270 ds_layout_ci.pNext = NULL;
4271 ds_layout_ci.bindingCount = 1;
4272 ds_layout_ci.pBindings = &dsl_binding_samp;
4273
4274 VkDescriptorSetLayout ds_layout_samp;
4275 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4276 ASSERT_VK_SUCCESS(err);
4277
4278 // Try to allocate 2 sets when pool only has 1 set
4279 VkDescriptorSet descriptor_sets[2];
4280 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4281 VkDescriptorSetAllocateInfo alloc_info = {};
4282 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4283 alloc_info.descriptorSetCount = 2;
4284 alloc_info.descriptorPool = ds_pool;
4285 alloc_info.pSetLayouts = set_layouts;
4286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4287 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4288 m_errorMonitor->VerifyFound();
4289
4290 alloc_info.descriptorSetCount = 1;
4291 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004292 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004293 dsl_binding.binding = 0;
4294 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4295 dsl_binding.descriptorCount = 1;
4296 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4297 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004298
Karl Schultz6addd812016-02-02 17:17:23 -07004299 ds_layout_ci.bindingCount = 1;
4300 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004301
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004302 VkDescriptorSetLayout ds_layout_ub;
4303 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004304 ASSERT_VK_SUCCESS(err);
4305
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004306 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004307 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004308 alloc_info.pSetLayouts = &ds_layout_ub;
4309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4310 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004311
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004312 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004313
Karl Schultz2825ab92016-12-02 08:23:14 -07004314 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004315 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004316 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004317}
4318
Karl Schultz6addd812016-02-02 17:17:23 -07004319TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4320 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004321
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004323
Tobin Ehlise735c692015-10-08 13:13:50 -06004324 ASSERT_NO_FATAL_FAILURE(InitState());
4325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004326
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004327 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004328 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4329 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004330
4331 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004332 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4333 ds_pool_ci.pNext = NULL;
4334 ds_pool_ci.maxSets = 1;
4335 ds_pool_ci.poolSizeCount = 1;
4336 ds_pool_ci.flags = 0;
4337 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4338 // app can only call vkResetDescriptorPool on this pool.;
4339 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004340
4341 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004342 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004343 ASSERT_VK_SUCCESS(err);
4344
4345 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004346 dsl_binding.binding = 0;
4347 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4348 dsl_binding.descriptorCount = 1;
4349 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4350 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004351
4352 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004353 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4354 ds_layout_ci.pNext = NULL;
4355 ds_layout_ci.bindingCount = 1;
4356 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004357
4358 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004359 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004360 ASSERT_VK_SUCCESS(err);
4361
4362 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004363 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004364 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004365 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004366 alloc_info.descriptorPool = ds_pool;
4367 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004368 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004369 ASSERT_VK_SUCCESS(err);
4370
4371 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004372 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004373
Chia-I Wuf7458c52015-10-26 21:10:41 +08004374 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4375 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004376}
4377
Karl Schultz6addd812016-02-02 17:17:23 -07004378TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004379 // Attempt to clear Descriptor Pool with bad object.
4380 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004381
4382 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004384 uint64_t fake_pool_handle = 0xbaad6001;
4385 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4386 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004387 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004388}
4389
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004390TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004391 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4392 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004393 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004394 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004395
4396 uint64_t fake_set_handle = 0xbaad6001;
4397 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004398 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004400
4401 ASSERT_NO_FATAL_FAILURE(InitState());
4402
4403 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4404 layout_bindings[0].binding = 0;
4405 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4406 layout_bindings[0].descriptorCount = 1;
4407 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4408 layout_bindings[0].pImmutableSamplers = NULL;
4409
4410 VkDescriptorSetLayout descriptor_set_layout;
4411 VkDescriptorSetLayoutCreateInfo dslci = {};
4412 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4413 dslci.pNext = NULL;
4414 dslci.bindingCount = 1;
4415 dslci.pBindings = layout_bindings;
4416 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004417 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004418
4419 VkPipelineLayout pipeline_layout;
4420 VkPipelineLayoutCreateInfo plci = {};
4421 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4422 plci.pNext = NULL;
4423 plci.setLayoutCount = 1;
4424 plci.pSetLayouts = &descriptor_set_layout;
4425 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004426 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004427
Tony Barbour552f6c02016-12-21 14:34:07 -07004428 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004429 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4430 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004431 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004432 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004433 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4434 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004435}
4436
Karl Schultz6addd812016-02-02 17:17:23 -07004437TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004438 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4439 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004440 uint64_t fake_layout_handle = 0xbaad6001;
4441 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004443 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004444 VkPipelineLayout pipeline_layout;
4445 VkPipelineLayoutCreateInfo plci = {};
4446 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4447 plci.pNext = NULL;
4448 plci.setLayoutCount = 1;
4449 plci.pSetLayouts = &bad_layout;
4450 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4451
4452 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004453}
4454
Mark Muellerd4914412016-06-13 17:52:06 -06004455TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004456 TEST_DESCRIPTION(
4457 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4458 "1) A uniform buffer update must have a valid buffer index."
4459 "2) When using an array of descriptors in a single WriteDescriptor,"
4460 " the descriptor types and stageflags must all be the same."
4461 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004462
Mike Weiblena6666382017-01-05 15:16:11 -07004463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004464
4465 ASSERT_NO_FATAL_FAILURE(InitState());
4466 VkDescriptorPoolSize ds_type_count[4] = {};
4467 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4468 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004469 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004470 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004471 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004472 ds_type_count[2].descriptorCount = 1;
4473 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4474 ds_type_count[3].descriptorCount = 1;
4475
4476 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4477 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4478 ds_pool_ci.maxSets = 1;
4479 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4480 ds_pool_ci.pPoolSizes = ds_type_count;
4481
4482 VkDescriptorPool ds_pool;
4483 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4484 ASSERT_VK_SUCCESS(err);
4485
Mark Muellerb9896722016-06-16 09:54:29 -06004486 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004487 layout_binding[0].binding = 0;
4488 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4489 layout_binding[0].descriptorCount = 1;
4490 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4491 layout_binding[0].pImmutableSamplers = NULL;
4492
4493 layout_binding[1].binding = 1;
4494 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4495 layout_binding[1].descriptorCount = 1;
4496 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4497 layout_binding[1].pImmutableSamplers = NULL;
4498
4499 VkSamplerCreateInfo sampler_ci = {};
4500 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4501 sampler_ci.pNext = NULL;
4502 sampler_ci.magFilter = VK_FILTER_NEAREST;
4503 sampler_ci.minFilter = VK_FILTER_NEAREST;
4504 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4505 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4506 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4507 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4508 sampler_ci.mipLodBias = 1.0;
4509 sampler_ci.anisotropyEnable = VK_FALSE;
4510 sampler_ci.maxAnisotropy = 1;
4511 sampler_ci.compareEnable = VK_FALSE;
4512 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4513 sampler_ci.minLod = 1.0;
4514 sampler_ci.maxLod = 1.0;
4515 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4516 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4517 VkSampler sampler;
4518
4519 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4520 ASSERT_VK_SUCCESS(err);
4521
4522 layout_binding[2].binding = 2;
4523 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4524 layout_binding[2].descriptorCount = 1;
4525 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4526 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4527
Mark Muellerd4914412016-06-13 17:52:06 -06004528 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4529 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4530 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4531 ds_layout_ci.pBindings = layout_binding;
4532 VkDescriptorSetLayout ds_layout;
4533 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4534 ASSERT_VK_SUCCESS(err);
4535
4536 VkDescriptorSetAllocateInfo alloc_info = {};
4537 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4538 alloc_info.descriptorSetCount = 1;
4539 alloc_info.descriptorPool = ds_pool;
4540 alloc_info.pSetLayouts = &ds_layout;
4541 VkDescriptorSet descriptorSet;
4542 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4543 ASSERT_VK_SUCCESS(err);
4544
4545 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4546 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4547 pipeline_layout_ci.pNext = NULL;
4548 pipeline_layout_ci.setLayoutCount = 1;
4549 pipeline_layout_ci.pSetLayouts = &ds_layout;
4550
4551 VkPipelineLayout pipeline_layout;
4552 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4553 ASSERT_VK_SUCCESS(err);
4554
Mark Mueller5c838ce2016-06-16 09:54:29 -06004555 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004556 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4557 descriptor_write.dstSet = descriptorSet;
4558 descriptor_write.dstBinding = 0;
4559 descriptor_write.descriptorCount = 1;
4560 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4561
Mark Mueller5c838ce2016-06-16 09:54:29 -06004562 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004563 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4564 m_errorMonitor->VerifyFound();
4565
4566 // Create a buffer to update the descriptor with
4567 uint32_t qfi = 0;
4568 VkBufferCreateInfo buffCI = {};
4569 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4570 buffCI.size = 1024;
4571 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4572 buffCI.queueFamilyIndexCount = 1;
4573 buffCI.pQueueFamilyIndices = &qfi;
4574
4575 VkBuffer dyub;
4576 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4577 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004578
Tony Barboure132c5f2016-12-12 11:50:20 -07004579 VkDeviceMemory mem;
4580 VkMemoryRequirements mem_reqs;
4581 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4582
4583 VkMemoryAllocateInfo mem_alloc_info = {};
4584 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4585 mem_alloc_info.allocationSize = mem_reqs.size;
4586 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4587 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4588 ASSERT_VK_SUCCESS(err);
4589
4590 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4591 ASSERT_VK_SUCCESS(err);
4592
4593 VkDescriptorBufferInfo buffInfo[2] = {};
4594 buffInfo[0].buffer = dyub;
4595 buffInfo[0].offset = 0;
4596 buffInfo[0].range = 1024;
4597 buffInfo[1].buffer = dyub;
4598 buffInfo[1].offset = 0;
4599 buffInfo[1].range = 1024;
4600 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004601 descriptor_write.descriptorCount = 2;
4602
Mark Mueller5c838ce2016-06-16 09:54:29 -06004603 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004605 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4606 m_errorMonitor->VerifyFound();
4607
Mark Mueller5c838ce2016-06-16 09:54:29 -06004608 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4609 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004610 descriptor_write.dstBinding = 1;
4611 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004612
Mark Mueller5c838ce2016-06-16 09:54:29 -06004613 // Make pImageInfo index non-null to avoid complaints of it missing
4614 VkDescriptorImageInfo imageInfo = {};
4615 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4616 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004618 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4619 m_errorMonitor->VerifyFound();
4620
Mark Muellerd4914412016-06-13 17:52:06 -06004621 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004622 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004623 vkDestroySampler(m_device->device(), sampler, NULL);
4624 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4625 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4627}
4628
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004629TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004630 TEST_DESCRIPTION(
4631 "Attempt to draw with a command buffer that is invalid "
4632 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004633 ASSERT_NO_FATAL_FAILURE(InitState());
4634
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004635 VkBuffer buffer;
4636 VkDeviceMemory mem;
4637 VkMemoryRequirements mem_reqs;
4638
4639 VkBufferCreateInfo buf_info = {};
4640 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004641 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004642 buf_info.size = 256;
4643 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4644 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4645 ASSERT_VK_SUCCESS(err);
4646
4647 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4648
4649 VkMemoryAllocateInfo alloc_info = {};
4650 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4651 alloc_info.allocationSize = 256;
4652 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004653 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 -06004654 if (!pass) {
4655 vkDestroyBuffer(m_device->device(), buffer, NULL);
4656 return;
4657 }
4658 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4659 ASSERT_VK_SUCCESS(err);
4660
4661 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4662 ASSERT_VK_SUCCESS(err);
4663
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004664 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004665 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004666 m_commandBuffer->EndCommandBuffer();
4667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004669 // Destroy buffer dependency prior to submit to cause ERROR
4670 vkDestroyBuffer(m_device->device(), buffer, NULL);
4671
4672 VkSubmitInfo submit_info = {};
4673 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4674 submit_info.commandBufferCount = 1;
4675 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004676 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004677 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4678
4679 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004680 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004681 vkFreeMemory(m_device->handle(), mem, NULL);
4682}
4683
Tobin Ehlisea413442016-09-28 10:23:59 -06004684TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4685 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4686
4687 ASSERT_NO_FATAL_FAILURE(InitState());
4688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4689
4690 VkDescriptorPoolSize ds_type_count;
4691 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4692 ds_type_count.descriptorCount = 1;
4693
4694 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4695 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4696 ds_pool_ci.maxSets = 1;
4697 ds_pool_ci.poolSizeCount = 1;
4698 ds_pool_ci.pPoolSizes = &ds_type_count;
4699
4700 VkDescriptorPool ds_pool;
4701 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4702 ASSERT_VK_SUCCESS(err);
4703
4704 VkDescriptorSetLayoutBinding layout_binding;
4705 layout_binding.binding = 0;
4706 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4707 layout_binding.descriptorCount = 1;
4708 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4709 layout_binding.pImmutableSamplers = NULL;
4710
4711 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4712 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4713 ds_layout_ci.bindingCount = 1;
4714 ds_layout_ci.pBindings = &layout_binding;
4715 VkDescriptorSetLayout ds_layout;
4716 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4717 ASSERT_VK_SUCCESS(err);
4718
4719 VkDescriptorSetAllocateInfo alloc_info = {};
4720 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4721 alloc_info.descriptorSetCount = 1;
4722 alloc_info.descriptorPool = ds_pool;
4723 alloc_info.pSetLayouts = &ds_layout;
4724 VkDescriptorSet descriptor_set;
4725 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4726 ASSERT_VK_SUCCESS(err);
4727
4728 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4729 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4730 pipeline_layout_ci.pNext = NULL;
4731 pipeline_layout_ci.setLayoutCount = 1;
4732 pipeline_layout_ci.pSetLayouts = &ds_layout;
4733
4734 VkPipelineLayout pipeline_layout;
4735 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4736 ASSERT_VK_SUCCESS(err);
4737
4738 VkBuffer buffer;
4739 uint32_t queue_family_index = 0;
4740 VkBufferCreateInfo buffer_create_info = {};
4741 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4742 buffer_create_info.size = 1024;
4743 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4744 buffer_create_info.queueFamilyIndexCount = 1;
4745 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4746
4747 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4748 ASSERT_VK_SUCCESS(err);
4749
4750 VkMemoryRequirements memory_reqs;
4751 VkDeviceMemory buffer_memory;
4752
4753 VkMemoryAllocateInfo memory_info = {};
4754 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4755 memory_info.allocationSize = 0;
4756 memory_info.memoryTypeIndex = 0;
4757
4758 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4759 memory_info.allocationSize = memory_reqs.size;
4760 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4761 ASSERT_TRUE(pass);
4762
4763 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4764 ASSERT_VK_SUCCESS(err);
4765 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4766 ASSERT_VK_SUCCESS(err);
4767
4768 VkBufferView view;
4769 VkBufferViewCreateInfo bvci = {};
4770 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4771 bvci.buffer = buffer;
4772 bvci.format = VK_FORMAT_R8_UNORM;
4773 bvci.range = VK_WHOLE_SIZE;
4774
4775 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4776 ASSERT_VK_SUCCESS(err);
4777
4778 VkWriteDescriptorSet descriptor_write = {};
4779 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4780 descriptor_write.dstSet = descriptor_set;
4781 descriptor_write.dstBinding = 0;
4782 descriptor_write.descriptorCount = 1;
4783 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4784 descriptor_write.pTexelBufferView = &view;
4785
4786 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4787
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004788 char const *vsSource =
4789 "#version 450\n"
4790 "\n"
4791 "out gl_PerVertex { \n"
4792 " vec4 gl_Position;\n"
4793 "};\n"
4794 "void main(){\n"
4795 " gl_Position = vec4(1);\n"
4796 "}\n";
4797 char const *fsSource =
4798 "#version 450\n"
4799 "\n"
4800 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4801 "layout(location=0) out vec4 x;\n"
4802 "void main(){\n"
4803 " x = imageLoad(s, 0);\n"
4804 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004805 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4806 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4807 VkPipelineObj pipe(m_device);
4808 pipe.AddShader(&vs);
4809 pipe.AddShader(&fs);
4810 pipe.AddColorAttachment();
4811 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4812
4813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4815
Tony Barbour552f6c02016-12-21 14:34:07 -07004816 m_commandBuffer->BeginCommandBuffer();
4817 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4818
Tobin Ehlisea413442016-09-28 10:23:59 -06004819 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4820 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4821 VkRect2D scissor = {{0, 0}, {16, 16}};
4822 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4823 // Bind pipeline to cmd buffer
4824 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4825 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4826 &descriptor_set, 0, nullptr);
4827 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004828 m_commandBuffer->EndRenderPass();
4829 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004830
4831 // Delete BufferView in order to invalidate cmd buffer
4832 vkDestroyBufferView(m_device->device(), view, NULL);
4833 // Now attempt submit of cmd buffer
4834 VkSubmitInfo submit_info = {};
4835 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4836 submit_info.commandBufferCount = 1;
4837 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4838 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4839 m_errorMonitor->VerifyFound();
4840
4841 // Clean-up
4842 vkDestroyBuffer(m_device->device(), buffer, NULL);
4843 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4844 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4845 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4846 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4847}
4848
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004849TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004850 TEST_DESCRIPTION(
4851 "Attempt to draw with a command buffer that is invalid "
4852 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004853 ASSERT_NO_FATAL_FAILURE(InitState());
4854
4855 VkImage image;
4856 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4857 VkImageCreateInfo image_create_info = {};
4858 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4859 image_create_info.pNext = NULL;
4860 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4861 image_create_info.format = tex_format;
4862 image_create_info.extent.width = 32;
4863 image_create_info.extent.height = 32;
4864 image_create_info.extent.depth = 1;
4865 image_create_info.mipLevels = 1;
4866 image_create_info.arrayLayers = 1;
4867 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4868 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004869 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004870 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004871 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004872 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004873 // Have to bind memory to image before recording cmd in cmd buffer using it
4874 VkMemoryRequirements mem_reqs;
4875 VkDeviceMemory image_mem;
4876 bool pass;
4877 VkMemoryAllocateInfo mem_alloc = {};
4878 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4879 mem_alloc.pNext = NULL;
4880 mem_alloc.memoryTypeIndex = 0;
4881 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4882 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004883 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004884 ASSERT_TRUE(pass);
4885 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4886 ASSERT_VK_SUCCESS(err);
4887 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4888 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004889
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004890 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004891 VkClearColorValue ccv;
4892 ccv.float32[0] = 1.0f;
4893 ccv.float32[1] = 1.0f;
4894 ccv.float32[2] = 1.0f;
4895 ccv.float32[3] = 1.0f;
4896 VkImageSubresourceRange isr = {};
4897 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004898 isr.baseArrayLayer = 0;
4899 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004900 isr.layerCount = 1;
4901 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004902 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004903 m_commandBuffer->EndCommandBuffer();
4904
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004906 // Destroy image dependency prior to submit to cause ERROR
4907 vkDestroyImage(m_device->device(), image, NULL);
4908
4909 VkSubmitInfo submit_info = {};
4910 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4911 submit_info.commandBufferCount = 1;
4912 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004913 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004914 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4915
4916 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004917 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004918}
4919
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004920TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004921 TEST_DESCRIPTION(
4922 "Attempt to draw with a command buffer that is invalid "
4923 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004924 VkFormatProperties format_properties;
4925 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004926 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4927 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004928 return;
4929 }
4930
4931 ASSERT_NO_FATAL_FAILURE(InitState());
4932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4933
4934 VkImageCreateInfo image_ci = {};
4935 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4936 image_ci.pNext = NULL;
4937 image_ci.imageType = VK_IMAGE_TYPE_2D;
4938 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4939 image_ci.extent.width = 32;
4940 image_ci.extent.height = 32;
4941 image_ci.extent.depth = 1;
4942 image_ci.mipLevels = 1;
4943 image_ci.arrayLayers = 1;
4944 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4945 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004946 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004947 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4948 image_ci.flags = 0;
4949 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004950 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004951
4952 VkMemoryRequirements memory_reqs;
4953 VkDeviceMemory image_memory;
4954 bool pass;
4955 VkMemoryAllocateInfo memory_info = {};
4956 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4957 memory_info.pNext = NULL;
4958 memory_info.allocationSize = 0;
4959 memory_info.memoryTypeIndex = 0;
4960 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4961 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004962 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004963 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004964 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004965 ASSERT_VK_SUCCESS(err);
4966 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4967 ASSERT_VK_SUCCESS(err);
4968
4969 VkImageViewCreateInfo ivci = {
4970 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4971 nullptr,
4972 0,
4973 image,
4974 VK_IMAGE_VIEW_TYPE_2D,
4975 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004976 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004977 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4978 };
4979 VkImageView view;
4980 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4981 ASSERT_VK_SUCCESS(err);
4982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004983 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004984 VkFramebuffer fb;
4985 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4986 ASSERT_VK_SUCCESS(err);
4987
4988 // Just use default renderpass with our framebuffer
4989 m_renderPassBeginInfo.framebuffer = fb;
4990 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004991 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004992 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07004993 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4994 m_commandBuffer->EndRenderPass();
4995 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004996 // Destroy image attached to framebuffer to invalidate cmd buffer
4997 vkDestroyImage(m_device->device(), image, NULL);
4998 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005000 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005001 QueueCommandBuffer(false);
5002 m_errorMonitor->VerifyFound();
5003
5004 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5005 vkDestroyImageView(m_device->device(), view, nullptr);
5006 vkFreeMemory(m_device->device(), image_memory, nullptr);
5007}
5008
Tobin Ehlisb329f992016-10-12 13:20:29 -06005009TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5010 TEST_DESCRIPTION("Delete in-use framebuffer.");
5011 VkFormatProperties format_properties;
5012 VkResult err = VK_SUCCESS;
5013 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5014
5015 ASSERT_NO_FATAL_FAILURE(InitState());
5016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5017
5018 VkImageObj image(m_device);
5019 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5020 ASSERT_TRUE(image.initialized());
5021 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5022
5023 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5024 VkFramebuffer fb;
5025 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5026 ASSERT_VK_SUCCESS(err);
5027
5028 // Just use default renderpass with our framebuffer
5029 m_renderPassBeginInfo.framebuffer = fb;
5030 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005031 m_commandBuffer->BeginCommandBuffer();
5032 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5033 m_commandBuffer->EndRenderPass();
5034 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005035 // Submit cmd buffer to put it in-flight
5036 VkSubmitInfo submit_info = {};
5037 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5038 submit_info.commandBufferCount = 1;
5039 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5040 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5041 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005043 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5044 m_errorMonitor->VerifyFound();
5045 // Wait for queue to complete so we can safely destroy everything
5046 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005047 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5048 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005049 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5050}
5051
Tobin Ehlis88becd72016-09-21 14:33:41 -06005052TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5053 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5054 VkFormatProperties format_properties;
5055 VkResult err = VK_SUCCESS;
5056 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005057
5058 ASSERT_NO_FATAL_FAILURE(InitState());
5059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5060
5061 VkImageCreateInfo image_ci = {};
5062 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5063 image_ci.pNext = NULL;
5064 image_ci.imageType = VK_IMAGE_TYPE_2D;
5065 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5066 image_ci.extent.width = 256;
5067 image_ci.extent.height = 256;
5068 image_ci.extent.depth = 1;
5069 image_ci.mipLevels = 1;
5070 image_ci.arrayLayers = 1;
5071 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5072 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005073 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005074 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5075 image_ci.flags = 0;
5076 VkImage image;
5077 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5078
5079 VkMemoryRequirements memory_reqs;
5080 VkDeviceMemory image_memory;
5081 bool pass;
5082 VkMemoryAllocateInfo memory_info = {};
5083 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5084 memory_info.pNext = NULL;
5085 memory_info.allocationSize = 0;
5086 memory_info.memoryTypeIndex = 0;
5087 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5088 memory_info.allocationSize = memory_reqs.size;
5089 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5090 ASSERT_TRUE(pass);
5091 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5092 ASSERT_VK_SUCCESS(err);
5093 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5094 ASSERT_VK_SUCCESS(err);
5095
5096 VkImageViewCreateInfo ivci = {
5097 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5098 nullptr,
5099 0,
5100 image,
5101 VK_IMAGE_VIEW_TYPE_2D,
5102 VK_FORMAT_B8G8R8A8_UNORM,
5103 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5104 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5105 };
5106 VkImageView view;
5107 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5108 ASSERT_VK_SUCCESS(err);
5109
5110 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5111 VkFramebuffer fb;
5112 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5113 ASSERT_VK_SUCCESS(err);
5114
5115 // Just use default renderpass with our framebuffer
5116 m_renderPassBeginInfo.framebuffer = fb;
5117 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005118 m_commandBuffer->BeginCommandBuffer();
5119 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5120 m_commandBuffer->EndRenderPass();
5121 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005122 // Submit cmd buffer to put it (and attached imageView) in-flight
5123 VkSubmitInfo submit_info = {};
5124 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5125 submit_info.commandBufferCount = 1;
5126 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5127 // Submit cmd buffer to put framebuffer and children in-flight
5128 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5129 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005131 vkDestroyImage(m_device->device(), image, NULL);
5132 m_errorMonitor->VerifyFound();
5133 // Wait for queue to complete so we can safely destroy image and other objects
5134 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005135 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5136 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005137 vkDestroyImage(m_device->device(), image, NULL);
5138 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5139 vkDestroyImageView(m_device->device(), view, nullptr);
5140 vkFreeMemory(m_device->device(), image_memory, nullptr);
5141}
5142
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005143TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5144 TEST_DESCRIPTION("Delete in-use renderPass.");
5145
5146 ASSERT_NO_FATAL_FAILURE(InitState());
5147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5148
5149 // Create simple renderpass
5150 VkAttachmentReference attach = {};
5151 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5152 VkSubpassDescription subpass = {};
5153 subpass.pColorAttachments = &attach;
5154 VkRenderPassCreateInfo rpci = {};
5155 rpci.subpassCount = 1;
5156 rpci.pSubpasses = &subpass;
5157 rpci.attachmentCount = 1;
5158 VkAttachmentDescription attach_desc = {};
5159 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5160 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5161 rpci.pAttachments = &attach_desc;
5162 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5163 VkRenderPass rp;
5164 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5165 ASSERT_VK_SUCCESS(err);
5166
5167 // Create a pipeline that uses the given renderpass
5168 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5169 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5170
5171 VkPipelineLayout pipeline_layout;
5172 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5173 ASSERT_VK_SUCCESS(err);
5174
5175 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5176 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5177 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005178 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005179 vp_state_ci.pViewports = &vp;
5180 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005181 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005182 vp_state_ci.pScissors = &scissors;
5183
5184 VkPipelineShaderStageCreateInfo shaderStages[2];
5185 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5186
5187 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005188 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 -06005189 // but add it to be able to run on more devices
5190 shaderStages[0] = vs.GetStageCreateInfo();
5191 shaderStages[1] = fs.GetStageCreateInfo();
5192
5193 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5194 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5195
5196 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5197 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5198 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5199
5200 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5201 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5202 rs_ci.rasterizerDiscardEnable = true;
5203 rs_ci.lineWidth = 1.0f;
5204
5205 VkPipelineColorBlendAttachmentState att = {};
5206 att.blendEnable = VK_FALSE;
5207 att.colorWriteMask = 0xf;
5208
5209 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5210 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5211 cb_ci.attachmentCount = 1;
5212 cb_ci.pAttachments = &att;
5213
5214 VkGraphicsPipelineCreateInfo gp_ci = {};
5215 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5216 gp_ci.stageCount = 2;
5217 gp_ci.pStages = shaderStages;
5218 gp_ci.pVertexInputState = &vi_ci;
5219 gp_ci.pInputAssemblyState = &ia_ci;
5220 gp_ci.pViewportState = &vp_state_ci;
5221 gp_ci.pRasterizationState = &rs_ci;
5222 gp_ci.pColorBlendState = &cb_ci;
5223 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5224 gp_ci.layout = pipeline_layout;
5225 gp_ci.renderPass = rp;
5226
5227 VkPipelineCacheCreateInfo pc_ci = {};
5228 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5229
5230 VkPipeline pipeline;
5231 VkPipelineCache pipe_cache;
5232 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5233 ASSERT_VK_SUCCESS(err);
5234
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005235 m_errorMonitor->SetUnexpectedError(
5236 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5237 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005238 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5239 ASSERT_VK_SUCCESS(err);
5240 // Bind pipeline to cmd buffer, will also bind renderpass
5241 m_commandBuffer->BeginCommandBuffer();
5242 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5243 m_commandBuffer->EndCommandBuffer();
5244
5245 VkSubmitInfo submit_info = {};
5246 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5247 submit_info.commandBufferCount = 1;
5248 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5249 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5250
5251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5252 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5253 m_errorMonitor->VerifyFound();
5254
5255 // Wait for queue to complete so we can safely destroy everything
5256 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005257 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5258 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005259 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5260 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5261 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5262 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5263}
5264
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005265TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005266 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005267 ASSERT_NO_FATAL_FAILURE(InitState());
5268
5269 VkImage image;
5270 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5271 VkImageCreateInfo image_create_info = {};
5272 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5273 image_create_info.pNext = NULL;
5274 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5275 image_create_info.format = tex_format;
5276 image_create_info.extent.width = 32;
5277 image_create_info.extent.height = 32;
5278 image_create_info.extent.depth = 1;
5279 image_create_info.mipLevels = 1;
5280 image_create_info.arrayLayers = 1;
5281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5282 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005283 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005284 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005285 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005286 ASSERT_VK_SUCCESS(err);
5287 // Have to bind memory to image before recording cmd in cmd buffer using it
5288 VkMemoryRequirements mem_reqs;
5289 VkDeviceMemory image_mem;
5290 bool pass;
5291 VkMemoryAllocateInfo mem_alloc = {};
5292 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5293 mem_alloc.pNext = NULL;
5294 mem_alloc.memoryTypeIndex = 0;
5295 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5296 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005297 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005298 ASSERT_TRUE(pass);
5299 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5300 ASSERT_VK_SUCCESS(err);
5301
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005302 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005304 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005305
5306 m_commandBuffer->BeginCommandBuffer();
5307 VkClearColorValue ccv;
5308 ccv.float32[0] = 1.0f;
5309 ccv.float32[1] = 1.0f;
5310 ccv.float32[2] = 1.0f;
5311 ccv.float32[3] = 1.0f;
5312 VkImageSubresourceRange isr = {};
5313 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5314 isr.baseArrayLayer = 0;
5315 isr.baseMipLevel = 0;
5316 isr.layerCount = 1;
5317 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005318 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005319 m_commandBuffer->EndCommandBuffer();
5320
5321 m_errorMonitor->VerifyFound();
5322 vkDestroyImage(m_device->device(), image, NULL);
5323 vkFreeMemory(m_device->device(), image_mem, nullptr);
5324}
5325
5326TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005327 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005328 ASSERT_NO_FATAL_FAILURE(InitState());
5329
5330 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005331 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 -06005332 VK_IMAGE_TILING_OPTIMAL, 0);
5333 ASSERT_TRUE(image.initialized());
5334
5335 VkBuffer buffer;
5336 VkDeviceMemory mem;
5337 VkMemoryRequirements mem_reqs;
5338
5339 VkBufferCreateInfo buf_info = {};
5340 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005341 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005342 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005343 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5344 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5345 ASSERT_VK_SUCCESS(err);
5346
5347 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5348
5349 VkMemoryAllocateInfo alloc_info = {};
5350 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005351 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005352 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005353 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 -06005354 if (!pass) {
5355 vkDestroyBuffer(m_device->device(), buffer, NULL);
5356 return;
5357 }
5358 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5359 ASSERT_VK_SUCCESS(err);
5360
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005361 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005363 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005364 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005365 region.bufferRowLength = 16;
5366 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005367 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5368
5369 region.imageSubresource.layerCount = 1;
5370 region.imageExtent.height = 4;
5371 region.imageExtent.width = 4;
5372 region.imageExtent.depth = 1;
5373 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005374 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5375 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005376 m_commandBuffer->EndCommandBuffer();
5377
5378 m_errorMonitor->VerifyFound();
5379
5380 vkDestroyBuffer(m_device->device(), buffer, NULL);
5381 vkFreeMemory(m_device->handle(), mem, NULL);
5382}
5383
Tobin Ehlis85940f52016-07-07 16:57:21 -06005384TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005385 TEST_DESCRIPTION(
5386 "Attempt to draw with a command buffer that is invalid "
5387 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005388 ASSERT_NO_FATAL_FAILURE(InitState());
5389
5390 VkEvent event;
5391 VkEventCreateInfo evci = {};
5392 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5393 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5394 ASSERT_VK_SUCCESS(result);
5395
5396 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005397 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005398 m_commandBuffer->EndCommandBuffer();
5399
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005401 // Destroy event dependency prior to submit to cause ERROR
5402 vkDestroyEvent(m_device->device(), event, NULL);
5403
5404 VkSubmitInfo submit_info = {};
5405 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5406 submit_info.commandBufferCount = 1;
5407 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005408 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted event");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005409 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5410
5411 m_errorMonitor->VerifyFound();
5412}
5413
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005414TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005415 TEST_DESCRIPTION(
5416 "Attempt to draw with a command buffer that is invalid "
5417 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005418 ASSERT_NO_FATAL_FAILURE(InitState());
5419
5420 VkQueryPool query_pool;
5421 VkQueryPoolCreateInfo qpci{};
5422 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5423 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5424 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005425 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005426 ASSERT_VK_SUCCESS(result);
5427
5428 m_commandBuffer->BeginCommandBuffer();
5429 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5430 m_commandBuffer->EndCommandBuffer();
5431
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005433 // Destroy query pool dependency prior to submit to cause ERROR
5434 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5435
5436 VkSubmitInfo submit_info = {};
5437 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5438 submit_info.commandBufferCount = 1;
5439 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005440 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted query pool");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005441 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5442
5443 m_errorMonitor->VerifyFound();
5444}
5445
Tobin Ehlis24130d92016-07-08 15:50:53 -06005446TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005447 TEST_DESCRIPTION(
5448 "Attempt to draw with a command buffer that is invalid "
5449 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005450 ASSERT_NO_FATAL_FAILURE(InitState());
5451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5452
5453 VkResult err;
5454
5455 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5456 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5457
5458 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005459 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005460 ASSERT_VK_SUCCESS(err);
5461
5462 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5463 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5464 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005465 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005466 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005467 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005468 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005469 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005470
5471 VkPipelineShaderStageCreateInfo shaderStages[2];
5472 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5473
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005474 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005475 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 -06005476 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005477 shaderStages[0] = vs.GetStageCreateInfo();
5478 shaderStages[1] = fs.GetStageCreateInfo();
5479
5480 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5481 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5482
5483 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5484 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5485 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5486
5487 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5488 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005489 rs_ci.rasterizerDiscardEnable = true;
5490 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005491
5492 VkPipelineColorBlendAttachmentState att = {};
5493 att.blendEnable = VK_FALSE;
5494 att.colorWriteMask = 0xf;
5495
5496 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5497 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5498 cb_ci.attachmentCount = 1;
5499 cb_ci.pAttachments = &att;
5500
5501 VkGraphicsPipelineCreateInfo gp_ci = {};
5502 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5503 gp_ci.stageCount = 2;
5504 gp_ci.pStages = shaderStages;
5505 gp_ci.pVertexInputState = &vi_ci;
5506 gp_ci.pInputAssemblyState = &ia_ci;
5507 gp_ci.pViewportState = &vp_state_ci;
5508 gp_ci.pRasterizationState = &rs_ci;
5509 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005510 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5511 gp_ci.layout = pipeline_layout;
5512 gp_ci.renderPass = renderPass();
5513
5514 VkPipelineCacheCreateInfo pc_ci = {};
5515 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5516
5517 VkPipeline pipeline;
5518 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005519 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005520 ASSERT_VK_SUCCESS(err);
5521
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005522 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005523 ASSERT_VK_SUCCESS(err);
5524
5525 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005526 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005527 m_commandBuffer->EndCommandBuffer();
5528 // Now destroy pipeline in order to cause error when submitting
5529 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5530
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005532
5533 VkSubmitInfo submit_info = {};
5534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5535 submit_info.commandBufferCount = 1;
5536 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005537 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted pipeline");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005538 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5539
5540 m_errorMonitor->VerifyFound();
5541 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5542 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5543}
5544
Tobin Ehlis31289162016-08-17 14:57:58 -06005545TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005546 TEST_DESCRIPTION(
5547 "Attempt to draw with a command buffer that is invalid "
5548 "due to a bound descriptor set with a buffer dependency "
5549 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005550 ASSERT_NO_FATAL_FAILURE(InitState());
5551 ASSERT_NO_FATAL_FAILURE(InitViewport());
5552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5553
5554 VkDescriptorPoolSize ds_type_count = {};
5555 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5556 ds_type_count.descriptorCount = 1;
5557
5558 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5559 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5560 ds_pool_ci.pNext = NULL;
5561 ds_pool_ci.maxSets = 1;
5562 ds_pool_ci.poolSizeCount = 1;
5563 ds_pool_ci.pPoolSizes = &ds_type_count;
5564
5565 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005566 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005567 ASSERT_VK_SUCCESS(err);
5568
5569 VkDescriptorSetLayoutBinding dsl_binding = {};
5570 dsl_binding.binding = 0;
5571 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5572 dsl_binding.descriptorCount = 1;
5573 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5574 dsl_binding.pImmutableSamplers = NULL;
5575
5576 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5577 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5578 ds_layout_ci.pNext = NULL;
5579 ds_layout_ci.bindingCount = 1;
5580 ds_layout_ci.pBindings = &dsl_binding;
5581 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005583 ASSERT_VK_SUCCESS(err);
5584
5585 VkDescriptorSet descriptorSet;
5586 VkDescriptorSetAllocateInfo alloc_info = {};
5587 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5588 alloc_info.descriptorSetCount = 1;
5589 alloc_info.descriptorPool = ds_pool;
5590 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005591 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005592 ASSERT_VK_SUCCESS(err);
5593
5594 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5595 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5596 pipeline_layout_ci.pNext = NULL;
5597 pipeline_layout_ci.setLayoutCount = 1;
5598 pipeline_layout_ci.pSetLayouts = &ds_layout;
5599
5600 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005601 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005602 ASSERT_VK_SUCCESS(err);
5603
5604 // Create a buffer to update the descriptor with
5605 uint32_t qfi = 0;
5606 VkBufferCreateInfo buffCI = {};
5607 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5608 buffCI.size = 1024;
5609 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5610 buffCI.queueFamilyIndexCount = 1;
5611 buffCI.pQueueFamilyIndices = &qfi;
5612
5613 VkBuffer buffer;
5614 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5615 ASSERT_VK_SUCCESS(err);
5616 // Allocate memory and bind to buffer so we can make it to the appropriate
5617 // error
5618 VkMemoryAllocateInfo mem_alloc = {};
5619 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5620 mem_alloc.pNext = NULL;
5621 mem_alloc.allocationSize = 1024;
5622 mem_alloc.memoryTypeIndex = 0;
5623
5624 VkMemoryRequirements memReqs;
5625 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005626 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005627 if (!pass) {
5628 vkDestroyBuffer(m_device->device(), buffer, NULL);
5629 return;
5630 }
5631
5632 VkDeviceMemory mem;
5633 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5634 ASSERT_VK_SUCCESS(err);
5635 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5636 ASSERT_VK_SUCCESS(err);
5637 // Correctly update descriptor to avoid "NOT_UPDATED" error
5638 VkDescriptorBufferInfo buffInfo = {};
5639 buffInfo.buffer = buffer;
5640 buffInfo.offset = 0;
5641 buffInfo.range = 1024;
5642
5643 VkWriteDescriptorSet descriptor_write;
5644 memset(&descriptor_write, 0, sizeof(descriptor_write));
5645 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5646 descriptor_write.dstSet = descriptorSet;
5647 descriptor_write.dstBinding = 0;
5648 descriptor_write.descriptorCount = 1;
5649 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5650 descriptor_write.pBufferInfo = &buffInfo;
5651
5652 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5653
5654 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005655 char const *vsSource =
5656 "#version 450\n"
5657 "\n"
5658 "out gl_PerVertex { \n"
5659 " vec4 gl_Position;\n"
5660 "};\n"
5661 "void main(){\n"
5662 " gl_Position = vec4(1);\n"
5663 "}\n";
5664 char const *fsSource =
5665 "#version 450\n"
5666 "\n"
5667 "layout(location=0) out vec4 x;\n"
5668 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5669 "void main(){\n"
5670 " x = vec4(bar.y);\n"
5671 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005672 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5673 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5674 VkPipelineObj pipe(m_device);
5675 pipe.AddShader(&vs);
5676 pipe.AddShader(&fs);
5677 pipe.AddColorAttachment();
5678 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5679
Tony Barbour552f6c02016-12-21 14:34:07 -07005680 m_commandBuffer->BeginCommandBuffer();
5681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5683 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5684 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005685
5686 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5687 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5688
Tobin Ehlis31289162016-08-17 14:57:58 -06005689 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005690 m_commandBuffer->EndRenderPass();
5691 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005693 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5694 vkDestroyBuffer(m_device->device(), buffer, NULL);
5695 // Attempt to submit cmd buffer
5696 VkSubmitInfo submit_info = {};
5697 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5698 submit_info.commandBufferCount = 1;
5699 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005700 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis31289162016-08-17 14:57:58 -06005701 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5702 m_errorMonitor->VerifyFound();
5703 // Cleanup
5704 vkFreeMemory(m_device->device(), mem, NULL);
5705
5706 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5707 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5708 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5709}
5710
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005711TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005712 TEST_DESCRIPTION(
5713 "Attempt to draw with a command buffer that is invalid "
5714 "due to a bound descriptor sets with a combined image "
5715 "sampler having their image, sampler, and descriptor set "
5716 "each respectively destroyed and then attempting to "
5717 "submit associated cmd buffers. Attempt to destroy a "
5718 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005719 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005720 ASSERT_NO_FATAL_FAILURE(InitViewport());
5721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5722
5723 VkDescriptorPoolSize ds_type_count = {};
5724 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5725 ds_type_count.descriptorCount = 1;
5726
5727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5729 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005730 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005731 ds_pool_ci.maxSets = 1;
5732 ds_pool_ci.poolSizeCount = 1;
5733 ds_pool_ci.pPoolSizes = &ds_type_count;
5734
5735 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005736 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005737 ASSERT_VK_SUCCESS(err);
5738
5739 VkDescriptorSetLayoutBinding dsl_binding = {};
5740 dsl_binding.binding = 0;
5741 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5742 dsl_binding.descriptorCount = 1;
5743 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5744 dsl_binding.pImmutableSamplers = NULL;
5745
5746 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5747 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5748 ds_layout_ci.pNext = NULL;
5749 ds_layout_ci.bindingCount = 1;
5750 ds_layout_ci.pBindings = &dsl_binding;
5751 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005752 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005753 ASSERT_VK_SUCCESS(err);
5754
5755 VkDescriptorSet descriptorSet;
5756 VkDescriptorSetAllocateInfo alloc_info = {};
5757 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5758 alloc_info.descriptorSetCount = 1;
5759 alloc_info.descriptorPool = ds_pool;
5760 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005761 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005762 ASSERT_VK_SUCCESS(err);
5763
5764 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5765 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5766 pipeline_layout_ci.pNext = NULL;
5767 pipeline_layout_ci.setLayoutCount = 1;
5768 pipeline_layout_ci.pSetLayouts = &ds_layout;
5769
5770 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005771 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005772 ASSERT_VK_SUCCESS(err);
5773
5774 // Create images to update the descriptor with
5775 VkImage image;
5776 VkImage image2;
5777 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5778 const int32_t tex_width = 32;
5779 const int32_t tex_height = 32;
5780 VkImageCreateInfo image_create_info = {};
5781 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5782 image_create_info.pNext = NULL;
5783 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5784 image_create_info.format = tex_format;
5785 image_create_info.extent.width = tex_width;
5786 image_create_info.extent.height = tex_height;
5787 image_create_info.extent.depth = 1;
5788 image_create_info.mipLevels = 1;
5789 image_create_info.arrayLayers = 1;
5790 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5791 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5792 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5793 image_create_info.flags = 0;
5794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5795 ASSERT_VK_SUCCESS(err);
5796 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5797 ASSERT_VK_SUCCESS(err);
5798
5799 VkMemoryRequirements memory_reqs;
5800 VkDeviceMemory image_memory;
5801 bool pass;
5802 VkMemoryAllocateInfo memory_info = {};
5803 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5804 memory_info.pNext = NULL;
5805 memory_info.allocationSize = 0;
5806 memory_info.memoryTypeIndex = 0;
5807 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5808 // Allocate enough memory for both images
5809 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005810 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005811 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005812 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005813 ASSERT_VK_SUCCESS(err);
5814 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5815 ASSERT_VK_SUCCESS(err);
5816 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005817 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005818 ASSERT_VK_SUCCESS(err);
5819
5820 VkImageViewCreateInfo image_view_create_info = {};
5821 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5822 image_view_create_info.image = image;
5823 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5824 image_view_create_info.format = tex_format;
5825 image_view_create_info.subresourceRange.layerCount = 1;
5826 image_view_create_info.subresourceRange.baseMipLevel = 0;
5827 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005828 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005829
5830 VkImageView view;
5831 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005832 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005833 ASSERT_VK_SUCCESS(err);
5834 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005835 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005836 ASSERT_VK_SUCCESS(err);
5837 // Create Samplers
5838 VkSamplerCreateInfo sampler_ci = {};
5839 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5840 sampler_ci.pNext = NULL;
5841 sampler_ci.magFilter = VK_FILTER_NEAREST;
5842 sampler_ci.minFilter = VK_FILTER_NEAREST;
5843 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5844 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5845 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5846 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5847 sampler_ci.mipLodBias = 1.0;
5848 sampler_ci.anisotropyEnable = VK_FALSE;
5849 sampler_ci.maxAnisotropy = 1;
5850 sampler_ci.compareEnable = VK_FALSE;
5851 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5852 sampler_ci.minLod = 1.0;
5853 sampler_ci.maxLod = 1.0;
5854 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5855 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5856 VkSampler sampler;
5857 VkSampler sampler2;
5858 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5859 ASSERT_VK_SUCCESS(err);
5860 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5861 ASSERT_VK_SUCCESS(err);
5862 // Update descriptor with image and sampler
5863 VkDescriptorImageInfo img_info = {};
5864 img_info.sampler = sampler;
5865 img_info.imageView = view;
5866 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5867
5868 VkWriteDescriptorSet descriptor_write;
5869 memset(&descriptor_write, 0, sizeof(descriptor_write));
5870 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5871 descriptor_write.dstSet = descriptorSet;
5872 descriptor_write.dstBinding = 0;
5873 descriptor_write.descriptorCount = 1;
5874 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5875 descriptor_write.pImageInfo = &img_info;
5876
5877 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5878
5879 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005880 char const *vsSource =
5881 "#version 450\n"
5882 "\n"
5883 "out gl_PerVertex { \n"
5884 " vec4 gl_Position;\n"
5885 "};\n"
5886 "void main(){\n"
5887 " gl_Position = vec4(1);\n"
5888 "}\n";
5889 char const *fsSource =
5890 "#version 450\n"
5891 "\n"
5892 "layout(set=0, binding=0) uniform sampler2D s;\n"
5893 "layout(location=0) out vec4 x;\n"
5894 "void main(){\n"
5895 " x = texture(s, vec2(1));\n"
5896 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005897 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5898 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5899 VkPipelineObj pipe(m_device);
5900 pipe.AddShader(&vs);
5901 pipe.AddShader(&fs);
5902 pipe.AddColorAttachment();
5903 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5904
5905 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005907 m_commandBuffer->BeginCommandBuffer();
5908 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005909 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5910 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5911 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005912 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5913 VkRect2D scissor = {{0, 0}, {16, 16}};
5914 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5915 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005916 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005917 m_commandBuffer->EndRenderPass();
5918 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005919 // Destroy sampler invalidates the cmd buffer, causing error on submit
5920 vkDestroySampler(m_device->device(), sampler, NULL);
5921 // Attempt to submit cmd buffer
5922 VkSubmitInfo submit_info = {};
5923 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5924 submit_info.commandBufferCount = 1;
5925 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005926 m_errorMonitor->SetUnexpectedError("that is invalid because bound sampler");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005927 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5928 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005929
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005930 // Now re-update descriptor with valid sampler and delete image
5931 img_info.sampler = sampler2;
5932 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005933
5934 VkCommandBufferBeginInfo info = {};
5935 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5936 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005939 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005940 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005941 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5942 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5943 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005944 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5945 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005946 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005947 m_commandBuffer->EndRenderPass();
5948 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005949 // Destroy image invalidates the cmd buffer, causing error on submit
5950 vkDestroyImage(m_device->device(), image, NULL);
5951 // Attempt to submit cmd buffer
5952 submit_info = {};
5953 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5954 submit_info.commandBufferCount = 1;
5955 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005956 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005957 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5958 m_errorMonitor->VerifyFound();
5959 // Now update descriptor to be valid, but then free descriptor
5960 img_info.imageView = view2;
5961 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005962 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005963 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005964 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5965 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5966 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005967 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5968 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005969 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005970 m_commandBuffer->EndRenderPass();
5971 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005972 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005973
5974 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005976 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005977 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005978
5979 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005980 // 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 -07005981 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005982 m_errorMonitor->SetUnexpectedError(
5983 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
5984 "either be a valid handle or VK_NULL_HANDLE");
5985 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07005986 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5987
5988 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005989 submit_info = {};
5990 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5991 submit_info.commandBufferCount = 1;
5992 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005994 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted descriptor set");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005995 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5996 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005997
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005998 // Cleanup
5999 vkFreeMemory(m_device->device(), image_memory, NULL);
6000 vkDestroySampler(m_device->device(), sampler2, NULL);
6001 vkDestroyImage(m_device->device(), image2, NULL);
6002 vkDestroyImageView(m_device->device(), view, NULL);
6003 vkDestroyImageView(m_device->device(), view2, NULL);
6004 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6005 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6006 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6007}
6008
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006009TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6010 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6011 ASSERT_NO_FATAL_FAILURE(InitState());
6012 ASSERT_NO_FATAL_FAILURE(InitViewport());
6013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6014
6015 VkDescriptorPoolSize ds_type_count = {};
6016 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6017 ds_type_count.descriptorCount = 1;
6018
6019 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6020 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6021 ds_pool_ci.pNext = NULL;
6022 ds_pool_ci.maxSets = 1;
6023 ds_pool_ci.poolSizeCount = 1;
6024 ds_pool_ci.pPoolSizes = &ds_type_count;
6025
6026 VkDescriptorPool ds_pool;
6027 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6028 ASSERT_VK_SUCCESS(err);
6029
6030 VkDescriptorSetLayoutBinding dsl_binding = {};
6031 dsl_binding.binding = 0;
6032 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6033 dsl_binding.descriptorCount = 1;
6034 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6035 dsl_binding.pImmutableSamplers = NULL;
6036
6037 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6038 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6039 ds_layout_ci.pNext = NULL;
6040 ds_layout_ci.bindingCount = 1;
6041 ds_layout_ci.pBindings = &dsl_binding;
6042 VkDescriptorSetLayout ds_layout;
6043 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6044 ASSERT_VK_SUCCESS(err);
6045
6046 VkDescriptorSet descriptor_set;
6047 VkDescriptorSetAllocateInfo alloc_info = {};
6048 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6049 alloc_info.descriptorSetCount = 1;
6050 alloc_info.descriptorPool = ds_pool;
6051 alloc_info.pSetLayouts = &ds_layout;
6052 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6053 ASSERT_VK_SUCCESS(err);
6054
6055 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6056 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6057 pipeline_layout_ci.pNext = NULL;
6058 pipeline_layout_ci.setLayoutCount = 1;
6059 pipeline_layout_ci.pSetLayouts = &ds_layout;
6060
6061 VkPipelineLayout pipeline_layout;
6062 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6063 ASSERT_VK_SUCCESS(err);
6064
6065 // Create image to update the descriptor with
6066 VkImageObj image(m_device);
6067 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6068 ASSERT_TRUE(image.initialized());
6069
6070 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6071 // Create Sampler
6072 VkSamplerCreateInfo sampler_ci = {};
6073 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6074 sampler_ci.pNext = NULL;
6075 sampler_ci.magFilter = VK_FILTER_NEAREST;
6076 sampler_ci.minFilter = VK_FILTER_NEAREST;
6077 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6078 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6079 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6080 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6081 sampler_ci.mipLodBias = 1.0;
6082 sampler_ci.anisotropyEnable = VK_FALSE;
6083 sampler_ci.maxAnisotropy = 1;
6084 sampler_ci.compareEnable = VK_FALSE;
6085 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6086 sampler_ci.minLod = 1.0;
6087 sampler_ci.maxLod = 1.0;
6088 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6089 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6090 VkSampler sampler;
6091 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6092 ASSERT_VK_SUCCESS(err);
6093 // Update descriptor with image and sampler
6094 VkDescriptorImageInfo img_info = {};
6095 img_info.sampler = sampler;
6096 img_info.imageView = view;
6097 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6098
6099 VkWriteDescriptorSet descriptor_write;
6100 memset(&descriptor_write, 0, sizeof(descriptor_write));
6101 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6102 descriptor_write.dstSet = descriptor_set;
6103 descriptor_write.dstBinding = 0;
6104 descriptor_write.descriptorCount = 1;
6105 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6106 descriptor_write.pImageInfo = &img_info;
6107
6108 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6109
6110 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006111 char const *vsSource =
6112 "#version 450\n"
6113 "\n"
6114 "out gl_PerVertex { \n"
6115 " vec4 gl_Position;\n"
6116 "};\n"
6117 "void main(){\n"
6118 " gl_Position = vec4(1);\n"
6119 "}\n";
6120 char const *fsSource =
6121 "#version 450\n"
6122 "\n"
6123 "layout(set=0, binding=0) uniform sampler2D s;\n"
6124 "layout(location=0) out vec4 x;\n"
6125 "void main(){\n"
6126 " x = texture(s, vec2(1));\n"
6127 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006128 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6129 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6130 VkPipelineObj pipe(m_device);
6131 pipe.AddShader(&vs);
6132 pipe.AddShader(&fs);
6133 pipe.AddColorAttachment();
6134 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6135
Tony Barbour552f6c02016-12-21 14:34:07 -07006136 m_commandBuffer->BeginCommandBuffer();
6137 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006138 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6139 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6140 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006141
6142 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6143 VkRect2D scissor = {{0, 0}, {16, 16}};
6144 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6145 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6146
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006147 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006148 m_commandBuffer->EndRenderPass();
6149 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006150 // Submit cmd buffer to put pool in-flight
6151 VkSubmitInfo submit_info = {};
6152 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6153 submit_info.commandBufferCount = 1;
6154 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6155 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6156 // Destroy pool while in-flight, causing error
6157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6158 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6159 m_errorMonitor->VerifyFound();
6160 vkQueueWaitIdle(m_device->m_queue);
6161 // Cleanup
6162 vkDestroySampler(m_device->device(), sampler, NULL);
6163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6164 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006165 m_errorMonitor->SetUnexpectedError(
6166 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6167 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006168 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006169 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006170}
6171
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006172TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6173 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6174 ASSERT_NO_FATAL_FAILURE(InitState());
6175 ASSERT_NO_FATAL_FAILURE(InitViewport());
6176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6177
6178 VkDescriptorPoolSize ds_type_count = {};
6179 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6180 ds_type_count.descriptorCount = 1;
6181
6182 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6183 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6184 ds_pool_ci.pNext = NULL;
6185 ds_pool_ci.maxSets = 1;
6186 ds_pool_ci.poolSizeCount = 1;
6187 ds_pool_ci.pPoolSizes = &ds_type_count;
6188
6189 VkDescriptorPool ds_pool;
6190 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6191 ASSERT_VK_SUCCESS(err);
6192
6193 VkDescriptorSetLayoutBinding dsl_binding = {};
6194 dsl_binding.binding = 0;
6195 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6196 dsl_binding.descriptorCount = 1;
6197 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6198 dsl_binding.pImmutableSamplers = NULL;
6199
6200 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6201 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6202 ds_layout_ci.pNext = NULL;
6203 ds_layout_ci.bindingCount = 1;
6204 ds_layout_ci.pBindings = &dsl_binding;
6205 VkDescriptorSetLayout ds_layout;
6206 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6207 ASSERT_VK_SUCCESS(err);
6208
6209 VkDescriptorSet descriptorSet;
6210 VkDescriptorSetAllocateInfo alloc_info = {};
6211 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6212 alloc_info.descriptorSetCount = 1;
6213 alloc_info.descriptorPool = ds_pool;
6214 alloc_info.pSetLayouts = &ds_layout;
6215 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6216 ASSERT_VK_SUCCESS(err);
6217
6218 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6219 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6220 pipeline_layout_ci.pNext = NULL;
6221 pipeline_layout_ci.setLayoutCount = 1;
6222 pipeline_layout_ci.pSetLayouts = &ds_layout;
6223
6224 VkPipelineLayout pipeline_layout;
6225 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6226 ASSERT_VK_SUCCESS(err);
6227
6228 // Create images to update the descriptor with
6229 VkImage image;
6230 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6231 const int32_t tex_width = 32;
6232 const int32_t tex_height = 32;
6233 VkImageCreateInfo image_create_info = {};
6234 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6235 image_create_info.pNext = NULL;
6236 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6237 image_create_info.format = tex_format;
6238 image_create_info.extent.width = tex_width;
6239 image_create_info.extent.height = tex_height;
6240 image_create_info.extent.depth = 1;
6241 image_create_info.mipLevels = 1;
6242 image_create_info.arrayLayers = 1;
6243 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6244 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6245 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6246 image_create_info.flags = 0;
6247 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6248 ASSERT_VK_SUCCESS(err);
6249 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6250 VkMemoryRequirements memory_reqs;
6251 VkDeviceMemory image_memory;
6252 bool pass;
6253 VkMemoryAllocateInfo memory_info = {};
6254 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6255 memory_info.pNext = NULL;
6256 memory_info.allocationSize = 0;
6257 memory_info.memoryTypeIndex = 0;
6258 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6259 // Allocate enough memory for image
6260 memory_info.allocationSize = memory_reqs.size;
6261 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6262 ASSERT_TRUE(pass);
6263 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6264 ASSERT_VK_SUCCESS(err);
6265 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6266 ASSERT_VK_SUCCESS(err);
6267
6268 VkImageViewCreateInfo image_view_create_info = {};
6269 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6270 image_view_create_info.image = image;
6271 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6272 image_view_create_info.format = tex_format;
6273 image_view_create_info.subresourceRange.layerCount = 1;
6274 image_view_create_info.subresourceRange.baseMipLevel = 0;
6275 image_view_create_info.subresourceRange.levelCount = 1;
6276 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6277
6278 VkImageView view;
6279 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6280 ASSERT_VK_SUCCESS(err);
6281 // Create Samplers
6282 VkSamplerCreateInfo sampler_ci = {};
6283 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6284 sampler_ci.pNext = NULL;
6285 sampler_ci.magFilter = VK_FILTER_NEAREST;
6286 sampler_ci.minFilter = VK_FILTER_NEAREST;
6287 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6288 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6289 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6290 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6291 sampler_ci.mipLodBias = 1.0;
6292 sampler_ci.anisotropyEnable = VK_FALSE;
6293 sampler_ci.maxAnisotropy = 1;
6294 sampler_ci.compareEnable = VK_FALSE;
6295 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6296 sampler_ci.minLod = 1.0;
6297 sampler_ci.maxLod = 1.0;
6298 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6299 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6300 VkSampler sampler;
6301 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6302 ASSERT_VK_SUCCESS(err);
6303 // Update descriptor with image and sampler
6304 VkDescriptorImageInfo img_info = {};
6305 img_info.sampler = sampler;
6306 img_info.imageView = view;
6307 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6308
6309 VkWriteDescriptorSet descriptor_write;
6310 memset(&descriptor_write, 0, sizeof(descriptor_write));
6311 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6312 descriptor_write.dstSet = descriptorSet;
6313 descriptor_write.dstBinding = 0;
6314 descriptor_write.descriptorCount = 1;
6315 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6316 descriptor_write.pImageInfo = &img_info;
6317 // Break memory binding and attempt update
6318 vkFreeMemory(m_device->device(), image_memory, nullptr);
6319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006320 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6322 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6323 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6324 m_errorMonitor->VerifyFound();
6325 // Cleanup
6326 vkDestroyImage(m_device->device(), image, NULL);
6327 vkDestroySampler(m_device->device(), sampler, NULL);
6328 vkDestroyImageView(m_device->device(), view, NULL);
6329 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6330 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6331 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6332}
6333
Karl Schultz6addd812016-02-02 17:17:23 -07006334TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006335 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6336 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006337 // Create a valid cmd buffer
6338 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006339 uint64_t fake_pipeline_handle = 0xbaad6001;
6340 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006341 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6343
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006345 m_commandBuffer->BeginCommandBuffer();
6346 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006347 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006348 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006349
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006350 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006351 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 -06006352 Draw(1, 0, 0, 0);
6353 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006354
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006355 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006356 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 -07006357 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006358 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6359 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006360}
6361
Karl Schultz6addd812016-02-02 17:17:23 -07006362TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006363 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006364 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006365
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006367
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006368 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006369 ASSERT_NO_FATAL_FAILURE(InitViewport());
6370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006371 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006372 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6373 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006374
6375 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006376 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6377 ds_pool_ci.pNext = NULL;
6378 ds_pool_ci.maxSets = 1;
6379 ds_pool_ci.poolSizeCount = 1;
6380 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006381
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006382 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006383 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006384 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006385
Tony Barboureb254902015-07-15 12:50:33 -06006386 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006387 dsl_binding.binding = 0;
6388 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6389 dsl_binding.descriptorCount = 1;
6390 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6391 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006392
Tony Barboureb254902015-07-15 12:50:33 -06006393 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006394 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6395 ds_layout_ci.pNext = NULL;
6396 ds_layout_ci.bindingCount = 1;
6397 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006398 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006399 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006400 ASSERT_VK_SUCCESS(err);
6401
6402 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006403 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006404 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006405 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006406 alloc_info.descriptorPool = ds_pool;
6407 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006409 ASSERT_VK_SUCCESS(err);
6410
Tony Barboureb254902015-07-15 12:50:33 -06006411 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006412 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6413 pipeline_layout_ci.pNext = NULL;
6414 pipeline_layout_ci.setLayoutCount = 1;
6415 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006416
6417 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006419 ASSERT_VK_SUCCESS(err);
6420
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006421 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006422 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006423 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006424 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006425
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006426 VkPipelineObj pipe(m_device);
6427 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006428 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006429 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006430 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006431
Tony Barbour552f6c02016-12-21 14:34:07 -07006432 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6434 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6435 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006436
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006437 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006438
Chia-I Wuf7458c52015-10-26 21:10:41 +08006439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006442}
6443
Karl Schultz6addd812016-02-02 17:17:23 -07006444TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006445 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006446 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006447
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006449
6450 ASSERT_NO_FATAL_FAILURE(InitState());
6451 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006452 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6453 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006454
6455 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006456 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6457 ds_pool_ci.pNext = NULL;
6458 ds_pool_ci.maxSets = 1;
6459 ds_pool_ci.poolSizeCount = 1;
6460 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006461
6462 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006463 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006464 ASSERT_VK_SUCCESS(err);
6465
6466 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006467 dsl_binding.binding = 0;
6468 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6469 dsl_binding.descriptorCount = 1;
6470 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6471 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006472
6473 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006474 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6475 ds_layout_ci.pNext = NULL;
6476 ds_layout_ci.bindingCount = 1;
6477 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006478 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006479 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006480 ASSERT_VK_SUCCESS(err);
6481
6482 VkDescriptorSet descriptorSet;
6483 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006484 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006485 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006486 alloc_info.descriptorPool = ds_pool;
6487 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006488 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006489 ASSERT_VK_SUCCESS(err);
6490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006491 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006492 VkWriteDescriptorSet descriptor_write;
6493 memset(&descriptor_write, 0, sizeof(descriptor_write));
6494 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6495 descriptor_write.dstSet = descriptorSet;
6496 descriptor_write.dstBinding = 0;
6497 descriptor_write.descriptorCount = 1;
6498 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6499 descriptor_write.pTexelBufferView = &view;
6500
6501 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6502
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006503 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006504
6505 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6506 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6507}
6508
Mark Youngd339ba32016-05-30 13:28:35 -06006509TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006510 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 -06006511
6512 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006514 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006515
6516 ASSERT_NO_FATAL_FAILURE(InitState());
6517
6518 // Create a buffer with no bound memory and then attempt to create
6519 // a buffer view.
6520 VkBufferCreateInfo buff_ci = {};
6521 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006522 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006523 buff_ci.size = 256;
6524 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6525 VkBuffer buffer;
6526 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6527 ASSERT_VK_SUCCESS(err);
6528
6529 VkBufferViewCreateInfo buff_view_ci = {};
6530 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6531 buff_view_ci.buffer = buffer;
6532 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6533 buff_view_ci.range = VK_WHOLE_SIZE;
6534 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006535 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006536
6537 m_errorMonitor->VerifyFound();
6538 vkDestroyBuffer(m_device->device(), buffer, NULL);
6539 // If last error is success, it still created the view, so delete it.
6540 if (err == VK_SUCCESS) {
6541 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6542 }
6543}
6544
Karl Schultz6addd812016-02-02 17:17:23 -07006545TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6546 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6547 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006548 // 1. No dynamicOffset supplied
6549 // 2. Too many dynamicOffsets supplied
6550 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006551 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6553 " requires 1 dynamicOffsets, but only "
6554 "0 dynamicOffsets are left in "
6555 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006556
6557 ASSERT_NO_FATAL_FAILURE(InitState());
6558 ASSERT_NO_FATAL_FAILURE(InitViewport());
6559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6560
6561 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006562 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6563 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006564
6565 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006566 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6567 ds_pool_ci.pNext = NULL;
6568 ds_pool_ci.maxSets = 1;
6569 ds_pool_ci.poolSizeCount = 1;
6570 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006571
6572 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006573 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006574 ASSERT_VK_SUCCESS(err);
6575
6576 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006577 dsl_binding.binding = 0;
6578 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6579 dsl_binding.descriptorCount = 1;
6580 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6581 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006582
6583 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006584 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6585 ds_layout_ci.pNext = NULL;
6586 ds_layout_ci.bindingCount = 1;
6587 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006588 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006589 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006590 ASSERT_VK_SUCCESS(err);
6591
6592 VkDescriptorSet descriptorSet;
6593 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006594 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006595 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006596 alloc_info.descriptorPool = ds_pool;
6597 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006598 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006599 ASSERT_VK_SUCCESS(err);
6600
6601 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006602 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6603 pipeline_layout_ci.pNext = NULL;
6604 pipeline_layout_ci.setLayoutCount = 1;
6605 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006606
6607 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006609 ASSERT_VK_SUCCESS(err);
6610
6611 // Create a buffer to update the descriptor with
6612 uint32_t qfi = 0;
6613 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006614 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6615 buffCI.size = 1024;
6616 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6617 buffCI.queueFamilyIndexCount = 1;
6618 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006619
6620 VkBuffer dyub;
6621 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6622 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006623 // Allocate memory and bind to buffer so we can make it to the appropriate
6624 // error
6625 VkMemoryAllocateInfo mem_alloc = {};
6626 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6627 mem_alloc.pNext = NULL;
6628 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006629 mem_alloc.memoryTypeIndex = 0;
6630
6631 VkMemoryRequirements memReqs;
6632 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006633 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006634 if (!pass) {
6635 vkDestroyBuffer(m_device->device(), dyub, NULL);
6636 return;
6637 }
6638
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006639 VkDeviceMemory mem;
6640 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6641 ASSERT_VK_SUCCESS(err);
6642 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6643 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006644 // Correctly update descriptor to avoid "NOT_UPDATED" error
6645 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006646 buffInfo.buffer = dyub;
6647 buffInfo.offset = 0;
6648 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006649
6650 VkWriteDescriptorSet descriptor_write;
6651 memset(&descriptor_write, 0, sizeof(descriptor_write));
6652 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6653 descriptor_write.dstSet = descriptorSet;
6654 descriptor_write.dstBinding = 0;
6655 descriptor_write.descriptorCount = 1;
6656 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6657 descriptor_write.pBufferInfo = &buffInfo;
6658
6659 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6660
Tony Barbour552f6c02016-12-21 14:34:07 -07006661 m_commandBuffer->BeginCommandBuffer();
6662 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006663 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6664 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006665 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006666 uint32_t pDynOff[2] = {512, 756};
6667 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6669 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6670 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6671 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006672 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006673 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6675 " dynamic offset 512 combined with "
6676 "offset 0 and range 1024 that "
6677 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006678 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006679 char const *vsSource =
6680 "#version 450\n"
6681 "\n"
6682 "out gl_PerVertex { \n"
6683 " vec4 gl_Position;\n"
6684 "};\n"
6685 "void main(){\n"
6686 " gl_Position = vec4(1);\n"
6687 "}\n";
6688 char const *fsSource =
6689 "#version 450\n"
6690 "\n"
6691 "layout(location=0) out vec4 x;\n"
6692 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6693 "void main(){\n"
6694 " x = vec4(bar.y);\n"
6695 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6697 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6698 VkPipelineObj pipe(m_device);
6699 pipe.AddShader(&vs);
6700 pipe.AddShader(&fs);
6701 pipe.AddColorAttachment();
6702 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6703
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006704 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6705 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6706 VkRect2D scissor = {{0, 0}, {16, 16}};
6707 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006709 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006710 // This update should succeed, but offset size of 512 will overstep buffer
6711 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006712 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6713 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006714 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006715 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006716
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006717 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006718 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006719
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006720 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006721 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006722 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6723}
6724
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006725TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006726 TEST_DESCRIPTION(
6727 "Attempt to update a descriptor with a non-sparse buffer "
6728 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006729 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006731 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6733 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006734
6735 ASSERT_NO_FATAL_FAILURE(InitState());
6736 ASSERT_NO_FATAL_FAILURE(InitViewport());
6737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6738
6739 VkDescriptorPoolSize ds_type_count = {};
6740 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6741 ds_type_count.descriptorCount = 1;
6742
6743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6745 ds_pool_ci.pNext = NULL;
6746 ds_pool_ci.maxSets = 1;
6747 ds_pool_ci.poolSizeCount = 1;
6748 ds_pool_ci.pPoolSizes = &ds_type_count;
6749
6750 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006752 ASSERT_VK_SUCCESS(err);
6753
6754 VkDescriptorSetLayoutBinding dsl_binding = {};
6755 dsl_binding.binding = 0;
6756 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6757 dsl_binding.descriptorCount = 1;
6758 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6759 dsl_binding.pImmutableSamplers = NULL;
6760
6761 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6762 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6763 ds_layout_ci.pNext = NULL;
6764 ds_layout_ci.bindingCount = 1;
6765 ds_layout_ci.pBindings = &dsl_binding;
6766 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006767 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006768 ASSERT_VK_SUCCESS(err);
6769
6770 VkDescriptorSet descriptorSet;
6771 VkDescriptorSetAllocateInfo alloc_info = {};
6772 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6773 alloc_info.descriptorSetCount = 1;
6774 alloc_info.descriptorPool = ds_pool;
6775 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006776 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006777 ASSERT_VK_SUCCESS(err);
6778
6779 // Create a buffer to update the descriptor with
6780 uint32_t qfi = 0;
6781 VkBufferCreateInfo buffCI = {};
6782 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6783 buffCI.size = 1024;
6784 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6785 buffCI.queueFamilyIndexCount = 1;
6786 buffCI.pQueueFamilyIndices = &qfi;
6787
6788 VkBuffer dyub;
6789 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6790 ASSERT_VK_SUCCESS(err);
6791
6792 // Attempt to update descriptor without binding memory to it
6793 VkDescriptorBufferInfo buffInfo = {};
6794 buffInfo.buffer = dyub;
6795 buffInfo.offset = 0;
6796 buffInfo.range = 1024;
6797
6798 VkWriteDescriptorSet descriptor_write;
6799 memset(&descriptor_write, 0, sizeof(descriptor_write));
6800 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6801 descriptor_write.dstSet = descriptorSet;
6802 descriptor_write.dstBinding = 0;
6803 descriptor_write.descriptorCount = 1;
6804 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6805 descriptor_write.pBufferInfo = &buffInfo;
6806
6807 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6808 m_errorMonitor->VerifyFound();
6809
6810 vkDestroyBuffer(m_device->device(), dyub, NULL);
6811 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6812 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6813}
6814
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006815TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006816 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006817 ASSERT_NO_FATAL_FAILURE(InitState());
6818 ASSERT_NO_FATAL_FAILURE(InitViewport());
6819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6820
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006821 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006822 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006823 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6824 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6825 pipeline_layout_ci.pushConstantRangeCount = 1;
6826 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6827
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006828 //
6829 // Check for invalid push constant ranges in pipeline layouts.
6830 //
6831 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006832 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006833 char const *msg;
6834 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006835
Karl Schultzc81037d2016-05-12 08:11:23 -06006836 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6837 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6838 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6839 "vkCreatePipelineLayout() call has push constants index 0 with "
6840 "size 0."},
6841 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6842 "vkCreatePipelineLayout() call has push constants index 0 with "
6843 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006844 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006845 "vkCreatePipelineLayout() call has push constants index 0 with "
6846 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006847 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006848 "vkCreatePipelineLayout() call has push constants index 0 with "
6849 "size 0."},
6850 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6851 "vkCreatePipelineLayout() call has push constants index 0 with "
6852 "offset 1. Offset must"},
6853 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6854 "vkCreatePipelineLayout() call has push constants index 0 "
6855 "with offset "},
6856 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6857 "vkCreatePipelineLayout() call has push constants "
6858 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006859 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006860 "vkCreatePipelineLayout() call has push constants index 0 "
6861 "with offset "},
6862 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6863 "vkCreatePipelineLayout() call has push "
6864 "constants index 0 with offset "},
6865 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6866 "vkCreatePipelineLayout() call has push "
6867 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006868 }};
6869
6870 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006871 for (const auto &iter : range_tests) {
6872 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6874 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006875 m_errorMonitor->VerifyFound();
6876 if (VK_SUCCESS == err) {
6877 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6878 }
6879 }
6880
6881 // Check for invalid stage flag
6882 pc_range.offset = 0;
6883 pc_range.size = 16;
6884 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006885 m_errorMonitor->SetDesiredFailureMsg(
6886 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6887 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006888 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006889 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006890 if (VK_SUCCESS == err) {
6891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6892 }
6893
6894 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006895 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006896 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006897 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006898 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006899 };
6900
Karl Schultzc81037d2016-05-12 08:11:23 -06006901 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006902 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6903 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6904 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6905 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6906 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006907 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6908 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6909 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6910 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6911 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6912 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6913 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6914 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6915 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6916 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006917 {
6918 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6919 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6920 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6921 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6922 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006923 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006924 },
6925 {
6926 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6927 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6928 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6929 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6930 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006931 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006932 },
6933 {
6934 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6935 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6936 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6937 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6938 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006939 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006940 },
6941 {
6942 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6943 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6944 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6945 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6946 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006947 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6948 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6949 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6950 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006951 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006952
Karl Schultzc81037d2016-05-12 08:11:23 -06006953 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006954 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006955 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006957 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006958 m_errorMonitor->VerifyFound();
6959 if (VK_SUCCESS == err) {
6960 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6961 }
6962 }
6963
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006964 //
6965 // CmdPushConstants tests
6966 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006967 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006968
6969 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006970 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6971 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006972 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006973 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6974 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006975 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006976 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6977 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006978 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006979 "vkCmdPushConstants() call has push constants with offset 1. "
6980 "Offset must be a multiple of 4."},
6981 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6982 "vkCmdPushConstants() call has push constants with offset 1. "
6983 "Offset must be a multiple of 4."},
6984 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6985 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6986 "0x1 not within flag-matching ranges in pipeline layout"},
6987 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6988 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6989 "0x1 not within flag-matching ranges in pipeline layout"},
6990 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6991 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6992 "0x1 not within flag-matching ranges in pipeline layout"},
6993 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6994 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6995 "0x1 not within flag-matching ranges in pipeline layout"},
6996 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6997 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6998 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006999 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06007000 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
7001 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007002 }};
7003
Tony Barbour552f6c02016-12-21 14:34:07 -07007004 m_commandBuffer->BeginCommandBuffer();
7005 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007006
7007 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06007008 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007009 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007010 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007011 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007012 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007013 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007014 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007015 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7017 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007018 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007019 m_errorMonitor->VerifyFound();
7020 }
7021
7022 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007024 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007025 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06007026 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007027
Karl Schultzc81037d2016-05-12 08:11:23 -06007028 // overlapping range tests with cmd
7029 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
7030 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
7031 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
7032 "0x1 not within flag-matching ranges in pipeline layout"},
7033 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
7034 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
7035 "0x1 not within flag-matching ranges in pipeline layout"},
7036 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
7037 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
7038 "0x1 not within flag-matching ranges in pipeline layout"},
7039 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007040 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06007041 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007042 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
7043 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06007044 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007045 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06007046 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06007048 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007049 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7051 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007052 iter.range.size, dummy_values);
7053 m_errorMonitor->VerifyFound();
7054 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007055 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7056
Tony Barbour552f6c02016-12-21 14:34:07 -07007057 m_commandBuffer->EndRenderPass();
7058 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007059}
7060
Karl Schultz6addd812016-02-02 17:17:23 -07007061TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007062 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007063 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007064
7065 ASSERT_NO_FATAL_FAILURE(InitState());
7066 ASSERT_NO_FATAL_FAILURE(InitViewport());
7067 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7068
7069 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7070 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007071 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7072 ds_type_count[0].descriptorCount = 10;
7073 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7074 ds_type_count[1].descriptorCount = 2;
7075 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7076 ds_type_count[2].descriptorCount = 2;
7077 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7078 ds_type_count[3].descriptorCount = 5;
7079 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7080 // type
7081 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7082 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7083 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007084
7085 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007086 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7087 ds_pool_ci.pNext = NULL;
7088 ds_pool_ci.maxSets = 5;
7089 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7090 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007091
7092 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007093 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007094 ASSERT_VK_SUCCESS(err);
7095
7096 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7097 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007098 dsl_binding[0].binding = 0;
7099 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7100 dsl_binding[0].descriptorCount = 5;
7101 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7102 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007103
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007104 // Create layout identical to set0 layout but w/ different stageFlags
7105 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007106 dsl_fs_stage_only.binding = 0;
7107 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7108 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007109 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7110 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007111 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007112 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007113 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7114 ds_layout_ci.pNext = NULL;
7115 ds_layout_ci.bindingCount = 1;
7116 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007117 static const uint32_t NUM_LAYOUTS = 4;
7118 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007119 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007120 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7121 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007122 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007123 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007124 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007125 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007126 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007127 dsl_binding[0].binding = 0;
7128 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007129 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007130 dsl_binding[1].binding = 1;
7131 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7132 dsl_binding[1].descriptorCount = 2;
7133 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7134 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007135 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007136 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007137 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007138 ASSERT_VK_SUCCESS(err);
7139 dsl_binding[0].binding = 0;
7140 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007141 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007142 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007143 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007144 ASSERT_VK_SUCCESS(err);
7145 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007146 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007147 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007148 ASSERT_VK_SUCCESS(err);
7149
7150 static const uint32_t NUM_SETS = 4;
7151 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7152 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007153 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007154 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007155 alloc_info.descriptorPool = ds_pool;
7156 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007157 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007158 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007159 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007160 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007161 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007162 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007163 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007164
7165 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007166 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7167 pipeline_layout_ci.pNext = NULL;
7168 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7169 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007170
7171 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007172 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007173 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007174 // Create pipelineLayout with only one setLayout
7175 pipeline_layout_ci.setLayoutCount = 1;
7176 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007177 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007178 ASSERT_VK_SUCCESS(err);
7179 // Create pipelineLayout with 2 descriptor setLayout at index 0
7180 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7181 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007182 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007183 ASSERT_VK_SUCCESS(err);
7184 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7185 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7186 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007187 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007188 ASSERT_VK_SUCCESS(err);
7189 // Create pipelineLayout with UB type, but stageFlags for FS only
7190 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7191 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007192 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007193 ASSERT_VK_SUCCESS(err);
7194 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7195 VkDescriptorSetLayout pl_bad_s0[2] = {};
7196 pl_bad_s0[0] = ds_layout_fs_only;
7197 pl_bad_s0[1] = ds_layout[1];
7198 pipeline_layout_ci.setLayoutCount = 2;
7199 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7200 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007201 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007202 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007203
Tobin Ehlis88452832015-12-03 09:40:56 -07007204 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007205 char const *vsSource =
7206 "#version 450\n"
7207 "\n"
7208 "out gl_PerVertex {\n"
7209 " vec4 gl_Position;\n"
7210 "};\n"
7211 "void main(){\n"
7212 " gl_Position = vec4(1);\n"
7213 "}\n";
7214 char const *fsSource =
7215 "#version 450\n"
7216 "\n"
7217 "layout(location=0) out vec4 x;\n"
7218 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7219 "void main(){\n"
7220 " x = vec4(bar.y);\n"
7221 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007222 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7223 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007224 VkPipelineObj pipe(m_device);
7225 pipe.AddShader(&vs);
7226 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007227 pipe.AddColorAttachment();
7228 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007229
Tony Barbour552f6c02016-12-21 14:34:07 -07007230 m_commandBuffer->BeginCommandBuffer();
7231 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007232
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007233 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007234 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7235 // of PSO
7236 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7237 // cmd_pipeline.c
7238 // due to the fact that cmd_alloc_dset_data() has not been called in
7239 // cmd_bind_graphics_pipeline()
7240 // TODO : Want to cause various binding incompatibility issues here to test
7241 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007242 // First cause various verify_layout_compatibility() fails
7243 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007244 // verify_set_layout_compatibility fail cases:
7245 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007247 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7248 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007249 m_errorMonitor->VerifyFound();
7250
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007251 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7253 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7254 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007255 m_errorMonitor->VerifyFound();
7256
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007257 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007258 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7259 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7261 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7262 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007263 m_errorMonitor->VerifyFound();
7264
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007265 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7266 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7268 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7269 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007270 m_errorMonitor->VerifyFound();
7271
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007272 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7273 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7275 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7276 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7277 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007278 m_errorMonitor->VerifyFound();
7279
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007280 // Cause INFO messages due to disturbing previously bound Sets
7281 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007282 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7283 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007284 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7286 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7287 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007288 m_errorMonitor->VerifyFound();
7289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007290 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7291 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007292 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7294 " newly bound as set #0 so set #1 and "
7295 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007296 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7297 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007298 m_errorMonitor->VerifyFound();
7299
Tobin Ehlis10fad692016-07-07 12:00:36 -06007300 // Now that we're done actively using the pipelineLayout that gfx pipeline
7301 // was created with, we should be able to delete it. Do that now to verify
7302 // that validation obeys pipelineLayout lifetime
7303 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7304
Tobin Ehlis88452832015-12-03 09:40:56 -07007305 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007306 // 1. Error due to not binding required set (we actually use same code as
7307 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007308 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7309 &descriptorSet[0], 0, NULL);
7310 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7311 &descriptorSet[1], 0, NULL);
7312 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 -07007313
7314 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7315 VkRect2D scissor = {{0, 0}, {16, 16}};
7316 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7317 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7318
Tobin Ehlis88452832015-12-03 09:40:56 -07007319 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007320 m_errorMonitor->VerifyFound();
7321
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007322 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007323 // 2. Error due to bound set not being compatible with PSO's
7324 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007325 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7326 &descriptorSet[0], 0, NULL);
7327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007328 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007329 m_errorMonitor->VerifyFound();
7330
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007331 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007332 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007333 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7334 }
7335 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007336 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7337 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7338}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007339
Karl Schultz6addd812016-02-02 17:17:23 -07007340TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7342 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007343
7344 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007345 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007346 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007347 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007348
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007349 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007350}
7351
Karl Schultz6addd812016-02-02 17:17:23 -07007352TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7353 VkResult err;
7354 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007355
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007357
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007358 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007359
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007360 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007361 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007362 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007363 cmd.commandPool = m_commandPool;
7364 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007365 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007366
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007367 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007368 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007369
7370 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007371 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007372 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7373
7374 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007375 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007376 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007377 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 -07007378 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007379
7380 // The error should be caught by validation of the BeginCommandBuffer call
7381 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7382
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007383 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007384 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007385}
7386
Karl Schultz6addd812016-02-02 17:17:23 -07007387TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007388 // Cause error due to Begin while recording CB
7389 // Then cause 2 errors for attempting to reset CB w/o having
7390 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7391 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007393
7394 ASSERT_NO_FATAL_FAILURE(InitState());
7395
7396 // Calls AllocateCommandBuffers
7397 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7398
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007399 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007400 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007401 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7402 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007403 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7404 cmd_buf_info.pNext = NULL;
7405 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007406 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007407
7408 // Begin CB to transition to recording state
7409 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7410 // Can't re-begin. This should trigger error
7411 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007412 m_errorMonitor->VerifyFound();
7413
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007415 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007416 // Reset attempt will trigger error due to incorrect CommandPool state
7417 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007418 m_errorMonitor->VerifyFound();
7419
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007421 // Transition CB to RECORDED state
7422 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7423 // Now attempting to Begin will implicitly reset, which triggers error
7424 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007425 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007426}
7427
Karl Schultz6addd812016-02-02 17:17:23 -07007428TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007429 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007430 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007431
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7433 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007434
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007435 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007437
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007438 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007439 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7440 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007441
7442 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007443 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7444 ds_pool_ci.pNext = NULL;
7445 ds_pool_ci.maxSets = 1;
7446 ds_pool_ci.poolSizeCount = 1;
7447 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007448
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007449 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007451 ASSERT_VK_SUCCESS(err);
7452
Tony Barboureb254902015-07-15 12:50:33 -06007453 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007454 dsl_binding.binding = 0;
7455 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7456 dsl_binding.descriptorCount = 1;
7457 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7458 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007459
Tony Barboureb254902015-07-15 12:50:33 -06007460 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007461 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7462 ds_layout_ci.pNext = NULL;
7463 ds_layout_ci.bindingCount = 1;
7464 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007465
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007466 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007467 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007468 ASSERT_VK_SUCCESS(err);
7469
7470 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007471 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007472 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007473 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007474 alloc_info.descriptorPool = ds_pool;
7475 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007476 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007477 ASSERT_VK_SUCCESS(err);
7478
Tony Barboureb254902015-07-15 12:50:33 -06007479 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007480 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7481 pipeline_layout_ci.setLayoutCount = 1;
7482 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007483
7484 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007485 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007486 ASSERT_VK_SUCCESS(err);
7487
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007488 VkViewport vp = {}; // Just need dummy vp to point to
7489 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007490
7491 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007492 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7493 vp_state_ci.scissorCount = 1;
7494 vp_state_ci.pScissors = &sc;
7495 vp_state_ci.viewportCount = 1;
7496 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007497
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007498 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7499 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7500 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7501 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7502 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7503 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007504 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007505 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007506 rs_state_ci.lineWidth = 1.0f;
7507
7508 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7509 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7510 vi_ci.pNext = nullptr;
7511 vi_ci.vertexBindingDescriptionCount = 0;
7512 vi_ci.pVertexBindingDescriptions = nullptr;
7513 vi_ci.vertexAttributeDescriptionCount = 0;
7514 vi_ci.pVertexAttributeDescriptions = nullptr;
7515
7516 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7517 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7518 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7519
7520 VkPipelineShaderStageCreateInfo shaderStages[2];
7521 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7522
7523 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7524 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007525 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007526 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007527
Tony Barboureb254902015-07-15 12:50:33 -06007528 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007529 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7530 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007531 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007532 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7533 gp_ci.layout = pipeline_layout;
7534 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007535 gp_ci.pVertexInputState = &vi_ci;
7536 gp_ci.pInputAssemblyState = &ia_ci;
7537
7538 gp_ci.stageCount = 1;
7539 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007540
7541 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007542 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7543 pc_ci.initialDataSize = 0;
7544 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007545
7546 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007547 VkPipelineCache pipelineCache;
7548
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007549 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007550 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007551 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007552 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007553
Chia-I Wuf7458c52015-10-26 21:10:41 +08007554 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7555 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007558}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007559
Tobin Ehlis912df022015-09-17 08:46:18 -06007560/*// TODO : This test should be good, but needs Tess support in compiler to run
7561TEST_F(VkLayerTest, InvalidPatchControlPoints)
7562{
7563 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007564 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007565
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007567 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7568primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007569
Tobin Ehlis912df022015-09-17 08:46:18 -06007570 ASSERT_NO_FATAL_FAILURE(InitState());
7571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007572
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007573 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007574 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007575 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007576
7577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7579 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007580 ds_pool_ci.poolSizeCount = 1;
7581 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007582
7583 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007584 err = vkCreateDescriptorPool(m_device->device(),
7585VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007586 ASSERT_VK_SUCCESS(err);
7587
7588 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007589 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007590 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007591 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007592 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7593 dsl_binding.pImmutableSamplers = NULL;
7594
7595 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007596 ds_layout_ci.sType =
7597VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007598 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007599 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007600 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007601
7602 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007603 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7604&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 ASSERT_VK_SUCCESS(err);
7606
7607 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007608 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7609VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007610 ASSERT_VK_SUCCESS(err);
7611
7612 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007613 pipeline_layout_ci.sType =
7614VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007615 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007616 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007617 pipeline_layout_ci.pSetLayouts = &ds_layout;
7618
7619 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007620 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7621&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007622 ASSERT_VK_SUCCESS(err);
7623
7624 VkPipelineShaderStageCreateInfo shaderStages[3];
7625 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7626
Karl Schultz6addd812016-02-02 17:17:23 -07007627 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7628this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007629 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007630 VkShaderObj
7631tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7632this);
7633 VkShaderObj
7634te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7635this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007636
Karl Schultz6addd812016-02-02 17:17:23 -07007637 shaderStages[0].sType =
7638VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007639 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007640 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007641 shaderStages[1].sType =
7642VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007643 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007644 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007645 shaderStages[2].sType =
7646VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007647 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007648 shaderStages[2].shader = te.handle();
7649
7650 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007651 iaCI.sType =
7652VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007653 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007654
7655 VkPipelineTessellationStateCreateInfo tsCI = {};
7656 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7657 tsCI.patchControlPoints = 0; // This will cause an error
7658
7659 VkGraphicsPipelineCreateInfo gp_ci = {};
7660 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7661 gp_ci.pNext = NULL;
7662 gp_ci.stageCount = 3;
7663 gp_ci.pStages = shaderStages;
7664 gp_ci.pVertexInputState = NULL;
7665 gp_ci.pInputAssemblyState = &iaCI;
7666 gp_ci.pTessellationState = &tsCI;
7667 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007668 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007669 gp_ci.pMultisampleState = NULL;
7670 gp_ci.pDepthStencilState = NULL;
7671 gp_ci.pColorBlendState = NULL;
7672 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7673 gp_ci.layout = pipeline_layout;
7674 gp_ci.renderPass = renderPass();
7675
7676 VkPipelineCacheCreateInfo pc_ci = {};
7677 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7678 pc_ci.pNext = NULL;
7679 pc_ci.initialSize = 0;
7680 pc_ci.initialData = 0;
7681 pc_ci.maxSize = 0;
7682
7683 VkPipeline pipeline;
7684 VkPipelineCache pipelineCache;
7685
Karl Schultz6addd812016-02-02 17:17:23 -07007686 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7687&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007688 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007689 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7690&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007691
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007692 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007693
Chia-I Wuf7458c52015-10-26 21:10:41 +08007694 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7695 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7696 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7697 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007698}
7699*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007700
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007701TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007702 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007703
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007704 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007705
Tobin Ehlise68360f2015-10-01 11:15:13 -06007706 ASSERT_NO_FATAL_FAILURE(InitState());
7707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007708
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007709 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007710 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7711 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007712
7713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7715 ds_pool_ci.maxSets = 1;
7716 ds_pool_ci.poolSizeCount = 1;
7717 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007718
7719 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007720 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007721 ASSERT_VK_SUCCESS(err);
7722
7723 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007724 dsl_binding.binding = 0;
7725 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7726 dsl_binding.descriptorCount = 1;
7727 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007728
7729 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007730 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7731 ds_layout_ci.bindingCount = 1;
7732 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007733
7734 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007735 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007736 ASSERT_VK_SUCCESS(err);
7737
7738 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007739 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007740 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007741 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007742 alloc_info.descriptorPool = ds_pool;
7743 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007745 ASSERT_VK_SUCCESS(err);
7746
7747 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007748 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7749 pipeline_layout_ci.setLayoutCount = 1;
7750 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007751
7752 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007753 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007754 ASSERT_VK_SUCCESS(err);
7755
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007756 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007757 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007758 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007759 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007760 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007761 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007762
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007763 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7764 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7765 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7766 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7767 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7768 rs_state_ci.depthClampEnable = VK_FALSE;
7769 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7770 rs_state_ci.depthBiasEnable = VK_FALSE;
7771
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007772 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7773 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7774 vi_ci.pNext = nullptr;
7775 vi_ci.vertexBindingDescriptionCount = 0;
7776 vi_ci.pVertexBindingDescriptions = nullptr;
7777 vi_ci.vertexAttributeDescriptionCount = 0;
7778 vi_ci.pVertexAttributeDescriptions = nullptr;
7779
7780 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7781 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7782 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7783
7784 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7785 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7786 pipe_ms_state_ci.pNext = NULL;
7787 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7788 pipe_ms_state_ci.sampleShadingEnable = 0;
7789 pipe_ms_state_ci.minSampleShading = 1.0;
7790 pipe_ms_state_ci.pSampleMask = NULL;
7791
Cody Northropeb3a6c12015-10-05 14:44:45 -06007792 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007793 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007794
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007795 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007796 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007797 shaderStages[0] = vs.GetStageCreateInfo();
7798 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007799
7800 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007801 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7802 gp_ci.stageCount = 2;
7803 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007804 gp_ci.pVertexInputState = &vi_ci;
7805 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007806 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007807 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007808 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007809 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7810 gp_ci.layout = pipeline_layout;
7811 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007812
7813 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007814 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007815
7816 VkPipeline pipeline;
7817 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007818 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007819 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007820
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007821 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007822 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007823
7824 // Check case where multiViewport is disabled and viewport count is not 1
7825 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7828 vp_state_ci.scissorCount = 0;
7829 vp_state_ci.viewportCount = 0;
7830 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7831 m_errorMonitor->VerifyFound();
7832 } else {
7833 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007834 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007835 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007836 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007837
7838 // Check is that viewportcount and scissorcount match
7839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7840 vp_state_ci.scissorCount = 1;
7841 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7842 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7843 m_errorMonitor->VerifyFound();
7844
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007845 // Check case where multiViewport is enabled and viewport count is greater than max
7846 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7849 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7850 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7851 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7852 m_errorMonitor->VerifyFound();
7853 }
7854 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007855
Chia-I Wuf7458c52015-10-26 21:10:41 +08007856 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7857 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7858 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7859 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007860}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007861
7862// 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
7863// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007864TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007865 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007866
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007867 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7868
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007870
Tobin Ehlise68360f2015-10-01 11:15:13 -06007871 ASSERT_NO_FATAL_FAILURE(InitState());
7872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007873
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007874 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007875 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7876 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007877
7878 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007879 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7880 ds_pool_ci.maxSets = 1;
7881 ds_pool_ci.poolSizeCount = 1;
7882 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007883
7884 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007885 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007886 ASSERT_VK_SUCCESS(err);
7887
7888 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007889 dsl_binding.binding = 0;
7890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7891 dsl_binding.descriptorCount = 1;
7892 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007893
7894 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007895 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7896 ds_layout_ci.bindingCount = 1;
7897 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007898
7899 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007900 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007901 ASSERT_VK_SUCCESS(err);
7902
7903 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007904 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007905 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007906 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007907 alloc_info.descriptorPool = ds_pool;
7908 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007910 ASSERT_VK_SUCCESS(err);
7911
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007912 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7913 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7914 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7915
7916 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7917 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7918 vi_ci.pNext = nullptr;
7919 vi_ci.vertexBindingDescriptionCount = 0;
7920 vi_ci.pVertexBindingDescriptions = nullptr;
7921 vi_ci.vertexAttributeDescriptionCount = 0;
7922 vi_ci.pVertexAttributeDescriptions = nullptr;
7923
7924 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7925 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7926 pipe_ms_state_ci.pNext = NULL;
7927 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7928 pipe_ms_state_ci.sampleShadingEnable = 0;
7929 pipe_ms_state_ci.minSampleShading = 1.0;
7930 pipe_ms_state_ci.pSampleMask = NULL;
7931
Tobin Ehlise68360f2015-10-01 11:15:13 -06007932 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007933 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7934 pipeline_layout_ci.setLayoutCount = 1;
7935 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007936
7937 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007938 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007939 ASSERT_VK_SUCCESS(err);
7940
7941 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7942 // Set scissor as dynamic to avoid second error
7943 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007944 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7945 dyn_state_ci.dynamicStateCount = 1;
7946 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007947
Cody Northropeb3a6c12015-10-05 14:44:45 -06007948 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007949 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007952 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7953 // 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 +08007954 shaderStages[0] = vs.GetStageCreateInfo();
7955 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007956
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007957 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7958 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7959 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7960 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7961 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7962 rs_state_ci.depthClampEnable = VK_FALSE;
7963 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7964 rs_state_ci.depthBiasEnable = VK_FALSE;
7965
Tobin Ehlise68360f2015-10-01 11:15:13 -06007966 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007967 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7968 gp_ci.stageCount = 2;
7969 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007970 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007971 // Not setting VP state w/o dynamic vp state should cause validation error
7972 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007973 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007974 gp_ci.pVertexInputState = &vi_ci;
7975 gp_ci.pInputAssemblyState = &ia_ci;
7976 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007977 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7978 gp_ci.layout = pipeline_layout;
7979 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007980
7981 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007982 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007983
7984 VkPipeline pipeline;
7985 VkPipelineCache pipelineCache;
7986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007987 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007988 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007989 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007990
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007991 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007992
Chia-I Wuf7458c52015-10-26 21:10:41 +08007993 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7994 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7996 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007997}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007998
7999// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8000// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008001TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8002 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008003
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008005
Tobin Ehlise68360f2015-10-01 11:15:13 -06008006 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008007
8008 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008009 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008010 return;
8011 }
8012
Tobin Ehlise68360f2015-10-01 11:15:13 -06008013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008014
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008015 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008016 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8017 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008018
8019 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008020 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8021 ds_pool_ci.maxSets = 1;
8022 ds_pool_ci.poolSizeCount = 1;
8023 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008024
8025 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008026 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008027 ASSERT_VK_SUCCESS(err);
8028
8029 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008030 dsl_binding.binding = 0;
8031 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8032 dsl_binding.descriptorCount = 1;
8033 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008034
8035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8037 ds_layout_ci.bindingCount = 1;
8038 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008039
8040 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008041 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008042 ASSERT_VK_SUCCESS(err);
8043
8044 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008045 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008046 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008047 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008048 alloc_info.descriptorPool = ds_pool;
8049 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008050 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008051 ASSERT_VK_SUCCESS(err);
8052
8053 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008054 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8055 pipeline_layout_ci.setLayoutCount = 1;
8056 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008057
8058 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008059 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008060 ASSERT_VK_SUCCESS(err);
8061
8062 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008063 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8064 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008065 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008066 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008067 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008068
8069 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8070 // Set scissor as dynamic to avoid that error
8071 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008072 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8073 dyn_state_ci.dynamicStateCount = 1;
8074 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008075
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008076 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8077 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8078 pipe_ms_state_ci.pNext = NULL;
8079 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8080 pipe_ms_state_ci.sampleShadingEnable = 0;
8081 pipe_ms_state_ci.minSampleShading = 1.0;
8082 pipe_ms_state_ci.pSampleMask = NULL;
8083
Cody Northropeb3a6c12015-10-05 14:44:45 -06008084 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008085 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008087 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008088 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8089 // 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 +08008090 shaderStages[0] = vs.GetStageCreateInfo();
8091 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008092
Cody Northropf6622dc2015-10-06 10:33:21 -06008093 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8094 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8095 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008096 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008097 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008098 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008099 vi_ci.pVertexAttributeDescriptions = nullptr;
8100
8101 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8102 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8103 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8104
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008105 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008106 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008107 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008108 rs_ci.pNext = nullptr;
8109
Mark Youngc89c6312016-03-31 16:03:20 -06008110 VkPipelineColorBlendAttachmentState att = {};
8111 att.blendEnable = VK_FALSE;
8112 att.colorWriteMask = 0xf;
8113
Cody Northropf6622dc2015-10-06 10:33:21 -06008114 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8115 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8116 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008117 cb_ci.attachmentCount = 1;
8118 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008119
Tobin Ehlise68360f2015-10-01 11:15:13 -06008120 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008121 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8122 gp_ci.stageCount = 2;
8123 gp_ci.pStages = shaderStages;
8124 gp_ci.pVertexInputState = &vi_ci;
8125 gp_ci.pInputAssemblyState = &ia_ci;
8126 gp_ci.pViewportState = &vp_state_ci;
8127 gp_ci.pRasterizationState = &rs_ci;
8128 gp_ci.pColorBlendState = &cb_ci;
8129 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008130 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008131 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8132 gp_ci.layout = pipeline_layout;
8133 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008134
8135 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008136 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008137
8138 VkPipeline pipeline;
8139 VkPipelineCache pipelineCache;
8140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008142 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008143 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008144
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008145 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008146
Tobin Ehlisd332f282015-10-02 11:00:56 -06008147 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008148 // First need to successfully create the PSO from above by setting
8149 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008150 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 -07008151
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008152 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008153 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008155 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008156 m_commandBuffer->BeginCommandBuffer();
8157 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008158 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008159 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008160 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008161 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008162 Draw(1, 0, 0, 0);
8163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008164 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008165
8166 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8167 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8168 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8169 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008170 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008171}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008172
8173// 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 -07008174// viewportCount
8175TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8176 VkResult err;
8177
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008179
8180 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008181
8182 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008183 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008184 return;
8185 }
8186
Karl Schultz6addd812016-02-02 17:17:23 -07008187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8188
8189 VkDescriptorPoolSize ds_type_count = {};
8190 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8191 ds_type_count.descriptorCount = 1;
8192
8193 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8194 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8195 ds_pool_ci.maxSets = 1;
8196 ds_pool_ci.poolSizeCount = 1;
8197 ds_pool_ci.pPoolSizes = &ds_type_count;
8198
8199 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008201 ASSERT_VK_SUCCESS(err);
8202
8203 VkDescriptorSetLayoutBinding dsl_binding = {};
8204 dsl_binding.binding = 0;
8205 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8206 dsl_binding.descriptorCount = 1;
8207 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8208
8209 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8210 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8211 ds_layout_ci.bindingCount = 1;
8212 ds_layout_ci.pBindings = &dsl_binding;
8213
8214 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008215 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008216 ASSERT_VK_SUCCESS(err);
8217
8218 VkDescriptorSet descriptorSet;
8219 VkDescriptorSetAllocateInfo alloc_info = {};
8220 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8221 alloc_info.descriptorSetCount = 1;
8222 alloc_info.descriptorPool = ds_pool;
8223 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008224 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008225 ASSERT_VK_SUCCESS(err);
8226
8227 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8228 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8229 pipeline_layout_ci.setLayoutCount = 1;
8230 pipeline_layout_ci.pSetLayouts = &ds_layout;
8231
8232 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008233 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008234 ASSERT_VK_SUCCESS(err);
8235
8236 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8237 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8238 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008239 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008240 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008241 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008242
8243 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8244 // Set scissor as dynamic to avoid that error
8245 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8246 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8247 dyn_state_ci.dynamicStateCount = 1;
8248 dyn_state_ci.pDynamicStates = &vp_state;
8249
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008250 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8251 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8252 pipe_ms_state_ci.pNext = NULL;
8253 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8254 pipe_ms_state_ci.sampleShadingEnable = 0;
8255 pipe_ms_state_ci.minSampleShading = 1.0;
8256 pipe_ms_state_ci.pSampleMask = NULL;
8257
Karl Schultz6addd812016-02-02 17:17:23 -07008258 VkPipelineShaderStageCreateInfo shaderStages[2];
8259 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8260
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008261 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008262 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8263 // 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 -07008264 shaderStages[0] = vs.GetStageCreateInfo();
8265 shaderStages[1] = fs.GetStageCreateInfo();
8266
8267 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8268 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8269 vi_ci.pNext = nullptr;
8270 vi_ci.vertexBindingDescriptionCount = 0;
8271 vi_ci.pVertexBindingDescriptions = nullptr;
8272 vi_ci.vertexAttributeDescriptionCount = 0;
8273 vi_ci.pVertexAttributeDescriptions = nullptr;
8274
8275 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8276 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8277 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8278
8279 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8280 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008281 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008282 rs_ci.pNext = nullptr;
8283
Mark Youngc89c6312016-03-31 16:03:20 -06008284 VkPipelineColorBlendAttachmentState att = {};
8285 att.blendEnable = VK_FALSE;
8286 att.colorWriteMask = 0xf;
8287
Karl Schultz6addd812016-02-02 17:17:23 -07008288 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8289 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8290 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008291 cb_ci.attachmentCount = 1;
8292 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008293
8294 VkGraphicsPipelineCreateInfo gp_ci = {};
8295 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8296 gp_ci.stageCount = 2;
8297 gp_ci.pStages = shaderStages;
8298 gp_ci.pVertexInputState = &vi_ci;
8299 gp_ci.pInputAssemblyState = &ia_ci;
8300 gp_ci.pViewportState = &vp_state_ci;
8301 gp_ci.pRasterizationState = &rs_ci;
8302 gp_ci.pColorBlendState = &cb_ci;
8303 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008304 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008305 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8306 gp_ci.layout = pipeline_layout;
8307 gp_ci.renderPass = renderPass();
8308
8309 VkPipelineCacheCreateInfo pc_ci = {};
8310 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8311
8312 VkPipeline pipeline;
8313 VkPipelineCache pipelineCache;
8314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008315 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008316 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008317 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008318
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008319 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008320
8321 // Now hit second fail case where we set scissor w/ different count than PSO
8322 // First need to successfully create the PSO from above by setting
8323 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8325 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008326
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008327 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008328 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008329 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008330 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008331 m_commandBuffer->BeginCommandBuffer();
8332 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008334 VkViewport viewports[1] = {};
8335 viewports[0].width = 8;
8336 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008337 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008338 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008339 Draw(1, 0, 0, 0);
8340
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008341 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008342
Chia-I Wuf7458c52015-10-26 21:10:41 +08008343 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8344 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8345 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8346 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008347 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008348}
8349
Mark Young7394fdd2016-03-31 14:56:43 -06008350TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8351 VkResult err;
8352
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008354
8355 ASSERT_NO_FATAL_FAILURE(InitState());
8356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8357
8358 VkDescriptorPoolSize ds_type_count = {};
8359 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8360 ds_type_count.descriptorCount = 1;
8361
8362 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8363 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8364 ds_pool_ci.maxSets = 1;
8365 ds_pool_ci.poolSizeCount = 1;
8366 ds_pool_ci.pPoolSizes = &ds_type_count;
8367
8368 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008369 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008370 ASSERT_VK_SUCCESS(err);
8371
8372 VkDescriptorSetLayoutBinding dsl_binding = {};
8373 dsl_binding.binding = 0;
8374 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8375 dsl_binding.descriptorCount = 1;
8376 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8377
8378 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8379 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8380 ds_layout_ci.bindingCount = 1;
8381 ds_layout_ci.pBindings = &dsl_binding;
8382
8383 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008385 ASSERT_VK_SUCCESS(err);
8386
8387 VkDescriptorSet descriptorSet;
8388 VkDescriptorSetAllocateInfo alloc_info = {};
8389 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8390 alloc_info.descriptorSetCount = 1;
8391 alloc_info.descriptorPool = ds_pool;
8392 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008393 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008394 ASSERT_VK_SUCCESS(err);
8395
8396 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8397 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8398 pipeline_layout_ci.setLayoutCount = 1;
8399 pipeline_layout_ci.pSetLayouts = &ds_layout;
8400
8401 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008402 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008403 ASSERT_VK_SUCCESS(err);
8404
8405 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8406 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8407 vp_state_ci.scissorCount = 1;
8408 vp_state_ci.pScissors = NULL;
8409 vp_state_ci.viewportCount = 1;
8410 vp_state_ci.pViewports = NULL;
8411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008412 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008413 // Set scissor as dynamic to avoid that error
8414 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8415 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8416 dyn_state_ci.dynamicStateCount = 2;
8417 dyn_state_ci.pDynamicStates = dynamic_states;
8418
8419 VkPipelineShaderStageCreateInfo shaderStages[2];
8420 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8421
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008422 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8423 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008424 this); // TODO - We shouldn't need a fragment shader
8425 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008426 shaderStages[0] = vs.GetStageCreateInfo();
8427 shaderStages[1] = fs.GetStageCreateInfo();
8428
8429 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8430 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8431 vi_ci.pNext = nullptr;
8432 vi_ci.vertexBindingDescriptionCount = 0;
8433 vi_ci.pVertexBindingDescriptions = nullptr;
8434 vi_ci.vertexAttributeDescriptionCount = 0;
8435 vi_ci.pVertexAttributeDescriptions = nullptr;
8436
8437 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8438 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8439 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8440
8441 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8442 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8443 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008444 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008445
Mark Young47107952016-05-02 15:59:55 -06008446 // Check too low (line width of -1.0f).
8447 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008448
8449 VkPipelineColorBlendAttachmentState att = {};
8450 att.blendEnable = VK_FALSE;
8451 att.colorWriteMask = 0xf;
8452
8453 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8454 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8455 cb_ci.pNext = nullptr;
8456 cb_ci.attachmentCount = 1;
8457 cb_ci.pAttachments = &att;
8458
8459 VkGraphicsPipelineCreateInfo gp_ci = {};
8460 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8461 gp_ci.stageCount = 2;
8462 gp_ci.pStages = shaderStages;
8463 gp_ci.pVertexInputState = &vi_ci;
8464 gp_ci.pInputAssemblyState = &ia_ci;
8465 gp_ci.pViewportState = &vp_state_ci;
8466 gp_ci.pRasterizationState = &rs_ci;
8467 gp_ci.pColorBlendState = &cb_ci;
8468 gp_ci.pDynamicState = &dyn_state_ci;
8469 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8470 gp_ci.layout = pipeline_layout;
8471 gp_ci.renderPass = renderPass();
8472
8473 VkPipelineCacheCreateInfo pc_ci = {};
8474 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8475
8476 VkPipeline pipeline;
8477 VkPipelineCache pipelineCache;
8478
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008482
8483 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008484 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008485
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008487
8488 // Check too high (line width of 65536.0f).
8489 rs_ci.lineWidth = 65536.0f;
8490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008492 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008493 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008494
8495 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008496 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008499
8500 dyn_state_ci.dynamicStateCount = 3;
8501
8502 rs_ci.lineWidth = 1.0f;
8503
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008505 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008506 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008507 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008508 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008509
8510 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008511 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008512 m_errorMonitor->VerifyFound();
8513
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008515
8516 // Check too high with dynamic setting.
8517 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8518 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008519 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008520
8521 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8522 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8523 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8524 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008525 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008526}
8527
Karl Schultz6addd812016-02-02 17:17:23 -07008528TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008529 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008531 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008532
8533 ASSERT_NO_FATAL_FAILURE(InitState());
8534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008535
Tony Barbour552f6c02016-12-21 14:34:07 -07008536 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008537 // Don't care about RenderPass handle b/c error should be flagged before
8538 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008540
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008541 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008542}
8543
Karl Schultz6addd812016-02-02 17:17:23 -07008544TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008545 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8547 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008548
8549 ASSERT_NO_FATAL_FAILURE(InitState());
8550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008551
Tony Barbour552f6c02016-12-21 14:34:07 -07008552 m_commandBuffer->BeginCommandBuffer();
8553 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008554 // Just create a dummy Renderpass that's non-NULL so we can get to the
8555 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008556 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008557
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008558 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008559}
8560
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008561TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008562 TEST_DESCRIPTION(
8563 "Begin a renderPass where clearValueCount is less than"
8564 "the number of renderPass attachments that use loadOp"
8565 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008566
8567 ASSERT_NO_FATAL_FAILURE(InitState());
8568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8569
8570 // Create a renderPass with a single attachment that uses loadOp CLEAR
8571 VkAttachmentReference attach = {};
8572 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8573 VkSubpassDescription subpass = {};
8574 subpass.inputAttachmentCount = 1;
8575 subpass.pInputAttachments = &attach;
8576 VkRenderPassCreateInfo rpci = {};
8577 rpci.subpassCount = 1;
8578 rpci.pSubpasses = &subpass;
8579 rpci.attachmentCount = 1;
8580 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008581 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008582 // Set loadOp to CLEAR
8583 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8584 rpci.pAttachments = &attach_desc;
8585 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8586 VkRenderPass rp;
8587 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8588
8589 VkCommandBufferInheritanceInfo hinfo = {};
8590 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8591 hinfo.renderPass = VK_NULL_HANDLE;
8592 hinfo.subpass = 0;
8593 hinfo.framebuffer = VK_NULL_HANDLE;
8594 hinfo.occlusionQueryEnable = VK_FALSE;
8595 hinfo.queryFlags = 0;
8596 hinfo.pipelineStatistics = 0;
8597 VkCommandBufferBeginInfo info = {};
8598 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8599 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8600 info.pInheritanceInfo = &hinfo;
8601
8602 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8603 VkRenderPassBeginInfo rp_begin = {};
8604 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8605 rp_begin.pNext = NULL;
8606 rp_begin.renderPass = renderPass();
8607 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008608 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008609
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008611
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008612 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008613
8614 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008615
8616 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008617}
8618
Slawomir Cygan0808f392016-11-28 17:53:23 +01008619TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008620 TEST_DESCRIPTION(
8621 "Begin a renderPass where clearValueCount is greater than"
8622 "the number of renderPass attachments that use loadOp"
8623 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008624
8625 ASSERT_NO_FATAL_FAILURE(InitState());
8626 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8627
8628 // Create a renderPass with a single attachment that uses loadOp CLEAR
8629 VkAttachmentReference attach = {};
8630 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8631 VkSubpassDescription subpass = {};
8632 subpass.inputAttachmentCount = 1;
8633 subpass.pInputAttachments = &attach;
8634 VkRenderPassCreateInfo rpci = {};
8635 rpci.subpassCount = 1;
8636 rpci.pSubpasses = &subpass;
8637 rpci.attachmentCount = 1;
8638 VkAttachmentDescription attach_desc = {};
8639 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8640 // Set loadOp to CLEAR
8641 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8642 rpci.pAttachments = &attach_desc;
8643 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8644 VkRenderPass rp;
8645 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8646
8647 VkCommandBufferBeginInfo info = {};
8648 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8649 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8650
8651 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8652 VkRenderPassBeginInfo rp_begin = {};
8653 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8654 rp_begin.pNext = NULL;
8655 rp_begin.renderPass = renderPass();
8656 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008657 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008658
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8660 " has a clearValueCount of"
8661 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008662
8663 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8664
8665 m_errorMonitor->VerifyFound();
8666
8667 vkDestroyRenderPass(m_device->device(), rp, NULL);
8668}
8669
Cody Northrop3bb4d962016-05-09 16:15:57 -06008670TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008671 TEST_DESCRIPTION("End a command buffer with an active render pass");
8672
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");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008675
8676 ASSERT_NO_FATAL_FAILURE(InitState());
8677 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8678
Tony Barbour552f6c02016-12-21 14:34:07 -07008679 m_commandBuffer->BeginCommandBuffer();
8680 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8681 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008682
8683 m_errorMonitor->VerifyFound();
8684
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008685 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8686 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008687}
8688
Karl Schultz6addd812016-02-02 17:17:23 -07008689TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008690 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8692 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693
8694 ASSERT_NO_FATAL_FAILURE(InitState());
8695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008696
Tony Barbour552f6c02016-12-21 14:34:07 -07008697 m_commandBuffer->BeginCommandBuffer();
8698 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008699
8700 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008701 vk_testing::Buffer dstBuffer;
8702 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008703
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008704 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008705
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008706 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008707}
8708
Karl Schultz6addd812016-02-02 17:17:23 -07008709TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008710 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8712 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008713
8714 ASSERT_NO_FATAL_FAILURE(InitState());
8715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008716
Tony Barbour552f6c02016-12-21 14:34:07 -07008717 m_commandBuffer->BeginCommandBuffer();
8718 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008719
8720 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008721 vk_testing::Buffer dstBuffer;
8722 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008723
Karl Schultz6addd812016-02-02 17:17:23 -07008724 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008725 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8726 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8727 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008728
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008729 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008730}
8731
Karl Schultz6addd812016-02-02 17:17:23 -07008732TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008733 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8735 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008736
8737 ASSERT_NO_FATAL_FAILURE(InitState());
8738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008739
Tony Barbour552f6c02016-12-21 14:34:07 -07008740 m_commandBuffer->BeginCommandBuffer();
8741 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008742
Michael Lentine0a369f62016-02-03 16:51:46 -06008743 VkClearColorValue clear_color;
8744 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008745 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8746 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8747 const int32_t tex_width = 32;
8748 const int32_t tex_height = 32;
8749 VkImageCreateInfo image_create_info = {};
8750 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8751 image_create_info.pNext = NULL;
8752 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8753 image_create_info.format = tex_format;
8754 image_create_info.extent.width = tex_width;
8755 image_create_info.extent.height = tex_height;
8756 image_create_info.extent.depth = 1;
8757 image_create_info.mipLevels = 1;
8758 image_create_info.arrayLayers = 1;
8759 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8760 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8761 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008762
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008763 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008764 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008765
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008766 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008767
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008768 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008769 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008771 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772}
8773
Karl Schultz6addd812016-02-02 17:17:23 -07008774TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008775 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8777 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008778
8779 ASSERT_NO_FATAL_FAILURE(InitState());
8780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008781
Tony Barbour552f6c02016-12-21 14:34:07 -07008782 m_commandBuffer->BeginCommandBuffer();
8783 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008784
8785 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008786 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008787 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8788 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8789 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8790 image_create_info.extent.width = 64;
8791 image_create_info.extent.height = 64;
8792 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8793 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008794
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008795 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008796 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008798 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008799
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008800 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8801 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008802
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008803 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008804}
8805
Karl Schultz6addd812016-02-02 17:17:23 -07008806TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008807 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008808 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008809
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8811 "vkCmdClearAttachments(): This call "
8812 "must be issued inside an active "
8813 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008814
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008815 ASSERT_NO_FATAL_FAILURE(InitState());
8816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008817
8818 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008819 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008820 ASSERT_VK_SUCCESS(err);
8821
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008822 VkClearAttachment color_attachment;
8823 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8824 color_attachment.clearValue.color.float32[0] = 0;
8825 color_attachment.clearValue.color.float32[1] = 0;
8826 color_attachment.clearValue.color.float32[2] = 0;
8827 color_attachment.clearValue.color.float32[3] = 0;
8828 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008829 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008830 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008831
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008832 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008833}
8834
Chris Forbes3b97e932016-09-07 11:29:24 +12008835TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008836 TEST_DESCRIPTION(
8837 "Test that an error is produced when CmdNextSubpass is "
8838 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008839
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8841 "vkCmdNextSubpass(): Attempted to advance "
8842 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008843
8844 ASSERT_NO_FATAL_FAILURE(InitState());
8845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8846
Tony Barbour552f6c02016-12-21 14:34:07 -07008847 m_commandBuffer->BeginCommandBuffer();
8848 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008849
8850 // error here.
8851 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8852 m_errorMonitor->VerifyFound();
8853
Tony Barbour552f6c02016-12-21 14:34:07 -07008854 m_commandBuffer->EndRenderPass();
8855 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008856}
8857
Chris Forbes6d624702016-09-07 13:57:05 +12008858TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008859 TEST_DESCRIPTION(
8860 "Test that an error is produced when CmdEndRenderPass is "
8861 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008862
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8864 "vkCmdEndRenderPass(): Called before reaching "
8865 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008866
8867 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008868 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8869 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008870
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008871 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008872
8873 VkRenderPass rp;
8874 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8875 ASSERT_VK_SUCCESS(err);
8876
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008877 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008878
8879 VkFramebuffer fb;
8880 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8881 ASSERT_VK_SUCCESS(err);
8882
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008883 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008885 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 +12008886
8887 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8888
8889 // Error here.
8890 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8891 m_errorMonitor->VerifyFound();
8892
8893 // Clean up.
8894 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8895 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8896}
8897
Karl Schultz9e66a292016-04-21 15:57:51 -06008898TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8899 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8901 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008902
8903 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008904 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008905
8906 VkBufferMemoryBarrier buf_barrier = {};
8907 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8908 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8909 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8910 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8911 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8912 buf_barrier.buffer = VK_NULL_HANDLE;
8913 buf_barrier.offset = 0;
8914 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008915 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8916 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008917
8918 m_errorMonitor->VerifyFound();
8919}
8920
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008921TEST_F(VkLayerTest, InvalidBarriers) {
8922 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8923
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008925
8926 ASSERT_NO_FATAL_FAILURE(InitState());
8927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8928
8929 VkMemoryBarrier mem_barrier = {};
8930 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8931 mem_barrier.pNext = NULL;
8932 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8933 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008934 m_commandBuffer->BeginCommandBuffer();
8935 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008936 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008937 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008938 &mem_barrier, 0, nullptr, 0, nullptr);
8939 m_errorMonitor->VerifyFound();
8940
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008942 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008943 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 -06008944 ASSERT_TRUE(image.initialized());
8945 VkImageMemoryBarrier img_barrier = {};
8946 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8947 img_barrier.pNext = NULL;
8948 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8949 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8950 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8951 // New layout can't be UNDEFINED
8952 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8953 img_barrier.image = image.handle();
8954 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8955 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8956 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8957 img_barrier.subresourceRange.baseArrayLayer = 0;
8958 img_barrier.subresourceRange.baseMipLevel = 0;
8959 img_barrier.subresourceRange.layerCount = 1;
8960 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008961 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8962 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008963 m_errorMonitor->VerifyFound();
8964 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8965
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8967 "Subresource must have the sum of the "
8968 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008969 // baseArrayLayer + layerCount must be <= image's arrayLayers
8970 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008971 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8972 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008973 m_errorMonitor->VerifyFound();
8974 img_barrier.subresourceRange.baseArrayLayer = 0;
8975
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008977 // baseMipLevel + levelCount must be <= image's mipLevels
8978 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008979 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8980 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008981 m_errorMonitor->VerifyFound();
8982 img_barrier.subresourceRange.baseMipLevel = 0;
8983
Mike Weiblen7053aa32017-01-25 15:21:10 -07008984 // levelCount must be non-zero.
8985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8986 img_barrier.subresourceRange.levelCount = 0;
8987 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8988 nullptr, 0, nullptr, 1, &img_barrier);
8989 m_errorMonitor->VerifyFound();
8990 img_barrier.subresourceRange.levelCount = 1;
8991
8992 // layerCount must be non-zero.
8993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8994 img_barrier.subresourceRange.layerCount = 0;
8995 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8996 nullptr, 0, nullptr, 1, &img_barrier);
8997 m_errorMonitor->VerifyFound();
8998 img_barrier.subresourceRange.layerCount = 1;
8999
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009000 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 -06009001 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009002 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9003 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009004 VkBufferMemoryBarrier buf_barrier = {};
9005 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9006 buf_barrier.pNext = NULL;
9007 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9008 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9009 buf_barrier.buffer = buffer.handle();
9010 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9011 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9012 buf_barrier.offset = 0;
9013 buf_barrier.size = VK_WHOLE_SIZE;
9014 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009015 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9016 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009017 m_errorMonitor->VerifyFound();
9018 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9019
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009021 buf_barrier.offset = 257;
9022 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009023 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9024 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009025 m_errorMonitor->VerifyFound();
9026 buf_barrier.offset = 0;
9027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009029 buf_barrier.size = 257;
9030 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009031 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9032 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009033 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009034
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009035 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009036 m_errorMonitor->SetDesiredFailureMsg(
9037 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009038 "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 -06009039 VkDepthStencilObj ds_image(m_device);
9040 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9041 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009042 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9043 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009044 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009045
9046 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009047 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009048 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9049 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009050 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009051
9052 // Having anything other than DEPTH or STENCIL is an error
9053 m_errorMonitor->SetDesiredFailureMsg(
9054 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9055 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9056 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9057 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9058 nullptr, 0, nullptr, 1, &img_barrier);
9059 m_errorMonitor->VerifyFound();
9060
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009061 // Now test depth-only
9062 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009063 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9064 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009065 VkDepthStencilObj d_image(m_device);
9066 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9067 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009068 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009069 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009070 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009071
9072 // DEPTH bit must be set
9073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9074 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009075 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009076 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9077 0, nullptr, 0, nullptr, 1, &img_barrier);
9078 m_errorMonitor->VerifyFound();
9079
9080 // No bits other than DEPTH may be set
9081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9082 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9083 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009084 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9085 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009086 m_errorMonitor->VerifyFound();
9087 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009088
9089 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009090 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9091 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009092 VkDepthStencilObj s_image(m_device);
9093 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9094 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009095 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009096 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009097 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009098 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9100 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009101 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009102 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9103 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009104 m_errorMonitor->VerifyFound();
9105 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009106
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009107 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009108 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009109 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 -06009110 ASSERT_TRUE(c_image.initialized());
9111 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9112 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9113 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009114
9115 // COLOR bit must be set
9116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9117 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009118 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009119 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9120 nullptr, 0, nullptr, 1, &img_barrier);
9121 m_errorMonitor->VerifyFound();
9122
9123 // No bits other than COLOR may be set
9124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9125 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9126 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009127 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9128 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009129 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009130
9131 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9132
9133 // Create command pool with incompatible queueflags
9134 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9135 uint32_t queue_family_index = UINT32_MAX;
9136 for (uint32_t i = 0; i < queue_props.size(); i++) {
9137 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9138 queue_family_index = i;
9139 break;
9140 }
9141 }
9142 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009143 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009144 return;
9145 }
9146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9147
9148 VkCommandPool command_pool;
9149 VkCommandPoolCreateInfo pool_create_info{};
9150 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9151 pool_create_info.queueFamilyIndex = queue_family_index;
9152 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9153 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9154
9155 // Allocate a command buffer
9156 VkCommandBuffer bad_command_buffer;
9157 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9158 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9159 command_buffer_allocate_info.commandPool = command_pool;
9160 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9161 command_buffer_allocate_info.commandBufferCount = 1;
9162 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9163
9164 VkCommandBufferBeginInfo cbbi = {};
9165 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9166 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9167 buf_barrier.offset = 0;
9168 buf_barrier.size = VK_WHOLE_SIZE;
9169 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9170 &buf_barrier, 0, nullptr);
9171 m_errorMonitor->VerifyFound();
9172
9173 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9174 vkEndCommandBuffer(bad_command_buffer);
9175 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009176 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009177 return;
9178 }
9179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9180 VkEvent event;
9181 VkEventCreateInfo event_create_info{};
9182 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9183 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9184 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9185 nullptr, 0, nullptr);
9186 m_errorMonitor->VerifyFound();
9187
9188 vkEndCommandBuffer(bad_command_buffer);
9189 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009190}
9191
Tony Barbour18ba25c2016-09-29 13:42:40 -06009192TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9193 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9194
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009196 ASSERT_NO_FATAL_FAILURE(InitState());
9197 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009198 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 -06009199 ASSERT_TRUE(image.initialized());
9200
9201 VkImageMemoryBarrier barrier = {};
9202 VkImageSubresourceRange range;
9203 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9204 barrier.srcAccessMask = 0;
9205 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9206 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9207 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9208 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9209 barrier.image = image.handle();
9210 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9211 range.baseMipLevel = 0;
9212 range.levelCount = 1;
9213 range.baseArrayLayer = 0;
9214 range.layerCount = 1;
9215 barrier.subresourceRange = range;
9216 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9217 cmdbuf.BeginCommandBuffer();
9218 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9219 &barrier);
9220 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9221 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9222 barrier.srcAccessMask = 0;
9223 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9224 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9225 &barrier);
9226
9227 m_errorMonitor->VerifyFound();
9228}
9229
Karl Schultz6addd812016-02-02 17:17:23 -07009230TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009231 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009232 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009233
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009235
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009236 ASSERT_NO_FATAL_FAILURE(InitState());
9237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009238 uint32_t qfi = 0;
9239 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009240 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9241 buffCI.size = 1024;
9242 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9243 buffCI.queueFamilyIndexCount = 1;
9244 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009245
9246 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009247 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009248 ASSERT_VK_SUCCESS(err);
9249
Tony Barbour552f6c02016-12-21 14:34:07 -07009250 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009251 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009252 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9253 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009254 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009255 m_errorMonitor->SetUnexpectedError(
9256 "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 -06009257 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009258
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009259 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009260
Chia-I Wuf7458c52015-10-26 21:10:41 +08009261 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009262}
9263
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009264TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9265 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9267 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9268 "of the indices specified when the device was created, via the "
9269 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009270
9271 ASSERT_NO_FATAL_FAILURE(InitState());
9272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9273 VkBufferCreateInfo buffCI = {};
9274 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9275 buffCI.size = 1024;
9276 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9277 buffCI.queueFamilyIndexCount = 1;
9278 // Introduce failure by specifying invalid queue_family_index
9279 uint32_t qfi = 777;
9280 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009281 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009282
9283 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009284 m_errorMonitor->SetUnexpectedError(
9285 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009286 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9287
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009288 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009289 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009290}
9291
Karl Schultz6addd812016-02-02 17:17:23 -07009292TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009293 TEST_DESCRIPTION(
9294 "Attempt vkCmdExecuteCommands with a primary command buffer"
9295 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009296
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009297 ASSERT_NO_FATAL_FAILURE(InitState());
9298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009299
Chris Forbesf29a84f2016-10-06 18:39:28 +13009300 // An empty primary command buffer
9301 VkCommandBufferObj cb(m_device, m_commandPool);
9302 cb.BeginCommandBuffer();
9303 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009304
Chris Forbesf29a84f2016-10-06 18:39:28 +13009305 m_commandBuffer->BeginCommandBuffer();
9306 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9307 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009308
Chris Forbesf29a84f2016-10-06 18:39:28 +13009309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9310 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009311 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009312
9313 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009314}
9315
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009316TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009317 TEST_DESCRIPTION(
9318 "Attempt to update descriptor sets for images and buffers "
9319 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009320 VkResult err;
9321
9322 ASSERT_NO_FATAL_FAILURE(InitState());
9323 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9324 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9325 ds_type_count[i].type = VkDescriptorType(i);
9326 ds_type_count[i].descriptorCount = 1;
9327 }
9328 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9329 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9330 ds_pool_ci.pNext = NULL;
9331 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9332 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9333 ds_pool_ci.pPoolSizes = ds_type_count;
9334
9335 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009337 ASSERT_VK_SUCCESS(err);
9338
9339 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009340 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009341 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9342 dsl_binding[i].binding = 0;
9343 dsl_binding[i].descriptorType = VkDescriptorType(i);
9344 dsl_binding[i].descriptorCount = 1;
9345 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9346 dsl_binding[i].pImmutableSamplers = NULL;
9347 }
9348
9349 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9350 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9351 ds_layout_ci.pNext = NULL;
9352 ds_layout_ci.bindingCount = 1;
9353 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9354 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9355 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009356 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009357 ASSERT_VK_SUCCESS(err);
9358 }
9359 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9360 VkDescriptorSetAllocateInfo alloc_info = {};
9361 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9362 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9363 alloc_info.descriptorPool = ds_pool;
9364 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009365 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009366 ASSERT_VK_SUCCESS(err);
9367
9368 // Create a buffer & bufferView to be used for invalid updates
9369 VkBufferCreateInfo buff_ci = {};
9370 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009371 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009372 buff_ci.size = 256;
9373 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009374 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009375 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9376 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009377
9378 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9379 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9380 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9381 ASSERT_VK_SUCCESS(err);
9382
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009383 VkMemoryRequirements mem_reqs;
9384 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9385 VkMemoryAllocateInfo mem_alloc_info = {};
9386 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9387 mem_alloc_info.pNext = NULL;
9388 mem_alloc_info.memoryTypeIndex = 0;
9389 mem_alloc_info.allocationSize = mem_reqs.size;
9390 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9391 if (!pass) {
9392 vkDestroyBuffer(m_device->device(), buffer, NULL);
9393 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9394 return;
9395 }
9396 VkDeviceMemory mem;
9397 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9398 ASSERT_VK_SUCCESS(err);
9399 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9400 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009401
9402 VkBufferViewCreateInfo buff_view_ci = {};
9403 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9404 buff_view_ci.buffer = buffer;
9405 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9406 buff_view_ci.range = VK_WHOLE_SIZE;
9407 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009408 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009409 ASSERT_VK_SUCCESS(err);
9410
Tony Barbour415497c2017-01-24 10:06:09 -07009411 // Now get resources / view for storage_texel_buffer
9412 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9413 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9414 if (!pass) {
9415 vkDestroyBuffer(m_device->device(), buffer, NULL);
9416 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9417 vkFreeMemory(m_device->device(), mem, NULL);
9418 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9419 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9420 return;
9421 }
9422 VkDeviceMemory storage_texel_buffer_mem;
9423 VkBufferView storage_texel_buffer_view;
9424 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9425 ASSERT_VK_SUCCESS(err);
9426 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9427 ASSERT_VK_SUCCESS(err);
9428 buff_view_ci.buffer = storage_texel_buffer;
9429 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9430 ASSERT_VK_SUCCESS(err);
9431
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009432 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009433 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009434 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009435 image_ci.format = VK_FORMAT_UNDEFINED;
9436 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9437 VkFormat format = static_cast<VkFormat>(f);
9438 VkFormatProperties fProps = m_device->format_properties(format);
9439 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9440 image_ci.format = format;
9441 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9442 break;
9443 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9444 image_ci.format = format;
9445 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9446 break;
9447 }
9448 }
9449 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9450 return;
9451 }
9452
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009453 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9454 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009455 image_ci.extent.width = 64;
9456 image_ci.extent.height = 64;
9457 image_ci.extent.depth = 1;
9458 image_ci.mipLevels = 1;
9459 image_ci.arrayLayers = 1;
9460 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009461 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009462 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009463 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9464 VkImage image;
9465 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9466 ASSERT_VK_SUCCESS(err);
9467 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009468 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009469
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009470 VkMemoryAllocateInfo mem_alloc = {};
9471 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9472 mem_alloc.pNext = NULL;
9473 mem_alloc.allocationSize = 0;
9474 mem_alloc.memoryTypeIndex = 0;
9475 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9476 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009477 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009478 ASSERT_TRUE(pass);
9479 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9480 ASSERT_VK_SUCCESS(err);
9481 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9482 ASSERT_VK_SUCCESS(err);
9483 // Now create view for image
9484 VkImageViewCreateInfo image_view_ci = {};
9485 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9486 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009487 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009488 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9489 image_view_ci.subresourceRange.layerCount = 1;
9490 image_view_ci.subresourceRange.baseArrayLayer = 0;
9491 image_view_ci.subresourceRange.levelCount = 1;
9492 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9493 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009495 ASSERT_VK_SUCCESS(err);
9496
9497 VkDescriptorBufferInfo buff_info = {};
9498 buff_info.buffer = buffer;
9499 VkDescriptorImageInfo img_info = {};
9500 img_info.imageView = image_view;
9501 VkWriteDescriptorSet descriptor_write = {};
9502 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9503 descriptor_write.dstBinding = 0;
9504 descriptor_write.descriptorCount = 1;
9505 descriptor_write.pTexelBufferView = &buff_view;
9506 descriptor_write.pBufferInfo = &buff_info;
9507 descriptor_write.pImageInfo = &img_info;
9508
9509 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009510 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009511 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9512 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9513 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9514 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9515 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9516 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9517 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9518 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9519 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9520 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9521 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009522 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009523 // Start loop at 1 as SAMPLER desc type has no usage bit error
9524 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009525 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9526 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9527 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9528 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009529 descriptor_write.descriptorType = VkDescriptorType(i);
9530 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009532
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009533 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009534
9535 m_errorMonitor->VerifyFound();
9536 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009537 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9538 descriptor_write.pTexelBufferView = &buff_view;
9539 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009540 }
Tony Barbour415497c2017-01-24 10:06:09 -07009541
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9543 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009544 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009545 vkDestroyImageView(m_device->device(), image_view, NULL);
9546 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009547 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009548 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009549 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009550 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009551 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009552 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9553}
9554
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009555TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009556 TEST_DESCRIPTION(
9557 "Attempt to update buffer descriptor set that has incorrect "
9558 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9559 "1. offset value greater than buffer size\n"
9560 "2. range value of 0\n"
9561 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009562 VkResult err;
9563
9564 ASSERT_NO_FATAL_FAILURE(InitState());
9565 VkDescriptorPoolSize ds_type_count = {};
9566 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9567 ds_type_count.descriptorCount = 1;
9568
9569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9571 ds_pool_ci.pNext = NULL;
9572 ds_pool_ci.maxSets = 1;
9573 ds_pool_ci.poolSizeCount = 1;
9574 ds_pool_ci.pPoolSizes = &ds_type_count;
9575
9576 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009577 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009578 ASSERT_VK_SUCCESS(err);
9579
9580 // Create layout with single uniform buffer descriptor
9581 VkDescriptorSetLayoutBinding dsl_binding = {};
9582 dsl_binding.binding = 0;
9583 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9584 dsl_binding.descriptorCount = 1;
9585 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9586 dsl_binding.pImmutableSamplers = NULL;
9587
9588 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9589 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9590 ds_layout_ci.pNext = NULL;
9591 ds_layout_ci.bindingCount = 1;
9592 ds_layout_ci.pBindings = &dsl_binding;
9593 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009594 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009595 ASSERT_VK_SUCCESS(err);
9596
9597 VkDescriptorSet descriptor_set = {};
9598 VkDescriptorSetAllocateInfo alloc_info = {};
9599 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9600 alloc_info.descriptorSetCount = 1;
9601 alloc_info.descriptorPool = ds_pool;
9602 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009603 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009604 ASSERT_VK_SUCCESS(err);
9605
9606 // Create a buffer to be used for invalid updates
9607 VkBufferCreateInfo buff_ci = {};
9608 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9609 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9610 buff_ci.size = 256;
9611 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9612 VkBuffer buffer;
9613 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9614 ASSERT_VK_SUCCESS(err);
9615 // Have to bind memory to buffer before descriptor update
9616 VkMemoryAllocateInfo mem_alloc = {};
9617 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9618 mem_alloc.pNext = NULL;
9619 mem_alloc.allocationSize = 256;
9620 mem_alloc.memoryTypeIndex = 0;
9621
9622 VkMemoryRequirements mem_reqs;
9623 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009624 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009625 if (!pass) {
9626 vkDestroyBuffer(m_device->device(), buffer, NULL);
9627 return;
9628 }
9629
9630 VkDeviceMemory mem;
9631 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9632 ASSERT_VK_SUCCESS(err);
9633 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9634 ASSERT_VK_SUCCESS(err);
9635
9636 VkDescriptorBufferInfo buff_info = {};
9637 buff_info.buffer = buffer;
9638 // First make offset 1 larger than buffer size
9639 buff_info.offset = 257;
9640 buff_info.range = VK_WHOLE_SIZE;
9641 VkWriteDescriptorSet descriptor_write = {};
9642 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9643 descriptor_write.dstBinding = 0;
9644 descriptor_write.descriptorCount = 1;
9645 descriptor_write.pTexelBufferView = nullptr;
9646 descriptor_write.pBufferInfo = &buff_info;
9647 descriptor_write.pImageInfo = nullptr;
9648
9649 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9650 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009652
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009653 m_errorMonitor->SetUnexpectedError(
9654 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9655 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009656 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9657
9658 m_errorMonitor->VerifyFound();
9659 // Now cause error due to range of 0
9660 buff_info.offset = 0;
9661 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009663
9664 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9665
9666 m_errorMonitor->VerifyFound();
9667 // Now cause error due to range exceeding buffer size - offset
9668 buff_info.offset = 128;
9669 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009671
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009672 m_errorMonitor->SetUnexpectedError(
9673 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9674 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009675 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9676
9677 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009678 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9680 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009681 m_errorMonitor->SetUnexpectedError(
9682 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009683 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9684 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9685}
9686
Tobin Ehlis845887e2017-02-02 19:01:44 -07009687TEST_F(VkLayerTest, DSBufferLimitErrors) {
9688 TEST_DESCRIPTION(
9689 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9690 "Test cases include:\n"
9691 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9692 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9693 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9694 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9695 VkResult err;
9696
9697 ASSERT_NO_FATAL_FAILURE(InitState());
9698 VkDescriptorPoolSize ds_type_count[2] = {};
9699 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9700 ds_type_count[0].descriptorCount = 1;
9701 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9702 ds_type_count[1].descriptorCount = 1;
9703
9704 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9705 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9706 ds_pool_ci.pNext = NULL;
9707 ds_pool_ci.maxSets = 1;
9708 ds_pool_ci.poolSizeCount = 2;
9709 ds_pool_ci.pPoolSizes = ds_type_count;
9710
9711 VkDescriptorPool ds_pool;
9712 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9713 ASSERT_VK_SUCCESS(err);
9714
9715 // Create layout with single uniform buffer & single storage buffer descriptor
9716 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9717 dsl_binding[0].binding = 0;
9718 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9719 dsl_binding[0].descriptorCount = 1;
9720 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9721 dsl_binding[0].pImmutableSamplers = NULL;
9722 dsl_binding[1].binding = 1;
9723 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9724 dsl_binding[1].descriptorCount = 1;
9725 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9726 dsl_binding[1].pImmutableSamplers = NULL;
9727
9728 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9729 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9730 ds_layout_ci.pNext = NULL;
9731 ds_layout_ci.bindingCount = 2;
9732 ds_layout_ci.pBindings = dsl_binding;
9733 VkDescriptorSetLayout ds_layout;
9734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9735 ASSERT_VK_SUCCESS(err);
9736
9737 VkDescriptorSet descriptor_set = {};
9738 VkDescriptorSetAllocateInfo alloc_info = {};
9739 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9740 alloc_info.descriptorSetCount = 1;
9741 alloc_info.descriptorPool = ds_pool;
9742 alloc_info.pSetLayouts = &ds_layout;
9743 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9744 ASSERT_VK_SUCCESS(err);
9745
9746 // Create a buffer to be used for invalid updates
9747 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9748 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9749 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9750 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9751 VkBufferCreateInfo ub_ci = {};
9752 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9753 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9754 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9755 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9756 VkBuffer uniform_buffer;
9757 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9758 ASSERT_VK_SUCCESS(err);
9759 VkBufferCreateInfo sb_ci = {};
9760 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9761 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9762 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9763 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9764 VkBuffer storage_buffer;
9765 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9766 ASSERT_VK_SUCCESS(err);
9767 // Have to bind memory to buffer before descriptor update
9768 VkMemoryAllocateInfo mem_alloc = {};
9769 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9770 mem_alloc.pNext = NULL;
9771 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9772 mem_alloc.memoryTypeIndex = 0;
9773
9774 VkMemoryRequirements mem_reqs;
9775 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9776 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9777 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9778 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9779 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009780 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009781 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009782 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9783 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009784 return;
9785 }
9786
9787 VkDeviceMemory mem;
9788 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009789 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009790 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009791 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9792 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9793 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9794 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9795 return;
9796 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009797 ASSERT_VK_SUCCESS(err);
9798 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9799 ASSERT_VK_SUCCESS(err);
9800 auto sb_offset = ub_ci.size + 1024;
9801 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9802 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9803 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9804 ASSERT_VK_SUCCESS(err);
9805
9806 VkDescriptorBufferInfo buff_info = {};
9807 buff_info.buffer = uniform_buffer;
9808 buff_info.range = ub_ci.size; // This will exceed limit
9809 VkWriteDescriptorSet descriptor_write = {};
9810 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9811 descriptor_write.dstBinding = 0;
9812 descriptor_write.descriptorCount = 1;
9813 descriptor_write.pTexelBufferView = nullptr;
9814 descriptor_write.pBufferInfo = &buff_info;
9815 descriptor_write.pImageInfo = nullptr;
9816
9817 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9818 descriptor_write.dstSet = descriptor_set;
9819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9820 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9821 m_errorMonitor->VerifyFound();
9822
9823 // Reduce size of range to acceptable limit & cause offset error
9824 buff_info.range = max_ub_range;
9825 buff_info.offset = min_ub_align - 1;
9826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9827 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9828 m_errorMonitor->VerifyFound();
9829
9830 // Now break storage updates
9831 buff_info.buffer = storage_buffer;
9832 buff_info.range = sb_ci.size; // This will exceed limit
9833 buff_info.offset = 0; // Reset offset for this update
9834
9835 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9836 descriptor_write.dstBinding = 1;
9837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9838 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9839 m_errorMonitor->VerifyFound();
9840
9841 // Reduce size of range to acceptable limit & cause offset error
9842 buff_info.range = max_sb_range;
9843 buff_info.offset = min_sb_align - 1;
9844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9845 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9846 m_errorMonitor->VerifyFound();
9847
9848 vkFreeMemory(m_device->device(), mem, NULL);
9849 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9850 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9851 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9852 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9853}
9854
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009855TEST_F(VkLayerTest, DSAspectBitsErrors) {
9856 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9857 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009858 TEST_DESCRIPTION(
9859 "Attempt to update descriptor sets for images "
9860 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009861 VkResult err;
9862
9863 ASSERT_NO_FATAL_FAILURE(InitState());
9864 VkDescriptorPoolSize ds_type_count = {};
9865 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9866 ds_type_count.descriptorCount = 1;
9867
9868 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9869 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9870 ds_pool_ci.pNext = NULL;
9871 ds_pool_ci.maxSets = 5;
9872 ds_pool_ci.poolSizeCount = 1;
9873 ds_pool_ci.pPoolSizes = &ds_type_count;
9874
9875 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009876 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009877 ASSERT_VK_SUCCESS(err);
9878
9879 VkDescriptorSetLayoutBinding dsl_binding = {};
9880 dsl_binding.binding = 0;
9881 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9882 dsl_binding.descriptorCount = 1;
9883 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9884 dsl_binding.pImmutableSamplers = NULL;
9885
9886 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9887 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9888 ds_layout_ci.pNext = NULL;
9889 ds_layout_ci.bindingCount = 1;
9890 ds_layout_ci.pBindings = &dsl_binding;
9891 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009892 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009893 ASSERT_VK_SUCCESS(err);
9894
9895 VkDescriptorSet descriptor_set = {};
9896 VkDescriptorSetAllocateInfo alloc_info = {};
9897 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9898 alloc_info.descriptorSetCount = 1;
9899 alloc_info.descriptorPool = ds_pool;
9900 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009901 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009902 ASSERT_VK_SUCCESS(err);
9903
9904 // Create an image to be used for invalid updates
9905 VkImageCreateInfo image_ci = {};
9906 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9907 image_ci.imageType = VK_IMAGE_TYPE_2D;
9908 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9909 image_ci.extent.width = 64;
9910 image_ci.extent.height = 64;
9911 image_ci.extent.depth = 1;
9912 image_ci.mipLevels = 1;
9913 image_ci.arrayLayers = 1;
9914 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9915 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9916 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9917 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9918 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9919 VkImage image;
9920 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9921 ASSERT_VK_SUCCESS(err);
9922 // Bind memory to image
9923 VkMemoryRequirements mem_reqs;
9924 VkDeviceMemory image_mem;
9925 bool pass;
9926 VkMemoryAllocateInfo mem_alloc = {};
9927 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9928 mem_alloc.pNext = NULL;
9929 mem_alloc.allocationSize = 0;
9930 mem_alloc.memoryTypeIndex = 0;
9931 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9932 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009933 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009934 ASSERT_TRUE(pass);
9935 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9936 ASSERT_VK_SUCCESS(err);
9937 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9938 ASSERT_VK_SUCCESS(err);
9939 // Now create view for image
9940 VkImageViewCreateInfo image_view_ci = {};
9941 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9942 image_view_ci.image = image;
9943 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9944 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9945 image_view_ci.subresourceRange.layerCount = 1;
9946 image_view_ci.subresourceRange.baseArrayLayer = 0;
9947 image_view_ci.subresourceRange.levelCount = 1;
9948 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009949 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009950
9951 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009953 ASSERT_VK_SUCCESS(err);
9954
9955 VkDescriptorImageInfo img_info = {};
9956 img_info.imageView = image_view;
9957 VkWriteDescriptorSet descriptor_write = {};
9958 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9959 descriptor_write.dstBinding = 0;
9960 descriptor_write.descriptorCount = 1;
9961 descriptor_write.pTexelBufferView = NULL;
9962 descriptor_write.pBufferInfo = NULL;
9963 descriptor_write.pImageInfo = &img_info;
9964 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9965 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009966 const char *error_msg =
9967 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9968 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009970
9971 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9972
9973 m_errorMonitor->VerifyFound();
9974 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9975 vkDestroyImage(m_device->device(), image, NULL);
9976 vkFreeMemory(m_device->device(), image_mem, NULL);
9977 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009978 m_errorMonitor->SetUnexpectedError(
9979 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009980 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9981 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9982}
9983
Karl Schultz6addd812016-02-02 17:17:23 -07009984TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009985 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009986 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009987
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9989 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9990 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009991
Tobin Ehlis3b780662015-05-28 12:11:26 -06009992 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009993 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009994 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009995 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9996 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009997
9998 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009999 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10000 ds_pool_ci.pNext = NULL;
10001 ds_pool_ci.maxSets = 1;
10002 ds_pool_ci.poolSizeCount = 1;
10003 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010004
Tobin Ehlis3b780662015-05-28 12:11:26 -060010005 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010006 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010007 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010008 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010009 dsl_binding.binding = 0;
10010 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10011 dsl_binding.descriptorCount = 1;
10012 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10013 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010014
Tony Barboureb254902015-07-15 12:50:33 -060010015 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010016 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10017 ds_layout_ci.pNext = NULL;
10018 ds_layout_ci.bindingCount = 1;
10019 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010020
Tobin Ehlis3b780662015-05-28 12:11:26 -060010021 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010022 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010023 ASSERT_VK_SUCCESS(err);
10024
10025 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010026 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010027 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010028 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010029 alloc_info.descriptorPool = ds_pool;
10030 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010031 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010032 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010033
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010034 VkSamplerCreateInfo sampler_ci = {};
10035 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10036 sampler_ci.pNext = NULL;
10037 sampler_ci.magFilter = VK_FILTER_NEAREST;
10038 sampler_ci.minFilter = VK_FILTER_NEAREST;
10039 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10040 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10041 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10042 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10043 sampler_ci.mipLodBias = 1.0;
10044 sampler_ci.anisotropyEnable = VK_FALSE;
10045 sampler_ci.maxAnisotropy = 1;
10046 sampler_ci.compareEnable = VK_FALSE;
10047 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10048 sampler_ci.minLod = 1.0;
10049 sampler_ci.maxLod = 1.0;
10050 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10051 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10052 VkSampler sampler;
10053 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10054 ASSERT_VK_SUCCESS(err);
10055
10056 VkDescriptorImageInfo info = {};
10057 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010058
10059 VkWriteDescriptorSet descriptor_write;
10060 memset(&descriptor_write, 0, sizeof(descriptor_write));
10061 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010062 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010063 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010064 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010065 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010066 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010067
10068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10069
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010070 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010071
Chia-I Wuf7458c52015-10-26 21:10:41 +080010072 vkDestroySampler(m_device->device(), sampler, NULL);
10073 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10074 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010075}
10076
Karl Schultz6addd812016-02-02 17:17:23 -070010077TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010078 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010079 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010080
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010082
Tobin Ehlis3b780662015-05-28 12:11:26 -060010083 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010084 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010085 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010086 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10087 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010088
10089 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010090 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10091 ds_pool_ci.pNext = NULL;
10092 ds_pool_ci.maxSets = 1;
10093 ds_pool_ci.poolSizeCount = 1;
10094 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010095
Tobin Ehlis3b780662015-05-28 12:11:26 -060010096 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010097 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010098 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010099
Tony Barboureb254902015-07-15 12:50:33 -060010100 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010101 dsl_binding.binding = 0;
10102 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10103 dsl_binding.descriptorCount = 1;
10104 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10105 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010106
10107 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010108 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10109 ds_layout_ci.pNext = NULL;
10110 ds_layout_ci.bindingCount = 1;
10111 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010112
Tobin Ehlis3b780662015-05-28 12:11:26 -060010113 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010114 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010115 ASSERT_VK_SUCCESS(err);
10116
10117 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010118 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010119 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010120 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010121 alloc_info.descriptorPool = ds_pool;
10122 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010123 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010124 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010125
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010126 // Correctly update descriptor to avoid "NOT_UPDATED" error
10127 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010128 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010129 buff_info.offset = 0;
10130 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010131
10132 VkWriteDescriptorSet descriptor_write;
10133 memset(&descriptor_write, 0, sizeof(descriptor_write));
10134 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010135 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010136 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010137 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010138 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10139 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010140
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010141 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010142 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10143
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010144 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010145
Chia-I Wuf7458c52015-10-26 21:10:41 +080010146 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10147 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010148}
10149
Karl Schultz6addd812016-02-02 17:17:23 -070010150TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010151 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010152 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010153
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010155
Tobin Ehlis3b780662015-05-28 12:11:26 -060010156 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010157 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010158 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010159 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10160 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010161
10162 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010163 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10164 ds_pool_ci.pNext = NULL;
10165 ds_pool_ci.maxSets = 1;
10166 ds_pool_ci.poolSizeCount = 1;
10167 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010168
Tobin Ehlis3b780662015-05-28 12:11:26 -060010169 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010171 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010172
Tony Barboureb254902015-07-15 12:50:33 -060010173 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010174 dsl_binding.binding = 0;
10175 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10176 dsl_binding.descriptorCount = 1;
10177 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10178 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010179
10180 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010181 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10182 ds_layout_ci.pNext = NULL;
10183 ds_layout_ci.bindingCount = 1;
10184 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010185 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010187 ASSERT_VK_SUCCESS(err);
10188
10189 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010190 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010192 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010193 alloc_info.descriptorPool = ds_pool;
10194 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010196 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010197
Tony Barboureb254902015-07-15 12:50:33 -060010198 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010199 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10200 sampler_ci.pNext = NULL;
10201 sampler_ci.magFilter = VK_FILTER_NEAREST;
10202 sampler_ci.minFilter = VK_FILTER_NEAREST;
10203 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10204 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10205 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10206 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10207 sampler_ci.mipLodBias = 1.0;
10208 sampler_ci.anisotropyEnable = VK_FALSE;
10209 sampler_ci.maxAnisotropy = 1;
10210 sampler_ci.compareEnable = VK_FALSE;
10211 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10212 sampler_ci.minLod = 1.0;
10213 sampler_ci.maxLod = 1.0;
10214 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10215 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010216
Tobin Ehlis3b780662015-05-28 12:11:26 -060010217 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010218 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010219 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010220
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010221 VkDescriptorImageInfo info = {};
10222 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010223
10224 VkWriteDescriptorSet descriptor_write;
10225 memset(&descriptor_write, 0, sizeof(descriptor_write));
10226 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010227 descriptor_write.dstSet = descriptorSet;
10228 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010229 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010230 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010231 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010232 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010233
10234 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10235
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010236 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010237
Chia-I Wuf7458c52015-10-26 21:10:41 +080010238 vkDestroySampler(m_device->device(), sampler, NULL);
10239 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10240 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010241}
10242
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010243TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10244 // Create layout w/ empty binding and attempt to update it
10245 VkResult err;
10246
10247 ASSERT_NO_FATAL_FAILURE(InitState());
10248
10249 VkDescriptorPoolSize ds_type_count = {};
10250 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10251 ds_type_count.descriptorCount = 1;
10252
10253 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10254 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10255 ds_pool_ci.pNext = NULL;
10256 ds_pool_ci.maxSets = 1;
10257 ds_pool_ci.poolSizeCount = 1;
10258 ds_pool_ci.pPoolSizes = &ds_type_count;
10259
10260 VkDescriptorPool ds_pool;
10261 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10262 ASSERT_VK_SUCCESS(err);
10263
10264 VkDescriptorSetLayoutBinding dsl_binding = {};
10265 dsl_binding.binding = 0;
10266 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10267 dsl_binding.descriptorCount = 0;
10268 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10269 dsl_binding.pImmutableSamplers = NULL;
10270
10271 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10272 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10273 ds_layout_ci.pNext = NULL;
10274 ds_layout_ci.bindingCount = 1;
10275 ds_layout_ci.pBindings = &dsl_binding;
10276 VkDescriptorSetLayout ds_layout;
10277 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10278 ASSERT_VK_SUCCESS(err);
10279
10280 VkDescriptorSet descriptor_set;
10281 VkDescriptorSetAllocateInfo alloc_info = {};
10282 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10283 alloc_info.descriptorSetCount = 1;
10284 alloc_info.descriptorPool = ds_pool;
10285 alloc_info.pSetLayouts = &ds_layout;
10286 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10287 ASSERT_VK_SUCCESS(err);
10288
10289 VkSamplerCreateInfo sampler_ci = {};
10290 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10291 sampler_ci.magFilter = VK_FILTER_NEAREST;
10292 sampler_ci.minFilter = VK_FILTER_NEAREST;
10293 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10294 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10295 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10296 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10297 sampler_ci.mipLodBias = 1.0;
10298 sampler_ci.maxAnisotropy = 1;
10299 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10300 sampler_ci.minLod = 1.0;
10301 sampler_ci.maxLod = 1.0;
10302 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10303
10304 VkSampler sampler;
10305 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10306 ASSERT_VK_SUCCESS(err);
10307
10308 VkDescriptorImageInfo info = {};
10309 info.sampler = sampler;
10310
10311 VkWriteDescriptorSet descriptor_write;
10312 memset(&descriptor_write, 0, sizeof(descriptor_write));
10313 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10314 descriptor_write.dstSet = descriptor_set;
10315 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010316 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010317 // This is the wrong type, but empty binding error will be flagged first
10318 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10319 descriptor_write.pImageInfo = &info;
10320
10321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10322 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10323 m_errorMonitor->VerifyFound();
10324
10325 vkDestroySampler(m_device->device(), sampler, NULL);
10326 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10327 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10328}
10329
Karl Schultz6addd812016-02-02 17:17:23 -070010330TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10331 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10332 // types
10333 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010335 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 -060010336
Tobin Ehlis3b780662015-05-28 12:11:26 -060010337 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010338
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010339 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010340 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10341 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010342
10343 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010344 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10345 ds_pool_ci.pNext = NULL;
10346 ds_pool_ci.maxSets = 1;
10347 ds_pool_ci.poolSizeCount = 1;
10348 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010349
Tobin Ehlis3b780662015-05-28 12:11:26 -060010350 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010351 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010352 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010353 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010354 dsl_binding.binding = 0;
10355 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10356 dsl_binding.descriptorCount = 1;
10357 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10358 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010359
Tony Barboureb254902015-07-15 12:50:33 -060010360 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010361 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10362 ds_layout_ci.pNext = NULL;
10363 ds_layout_ci.bindingCount = 1;
10364 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010365
Tobin Ehlis3b780662015-05-28 12:11:26 -060010366 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010368 ASSERT_VK_SUCCESS(err);
10369
10370 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010371 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010373 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010374 alloc_info.descriptorPool = ds_pool;
10375 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010377 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010378
Tony Barboureb254902015-07-15 12:50:33 -060010379 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010380 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10381 sampler_ci.pNext = NULL;
10382 sampler_ci.magFilter = VK_FILTER_NEAREST;
10383 sampler_ci.minFilter = VK_FILTER_NEAREST;
10384 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10385 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10386 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10387 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10388 sampler_ci.mipLodBias = 1.0;
10389 sampler_ci.anisotropyEnable = VK_FALSE;
10390 sampler_ci.maxAnisotropy = 1;
10391 sampler_ci.compareEnable = VK_FALSE;
10392 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10393 sampler_ci.minLod = 1.0;
10394 sampler_ci.maxLod = 1.0;
10395 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10396 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010397 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010398 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010399 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010400
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010401 VkDescriptorImageInfo info = {};
10402 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010403
10404 VkWriteDescriptorSet descriptor_write;
10405 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010407 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010408 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010409 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010410 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010411 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010412
10413 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10414
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010415 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010416
Chia-I Wuf7458c52015-10-26 21:10:41 +080010417 vkDestroySampler(m_device->device(), sampler, NULL);
10418 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10419 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010420}
10421
Karl Schultz6addd812016-02-02 17:17:23 -070010422TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010423 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010424 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010425
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010427
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010428 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010429 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10430 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010431 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010432 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10433 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010434
10435 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010436 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10437 ds_pool_ci.pNext = NULL;
10438 ds_pool_ci.maxSets = 1;
10439 ds_pool_ci.poolSizeCount = 1;
10440 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010441
10442 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010443 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010444 ASSERT_VK_SUCCESS(err);
10445
10446 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010447 dsl_binding.binding = 0;
10448 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10449 dsl_binding.descriptorCount = 1;
10450 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10451 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010452
10453 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010454 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10455 ds_layout_ci.pNext = NULL;
10456 ds_layout_ci.bindingCount = 1;
10457 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010458 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010459 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010460 ASSERT_VK_SUCCESS(err);
10461
10462 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010463 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010464 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010465 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010466 alloc_info.descriptorPool = ds_pool;
10467 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010468 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010469 ASSERT_VK_SUCCESS(err);
10470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010471 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010472
10473 VkDescriptorImageInfo descriptor_info;
10474 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10475 descriptor_info.sampler = sampler;
10476
10477 VkWriteDescriptorSet descriptor_write;
10478 memset(&descriptor_write, 0, sizeof(descriptor_write));
10479 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010480 descriptor_write.dstSet = descriptorSet;
10481 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010482 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010483 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10484 descriptor_write.pImageInfo = &descriptor_info;
10485
10486 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10487
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010488 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010489
Chia-I Wuf7458c52015-10-26 21:10:41 +080010490 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10491 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010492}
10493
Karl Schultz6addd812016-02-02 17:17:23 -070010494TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10495 // Create a single combined Image/Sampler descriptor and send it an invalid
10496 // imageView
10497 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010498
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010500
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010501 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010502 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010503 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10504 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010505
10506 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010507 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10508 ds_pool_ci.pNext = NULL;
10509 ds_pool_ci.maxSets = 1;
10510 ds_pool_ci.poolSizeCount = 1;
10511 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010512
10513 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010514 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010515 ASSERT_VK_SUCCESS(err);
10516
10517 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010518 dsl_binding.binding = 0;
10519 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10520 dsl_binding.descriptorCount = 1;
10521 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10522 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010523
10524 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010525 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10526 ds_layout_ci.pNext = NULL;
10527 ds_layout_ci.bindingCount = 1;
10528 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010529 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010530 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010531 ASSERT_VK_SUCCESS(err);
10532
10533 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010534 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010535 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010536 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010537 alloc_info.descriptorPool = ds_pool;
10538 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010539 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010540 ASSERT_VK_SUCCESS(err);
10541
10542 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010543 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10544 sampler_ci.pNext = NULL;
10545 sampler_ci.magFilter = VK_FILTER_NEAREST;
10546 sampler_ci.minFilter = VK_FILTER_NEAREST;
10547 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10548 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10549 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10550 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10551 sampler_ci.mipLodBias = 1.0;
10552 sampler_ci.anisotropyEnable = VK_FALSE;
10553 sampler_ci.maxAnisotropy = 1;
10554 sampler_ci.compareEnable = VK_FALSE;
10555 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10556 sampler_ci.minLod = 1.0;
10557 sampler_ci.maxLod = 1.0;
10558 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10559 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010560
10561 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010562 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010563 ASSERT_VK_SUCCESS(err);
10564
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010565 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010566
10567 VkDescriptorImageInfo descriptor_info;
10568 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10569 descriptor_info.sampler = sampler;
10570 descriptor_info.imageView = view;
10571
10572 VkWriteDescriptorSet descriptor_write;
10573 memset(&descriptor_write, 0, sizeof(descriptor_write));
10574 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010575 descriptor_write.dstSet = descriptorSet;
10576 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010577 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010578 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10579 descriptor_write.pImageInfo = &descriptor_info;
10580
10581 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10582
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010583 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010584
Chia-I Wuf7458c52015-10-26 21:10:41 +080010585 vkDestroySampler(m_device->device(), sampler, NULL);
10586 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10587 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010588}
10589
Karl Schultz6addd812016-02-02 17:17:23 -070010590TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10591 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10592 // into the other
10593 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010594
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10596 " binding #1 with type "
10597 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10598 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010599
Tobin Ehlis04356f92015-10-27 16:35:27 -060010600 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010601 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010602 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010603 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10604 ds_type_count[0].descriptorCount = 1;
10605 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10606 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010607
10608 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010609 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10610 ds_pool_ci.pNext = NULL;
10611 ds_pool_ci.maxSets = 1;
10612 ds_pool_ci.poolSizeCount = 2;
10613 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010614
10615 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010616 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010617 ASSERT_VK_SUCCESS(err);
10618 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010619 dsl_binding[0].binding = 0;
10620 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10621 dsl_binding[0].descriptorCount = 1;
10622 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10623 dsl_binding[0].pImmutableSamplers = NULL;
10624 dsl_binding[1].binding = 1;
10625 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10626 dsl_binding[1].descriptorCount = 1;
10627 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10628 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010629
10630 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010631 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10632 ds_layout_ci.pNext = NULL;
10633 ds_layout_ci.bindingCount = 2;
10634 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010635
10636 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010637 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010638 ASSERT_VK_SUCCESS(err);
10639
10640 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010641 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010642 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010643 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010644 alloc_info.descriptorPool = ds_pool;
10645 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010646 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010647 ASSERT_VK_SUCCESS(err);
10648
10649 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010650 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10651 sampler_ci.pNext = NULL;
10652 sampler_ci.magFilter = VK_FILTER_NEAREST;
10653 sampler_ci.minFilter = VK_FILTER_NEAREST;
10654 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10655 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10656 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10657 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10658 sampler_ci.mipLodBias = 1.0;
10659 sampler_ci.anisotropyEnable = VK_FALSE;
10660 sampler_ci.maxAnisotropy = 1;
10661 sampler_ci.compareEnable = VK_FALSE;
10662 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10663 sampler_ci.minLod = 1.0;
10664 sampler_ci.maxLod = 1.0;
10665 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10666 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010667
10668 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010669 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010670 ASSERT_VK_SUCCESS(err);
10671
10672 VkDescriptorImageInfo info = {};
10673 info.sampler = sampler;
10674
10675 VkWriteDescriptorSet descriptor_write;
10676 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10677 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010678 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010679 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010680 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010681 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10682 descriptor_write.pImageInfo = &info;
10683 // This write update should succeed
10684 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10685 // Now perform a copy update that fails due to type mismatch
10686 VkCopyDescriptorSet copy_ds_update;
10687 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10688 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10689 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010690 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010691 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010692 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10693 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010694 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10695
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010696 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010697 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010698 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 -060010699 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10700 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10701 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010702 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010703 copy_ds_update.dstSet = descriptorSet;
10704 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010705 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010706 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10707
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010708 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010709
Tobin Ehlis04356f92015-10-27 16:35:27 -060010710 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10712 " binding#1 with offset index of 1 plus "
10713 "update array offset of 0 and update of "
10714 "5 descriptors oversteps total number "
10715 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010716
Tobin Ehlis04356f92015-10-27 16:35:27 -060010717 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10718 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10719 copy_ds_update.srcSet = descriptorSet;
10720 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010721 copy_ds_update.dstSet = descriptorSet;
10722 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010723 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010724 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10725
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010726 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010727
Chia-I Wuf7458c52015-10-26 21:10:41 +080010728 vkDestroySampler(m_device->device(), sampler, NULL);
10729 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10730 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010731}
10732
Karl Schultz6addd812016-02-02 17:17:23 -070010733TEST_F(VkLayerTest, NumSamplesMismatch) {
10734 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10735 // sampleCount
10736 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010739
Tobin Ehlis3b780662015-05-28 12:11:26 -060010740 ASSERT_NO_FATAL_FAILURE(InitState());
10741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010742 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010743 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010744 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010745
10746 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010747 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10748 ds_pool_ci.pNext = NULL;
10749 ds_pool_ci.maxSets = 1;
10750 ds_pool_ci.poolSizeCount = 1;
10751 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010752
Tobin Ehlis3b780662015-05-28 12:11:26 -060010753 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010754 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010755 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010756
Tony Barboureb254902015-07-15 12:50:33 -060010757 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010758 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010759 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010760 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010761 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10762 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010763
Tony Barboureb254902015-07-15 12:50:33 -060010764 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10765 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10766 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010767 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010768 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010769
Tobin Ehlis3b780662015-05-28 12:11:26 -060010770 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010771 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010772 ASSERT_VK_SUCCESS(err);
10773
10774 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010775 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010776 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010777 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010778 alloc_info.descriptorPool = ds_pool;
10779 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010780 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010781 ASSERT_VK_SUCCESS(err);
10782
Tony Barboureb254902015-07-15 12:50:33 -060010783 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010784 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010785 pipe_ms_state_ci.pNext = NULL;
10786 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10787 pipe_ms_state_ci.sampleShadingEnable = 0;
10788 pipe_ms_state_ci.minSampleShading = 1.0;
10789 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010790
Tony Barboureb254902015-07-15 12:50:33 -060010791 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010792 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10793 pipeline_layout_ci.pNext = NULL;
10794 pipeline_layout_ci.setLayoutCount = 1;
10795 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010796
10797 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010798 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010799 ASSERT_VK_SUCCESS(err);
10800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010801 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010802 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 -060010803 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010804 VkPipelineObj pipe(m_device);
10805 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010806 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010807 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010808 pipe.SetMSAA(&pipe_ms_state_ci);
10809 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010810
Tony Barbour552f6c02016-12-21 14:34:07 -070010811 m_commandBuffer->BeginCommandBuffer();
10812 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010813 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010814
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010815 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10816 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10817 VkRect2D scissor = {{0, 0}, {16, 16}};
10818 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10819
Mark Young29927482016-05-04 14:38:51 -060010820 // Render triangle (the error should trigger on the attempt to draw).
10821 Draw(3, 1, 0, 0);
10822
10823 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010824 m_commandBuffer->EndRenderPass();
10825 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010826
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010827 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010828
Chia-I Wuf7458c52015-10-26 21:10:41 +080010829 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010832}
Mark Young29927482016-05-04 14:38:51 -060010833
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010834TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010835 TEST_DESCRIPTION(
10836 "Hit RenderPass incompatible cases. "
10837 "Initial case is drawing with an active renderpass that's "
10838 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010839 VkResult err;
10840
10841 ASSERT_NO_FATAL_FAILURE(InitState());
10842 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10843
10844 VkDescriptorSetLayoutBinding dsl_binding = {};
10845 dsl_binding.binding = 0;
10846 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10847 dsl_binding.descriptorCount = 1;
10848 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10849 dsl_binding.pImmutableSamplers = NULL;
10850
10851 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10852 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10853 ds_layout_ci.pNext = NULL;
10854 ds_layout_ci.bindingCount = 1;
10855 ds_layout_ci.pBindings = &dsl_binding;
10856
10857 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010858 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010859 ASSERT_VK_SUCCESS(err);
10860
10861 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10862 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10863 pipeline_layout_ci.pNext = NULL;
10864 pipeline_layout_ci.setLayoutCount = 1;
10865 pipeline_layout_ci.pSetLayouts = &ds_layout;
10866
10867 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010868 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010869 ASSERT_VK_SUCCESS(err);
10870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010871 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010872 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 -060010873 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010874 // Create a renderpass that will be incompatible with default renderpass
10875 VkAttachmentReference attach = {};
10876 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10877 VkAttachmentReference color_att = {};
10878 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10879 VkSubpassDescription subpass = {};
10880 subpass.inputAttachmentCount = 1;
10881 subpass.pInputAttachments = &attach;
10882 subpass.colorAttachmentCount = 1;
10883 subpass.pColorAttachments = &color_att;
10884 VkRenderPassCreateInfo rpci = {};
10885 rpci.subpassCount = 1;
10886 rpci.pSubpasses = &subpass;
10887 rpci.attachmentCount = 1;
10888 VkAttachmentDescription attach_desc = {};
10889 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010890 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10891 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010892 rpci.pAttachments = &attach_desc;
10893 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10894 VkRenderPass rp;
10895 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10896 VkPipelineObj pipe(m_device);
10897 pipe.AddShader(&vs);
10898 pipe.AddShader(&fs);
10899 pipe.AddColorAttachment();
10900 VkViewport view_port = {};
10901 m_viewports.push_back(view_port);
10902 pipe.SetViewport(m_viewports);
10903 VkRect2D rect = {};
10904 m_scissors.push_back(rect);
10905 pipe.SetScissor(m_scissors);
10906 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10907
10908 VkCommandBufferInheritanceInfo cbii = {};
10909 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10910 cbii.renderPass = rp;
10911 cbii.subpass = 0;
10912 VkCommandBufferBeginInfo cbbi = {};
10913 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10914 cbbi.pInheritanceInfo = &cbii;
10915 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10916 VkRenderPassBeginInfo rpbi = {};
10917 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10918 rpbi.framebuffer = m_framebuffer;
10919 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010920 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10921 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010922
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010924 // Render triangle (the error should trigger on the attempt to draw).
10925 Draw(3, 1, 0, 0);
10926
10927 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010928 m_commandBuffer->EndRenderPass();
10929 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010930
10931 m_errorMonitor->VerifyFound();
10932
10933 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10934 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10935 vkDestroyRenderPass(m_device->device(), rp, NULL);
10936}
10937
Mark Youngc89c6312016-03-31 16:03:20 -060010938TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10939 // Create Pipeline where the number of blend attachments doesn't match the
10940 // number of color attachments. In this case, we don't add any color
10941 // blend attachments even though we have a color attachment.
10942 VkResult err;
10943
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010945
10946 ASSERT_NO_FATAL_FAILURE(InitState());
10947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10948 VkDescriptorPoolSize ds_type_count = {};
10949 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10950 ds_type_count.descriptorCount = 1;
10951
10952 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10953 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10954 ds_pool_ci.pNext = NULL;
10955 ds_pool_ci.maxSets = 1;
10956 ds_pool_ci.poolSizeCount = 1;
10957 ds_pool_ci.pPoolSizes = &ds_type_count;
10958
10959 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010960 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010961 ASSERT_VK_SUCCESS(err);
10962
10963 VkDescriptorSetLayoutBinding dsl_binding = {};
10964 dsl_binding.binding = 0;
10965 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10966 dsl_binding.descriptorCount = 1;
10967 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10968 dsl_binding.pImmutableSamplers = NULL;
10969
10970 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10971 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10972 ds_layout_ci.pNext = NULL;
10973 ds_layout_ci.bindingCount = 1;
10974 ds_layout_ci.pBindings = &dsl_binding;
10975
10976 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010977 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010978 ASSERT_VK_SUCCESS(err);
10979
10980 VkDescriptorSet descriptorSet;
10981 VkDescriptorSetAllocateInfo alloc_info = {};
10982 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10983 alloc_info.descriptorSetCount = 1;
10984 alloc_info.descriptorPool = ds_pool;
10985 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010986 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010987 ASSERT_VK_SUCCESS(err);
10988
10989 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010990 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010991 pipe_ms_state_ci.pNext = NULL;
10992 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10993 pipe_ms_state_ci.sampleShadingEnable = 0;
10994 pipe_ms_state_ci.minSampleShading = 1.0;
10995 pipe_ms_state_ci.pSampleMask = NULL;
10996
10997 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10998 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10999 pipeline_layout_ci.pNext = NULL;
11000 pipeline_layout_ci.setLayoutCount = 1;
11001 pipeline_layout_ci.pSetLayouts = &ds_layout;
11002
11003 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011004 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011005 ASSERT_VK_SUCCESS(err);
11006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011007 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011008 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 -060011009 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011010 VkPipelineObj pipe(m_device);
11011 pipe.AddShader(&vs);
11012 pipe.AddShader(&fs);
11013 pipe.SetMSAA(&pipe_ms_state_ci);
11014 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011015 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011016
11017 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11018 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11019 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11020}
Mark Young29927482016-05-04 14:38:51 -060011021
Mark Muellerd4914412016-06-13 17:52:06 -060011022TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011023 TEST_DESCRIPTION(
11024 "Points to a wrong colorAttachment index in a VkClearAttachment "
11025 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011026 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011028
11029 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11030 m_errorMonitor->VerifyFound();
11031}
11032
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011033TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011034 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11035 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011036
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011037 ASSERT_NO_FATAL_FAILURE(InitState());
11038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011039
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11042 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011043
11044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11046 ds_pool_ci.pNext = NULL;
11047 ds_pool_ci.maxSets = 1;
11048 ds_pool_ci.poolSizeCount = 1;
11049 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011050
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011051 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011052 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011053 ASSERT_VK_SUCCESS(err);
11054
Tony Barboureb254902015-07-15 12:50:33 -060011055 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011056 dsl_binding.binding = 0;
11057 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11058 dsl_binding.descriptorCount = 1;
11059 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11060 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011061
Tony Barboureb254902015-07-15 12:50:33 -060011062 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011063 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11064 ds_layout_ci.pNext = NULL;
11065 ds_layout_ci.bindingCount = 1;
11066 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011067
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011068 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011069 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011070 ASSERT_VK_SUCCESS(err);
11071
11072 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011073 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011074 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011075 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011076 alloc_info.descriptorPool = ds_pool;
11077 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011078 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011079 ASSERT_VK_SUCCESS(err);
11080
Tony Barboureb254902015-07-15 12:50:33 -060011081 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011082 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011083 pipe_ms_state_ci.pNext = NULL;
11084 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11085 pipe_ms_state_ci.sampleShadingEnable = 0;
11086 pipe_ms_state_ci.minSampleShading = 1.0;
11087 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011088
Tony Barboureb254902015-07-15 12:50:33 -060011089 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011090 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11091 pipeline_layout_ci.pNext = NULL;
11092 pipeline_layout_ci.setLayoutCount = 1;
11093 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011094
11095 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011096 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011097 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011099 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011100 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011101 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011102 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011103
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011104 VkPipelineObj pipe(m_device);
11105 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011106 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011107 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011108 m_errorMonitor->SetUnexpectedError(
11109 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11110 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011111 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011112
Tony Barbour552f6c02016-12-21 14:34:07 -070011113 m_commandBuffer->BeginCommandBuffer();
11114 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011115
Karl Schultz6addd812016-02-02 17:17:23 -070011116 // Main thing we care about for this test is that the VkImage obj we're
11117 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011118 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011119 VkClearAttachment color_attachment;
11120 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11121 color_attachment.clearValue.color.float32[0] = 1.0;
11122 color_attachment.clearValue.color.float32[1] = 1.0;
11123 color_attachment.clearValue.color.float32[2] = 1.0;
11124 color_attachment.clearValue.color.float32[3] = 1.0;
11125 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011126 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011127
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011128 // Call for full-sized FB Color attachment prior to issuing a Draw
11129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011130 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011131 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011132 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011133
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011134 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11135 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11137 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11138 m_errorMonitor->VerifyFound();
11139
11140 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11141 clear_rect.layerCount = 2;
11142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11143 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011144 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011145
Chia-I Wuf7458c52015-10-26 21:10:41 +080011146 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11147 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11148 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011149}
11150
Karl Schultz6addd812016-02-02 17:17:23 -070011151TEST_F(VkLayerTest, VtxBufferBadIndex) {
11152 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11155 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011156
Tobin Ehlis502480b2015-06-24 15:53:07 -060011157 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011158 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011160
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011161 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011162 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11163 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011164
11165 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011166 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11167 ds_pool_ci.pNext = NULL;
11168 ds_pool_ci.maxSets = 1;
11169 ds_pool_ci.poolSizeCount = 1;
11170 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011171
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011172 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011173 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011174 ASSERT_VK_SUCCESS(err);
11175
Tony Barboureb254902015-07-15 12:50:33 -060011176 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011177 dsl_binding.binding = 0;
11178 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11179 dsl_binding.descriptorCount = 1;
11180 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11181 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011182
Tony Barboureb254902015-07-15 12:50:33 -060011183 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011184 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11185 ds_layout_ci.pNext = NULL;
11186 ds_layout_ci.bindingCount = 1;
11187 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011188
Tobin Ehlis502480b2015-06-24 15:53:07 -060011189 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011191 ASSERT_VK_SUCCESS(err);
11192
11193 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011194 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011195 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011196 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011197 alloc_info.descriptorPool = ds_pool;
11198 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011199 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011200 ASSERT_VK_SUCCESS(err);
11201
Tony Barboureb254902015-07-15 12:50:33 -060011202 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011203 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011204 pipe_ms_state_ci.pNext = NULL;
11205 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11206 pipe_ms_state_ci.sampleShadingEnable = 0;
11207 pipe_ms_state_ci.minSampleShading = 1.0;
11208 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011209
Tony Barboureb254902015-07-15 12:50:33 -060011210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11212 pipeline_layout_ci.pNext = NULL;
11213 pipeline_layout_ci.setLayoutCount = 1;
11214 pipeline_layout_ci.pSetLayouts = &ds_layout;
11215 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011218 ASSERT_VK_SUCCESS(err);
11219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011220 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011221 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 -060011222 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011223 VkPipelineObj pipe(m_device);
11224 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011225 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011226 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011227 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011228 pipe.SetViewport(m_viewports);
11229 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011230 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011231
Tony Barbour552f6c02016-12-21 14:34:07 -070011232 m_commandBuffer->BeginCommandBuffer();
11233 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011235 // Don't care about actual data, just need to get to draw to flag error
11236 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011237 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011238 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011239 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011240
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011241 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011242
Chia-I Wuf7458c52015-10-26 21:10:41 +080011243 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11244 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11245 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011246}
Mark Muellerdfe37552016-07-07 14:47:42 -060011247
Mark Mueller2ee294f2016-08-04 12:59:48 -060011248TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011249 TEST_DESCRIPTION(
11250 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11251 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011252 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011253
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011254 const char *invalid_queueFamilyIndex_message =
11255 "Invalid queue create request in vkCreateDevice(). Invalid "
11256 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011258 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011259
Mark Mueller880fce52016-08-17 15:23:23 -060011260 // The following test fails with recent NVidia drivers.
11261 // By the time core_validation is reached, the NVidia
11262 // driver has sanitized the invalid condition and core_validation
11263 // is not introduced to the failure condition. This is not the case
11264 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011265 // uint32_t count = static_cast<uint32_t>(~0);
11266 // VkPhysicalDevice physical_device;
11267 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11268 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011271 float queue_priority = 0.0;
11272
11273 VkDeviceQueueCreateInfo queue_create_info = {};
11274 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11275 queue_create_info.queueCount = 1;
11276 queue_create_info.pQueuePriorities = &queue_priority;
11277 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11278
11279 VkPhysicalDeviceFeatures features = m_device->phy().features();
11280 VkDevice testDevice;
11281 VkDeviceCreateInfo device_create_info = {};
11282 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11283 device_create_info.queueCreateInfoCount = 1;
11284 device_create_info.pQueueCreateInfos = &queue_create_info;
11285 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011286 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011287 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11288 m_errorMonitor->VerifyFound();
11289
11290 queue_create_info.queueFamilyIndex = 1;
11291
11292 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11293 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11294 for (unsigned i = 0; i < feature_count; i++) {
11295 if (VK_FALSE == feature_array[i]) {
11296 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011298 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011299 m_errorMonitor->SetUnexpectedError(
11300 "You requested features that are unavailable on this device. You should first query feature availability by "
11301 "calling vkGetPhysicalDeviceFeatures().");
11302 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011303 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11304 m_errorMonitor->VerifyFound();
11305 break;
11306 }
11307 }
11308}
11309
Tobin Ehlis16edf082016-11-21 12:33:49 -070011310TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11311 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11312
11313 ASSERT_NO_FATAL_FAILURE(InitState());
11314
11315 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11316 std::vector<VkDeviceQueueCreateInfo> queue_info;
11317 queue_info.reserve(queue_props.size());
11318 std::vector<std::vector<float>> queue_priorities;
11319 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11320 VkDeviceQueueCreateInfo qi{};
11321 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11322 qi.queueFamilyIndex = i;
11323 qi.queueCount = queue_props[i].queueCount;
11324 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11325 qi.pQueuePriorities = queue_priorities[i].data();
11326 queue_info.push_back(qi);
11327 }
11328
11329 std::vector<const char *> device_extension_names;
11330
11331 VkDevice local_device;
11332 VkDeviceCreateInfo device_create_info = {};
11333 auto features = m_device->phy().features();
11334 // Intentionally disable pipeline stats
11335 features.pipelineStatisticsQuery = VK_FALSE;
11336 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11337 device_create_info.pNext = NULL;
11338 device_create_info.queueCreateInfoCount = queue_info.size();
11339 device_create_info.pQueueCreateInfos = queue_info.data();
11340 device_create_info.enabledLayerCount = 0;
11341 device_create_info.ppEnabledLayerNames = NULL;
11342 device_create_info.pEnabledFeatures = &features;
11343 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11344 ASSERT_VK_SUCCESS(err);
11345
11346 VkQueryPoolCreateInfo qpci{};
11347 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11348 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11349 qpci.queryCount = 1;
11350 VkQueryPool query_pool;
11351
11352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11353 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11354 m_errorMonitor->VerifyFound();
11355
11356 vkDestroyDevice(local_device, nullptr);
11357}
11358
Mark Mueller2ee294f2016-08-04 12:59:48 -060011359TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011360 TEST_DESCRIPTION(
11361 "Use an invalid queue index in a vkCmdWaitEvents call."
11362 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011363
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011364 const char *invalid_queue_index =
11365 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11366 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11367 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011369 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011372
11373 ASSERT_NO_FATAL_FAILURE(InitState());
11374
11375 VkEvent event;
11376 VkEventCreateInfo event_create_info{};
11377 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11378 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11379
Mark Mueller2ee294f2016-08-04 12:59:48 -060011380 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011381 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011382
Tony Barbour552f6c02016-12-21 14:34:07 -070011383 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011384
11385 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011386 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 -060011387 ASSERT_TRUE(image.initialized());
11388 VkImageMemoryBarrier img_barrier = {};
11389 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11390 img_barrier.pNext = NULL;
11391 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11392 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11393 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11394 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11395 img_barrier.image = image.handle();
11396 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011397
11398 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11399 // that layer validation catches the case when it is not.
11400 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011401 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11402 img_barrier.subresourceRange.baseArrayLayer = 0;
11403 img_barrier.subresourceRange.baseMipLevel = 0;
11404 img_barrier.subresourceRange.layerCount = 1;
11405 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011406 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11407 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011408 m_errorMonitor->VerifyFound();
11409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011411
11412 VkQueryPool query_pool;
11413 VkQueryPoolCreateInfo query_pool_create_info = {};
11414 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11415 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11416 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011417 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011419 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011420 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11421
11422 vkEndCommandBuffer(m_commandBuffer->handle());
11423 m_errorMonitor->VerifyFound();
11424
11425 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11426 vkDestroyEvent(m_device->device(), event, nullptr);
11427}
11428
Mark Muellerdfe37552016-07-07 14:47:42 -060011429TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011430 TEST_DESCRIPTION(
11431 "Submit a command buffer using deleted vertex buffer, "
11432 "delete a buffer twice, use an invalid offset for each "
11433 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011434
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011435 const char *deleted_buffer_in_command_buffer =
11436 "Cannot submit cmd buffer "
11437 "using deleted buffer ";
11438 const char *invalid_offset_message =
11439 "vkBindBufferMemory(): "
11440 "memoryOffset is 0x";
11441 const char *invalid_storage_buffer_offset_message =
11442 "vkBindBufferMemory(): "
11443 "storage memoryOffset "
11444 "is 0x";
11445 const char *invalid_texel_buffer_offset_message =
11446 "vkBindBufferMemory(): "
11447 "texel memoryOffset "
11448 "is 0x";
11449 const char *invalid_uniform_buffer_offset_message =
11450 "vkBindBufferMemory(): "
11451 "uniform memoryOffset "
11452 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011453
11454 ASSERT_NO_FATAL_FAILURE(InitState());
11455 ASSERT_NO_FATAL_FAILURE(InitViewport());
11456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11457
11458 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011459 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011460 pipe_ms_state_ci.pNext = NULL;
11461 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11462 pipe_ms_state_ci.sampleShadingEnable = 0;
11463 pipe_ms_state_ci.minSampleShading = 1.0;
11464 pipe_ms_state_ci.pSampleMask = nullptr;
11465
11466 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11467 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11468 VkPipelineLayout pipeline_layout;
11469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011470 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011471 ASSERT_VK_SUCCESS(err);
11472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011473 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11474 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011475 VkPipelineObj pipe(m_device);
11476 pipe.AddShader(&vs);
11477 pipe.AddShader(&fs);
11478 pipe.AddColorAttachment();
11479 pipe.SetMSAA(&pipe_ms_state_ci);
11480 pipe.SetViewport(m_viewports);
11481 pipe.SetScissor(m_scissors);
11482 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11483
Tony Barbour552f6c02016-12-21 14:34:07 -070011484 m_commandBuffer->BeginCommandBuffer();
11485 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011486 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011487
11488 {
11489 // Create and bind a vertex buffer in a reduced scope, which will cause
11490 // it to be deleted upon leaving this scope
11491 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011492 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011493 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11494 draw_verticies.AddVertexInputToPipe(pipe);
11495 }
11496
11497 Draw(1, 0, 0, 0);
11498
Tony Barbour552f6c02016-12-21 14:34:07 -070011499 m_commandBuffer->EndRenderPass();
11500 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011503 QueueCommandBuffer(false);
11504 m_errorMonitor->VerifyFound();
11505
11506 {
11507 // Create and bind a vertex buffer in a reduced scope, and delete it
11508 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011509 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011511 buffer_test.TestDoubleDestroy();
11512 }
11513 m_errorMonitor->VerifyFound();
11514
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011515 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011516 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011517 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011519 m_errorMonitor->SetUnexpectedError(
11520 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11521 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011522 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11523 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011524 m_errorMonitor->VerifyFound();
11525 }
11526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011527 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11528 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011529 // Create and bind a memory buffer with an invalid offset again,
11530 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011532 m_errorMonitor->SetUnexpectedError(
11533 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11534 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11536 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011537 m_errorMonitor->VerifyFound();
11538 }
11539
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011540 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011541 // Create and bind a memory buffer with an invalid offset again, but
11542 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011544 m_errorMonitor->SetUnexpectedError(
11545 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11546 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011547 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11548 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011549 m_errorMonitor->VerifyFound();
11550 }
11551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011552 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011553 // Create and bind a memory buffer with an invalid offset again, but
11554 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011556 m_errorMonitor->SetUnexpectedError(
11557 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11558 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011559 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11560 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011561 m_errorMonitor->VerifyFound();
11562 }
11563
11564 {
11565 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011567 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11568 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011569 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11570 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011571 m_errorMonitor->VerifyFound();
11572 }
11573
11574 {
11575 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011577 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11578 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011579 }
11580 m_errorMonitor->VerifyFound();
11581
11582 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11583}
11584
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011585// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11586TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011587 TEST_DESCRIPTION(
11588 "Hit all possible validation checks associated with the "
11589 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11590 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011591 // 3 in ValidateCmdBufImageLayouts
11592 // * -1 Attempt to submit cmd buf w/ deleted image
11593 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11594 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011595
11596 ASSERT_NO_FATAL_FAILURE(InitState());
11597 // Create src & dst images to use for copy operations
11598 VkImage src_image;
11599 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011600 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011601
11602 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11603 const int32_t tex_width = 32;
11604 const int32_t tex_height = 32;
11605
11606 VkImageCreateInfo image_create_info = {};
11607 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11608 image_create_info.pNext = NULL;
11609 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11610 image_create_info.format = tex_format;
11611 image_create_info.extent.width = tex_width;
11612 image_create_info.extent.height = tex_height;
11613 image_create_info.extent.depth = 1;
11614 image_create_info.mipLevels = 1;
11615 image_create_info.arrayLayers = 4;
11616 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11617 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11618 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011619 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011620 image_create_info.flags = 0;
11621
11622 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11623 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011624 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011625 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11626 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011627 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11628 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11629 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11630 ASSERT_VK_SUCCESS(err);
11631
11632 // Allocate memory
11633 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011634 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011635 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011636 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11637 mem_alloc.pNext = NULL;
11638 mem_alloc.allocationSize = 0;
11639 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011640
11641 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011642 mem_alloc.allocationSize = img_mem_reqs.size;
11643 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011644 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011645 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011646 ASSERT_VK_SUCCESS(err);
11647
11648 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011649 mem_alloc.allocationSize = img_mem_reqs.size;
11650 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011651 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011652 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011653 ASSERT_VK_SUCCESS(err);
11654
11655 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011656 mem_alloc.allocationSize = img_mem_reqs.size;
11657 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011658 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011659 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011660 ASSERT_VK_SUCCESS(err);
11661
11662 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11663 ASSERT_VK_SUCCESS(err);
11664 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11665 ASSERT_VK_SUCCESS(err);
11666 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11667 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011668
Tony Barbour552f6c02016-12-21 14:34:07 -070011669 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011670 VkImageCopy copy_region;
11671 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11672 copy_region.srcSubresource.mipLevel = 0;
11673 copy_region.srcSubresource.baseArrayLayer = 0;
11674 copy_region.srcSubresource.layerCount = 1;
11675 copy_region.srcOffset.x = 0;
11676 copy_region.srcOffset.y = 0;
11677 copy_region.srcOffset.z = 0;
11678 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11679 copy_region.dstSubresource.mipLevel = 0;
11680 copy_region.dstSubresource.baseArrayLayer = 0;
11681 copy_region.dstSubresource.layerCount = 1;
11682 copy_region.dstOffset.x = 0;
11683 copy_region.dstOffset.y = 0;
11684 copy_region.dstOffset.z = 0;
11685 copy_region.extent.width = 1;
11686 copy_region.extent.height = 1;
11687 copy_region.extent.depth = 1;
11688
11689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11690 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011691 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011692 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 -060011693 m_errorMonitor->VerifyFound();
11694 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11696 "Cannot copy from an image whose source layout is "
11697 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11698 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011699 m_errorMonitor->SetUnexpectedError(
11700 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011701 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 -060011702 m_errorMonitor->VerifyFound();
11703 // Final src error is due to bad layout type
11704 m_errorMonitor->SetDesiredFailureMsg(
11705 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11706 "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 -070011707 m_errorMonitor->SetUnexpectedError(
11708 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11709 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011710 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 -060011711 m_errorMonitor->VerifyFound();
11712 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11714 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011715 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011716 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 -060011717 m_errorMonitor->VerifyFound();
11718 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11720 "Cannot copy from an image whose dest layout is "
11721 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11722 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011723 m_errorMonitor->SetUnexpectedError(
11724 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011725 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 -060011726 m_errorMonitor->VerifyFound();
11727 m_errorMonitor->SetDesiredFailureMsg(
11728 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11729 "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 -070011730 m_errorMonitor->SetUnexpectedError(
11731 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11732 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011733 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 -060011734 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011735
Cort3b021012016-12-07 12:00:57 -080011736 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11737 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11738 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11739 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11740 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11741 transfer_dst_image_barrier[0].srcAccessMask = 0;
11742 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11743 transfer_dst_image_barrier[0].image = dst_image;
11744 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11745 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11746 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11747 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11748 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11749 transfer_dst_image_barrier[0].image = depth_image;
11750 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11751 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11752 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11753
11754 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011755 VkClearColorValue color_clear_value = {};
11756 VkImageSubresourceRange clear_range;
11757 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11758 clear_range.baseMipLevel = 0;
11759 clear_range.baseArrayLayer = 0;
11760 clear_range.layerCount = 1;
11761 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011762
Cort3b021012016-12-07 12:00:57 -080011763 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11764 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011767 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011768 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011769 // Fail due to provided layout not matching actual current layout for color clear.
11770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011771 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011772 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011773
Cort530cf382016-12-08 09:59:47 -080011774 VkClearDepthStencilValue depth_clear_value = {};
11775 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011776
11777 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11778 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011781 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011782 m_errorMonitor->VerifyFound();
11783 // Fail due to provided layout not matching actual current layout for depth clear.
11784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011785 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011786 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011787
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011788 // Now cause error due to bad image layout transition in PipelineBarrier
11789 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011790 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011791 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011792 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011793 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011794 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11795 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011796 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11798 "You cannot transition the layout of aspect 1 from "
11799 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11800 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011801 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11802 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011803 m_errorMonitor->VerifyFound();
11804
11805 // Finally some layout errors at RenderPass create time
11806 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11807 VkAttachmentReference attach = {};
11808 // perf warning for GENERAL layout w/ non-DS input attachment
11809 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11810 VkSubpassDescription subpass = {};
11811 subpass.inputAttachmentCount = 1;
11812 subpass.pInputAttachments = &attach;
11813 VkRenderPassCreateInfo rpci = {};
11814 rpci.subpassCount = 1;
11815 rpci.pSubpasses = &subpass;
11816 rpci.attachmentCount = 1;
11817 VkAttachmentDescription attach_desc = {};
11818 attach_desc.format = VK_FORMAT_UNDEFINED;
11819 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011820 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011821 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11823 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011824 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11825 m_errorMonitor->VerifyFound();
11826 // error w/ non-general layout
11827 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11828
11829 m_errorMonitor->SetDesiredFailureMsg(
11830 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11831 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11832 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11833 m_errorMonitor->VerifyFound();
11834 subpass.inputAttachmentCount = 0;
11835 subpass.colorAttachmentCount = 1;
11836 subpass.pColorAttachments = &attach;
11837 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11838 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11840 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011841 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11842 m_errorMonitor->VerifyFound();
11843 // error w/ non-color opt or GENERAL layout for color attachment
11844 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11845 m_errorMonitor->SetDesiredFailureMsg(
11846 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11847 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11848 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11849 m_errorMonitor->VerifyFound();
11850 subpass.colorAttachmentCount = 0;
11851 subpass.pDepthStencilAttachment = &attach;
11852 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11853 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11855 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011856 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11857 m_errorMonitor->VerifyFound();
11858 // error w/ non-ds opt or GENERAL layout for color attachment
11859 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11861 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11862 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011863 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11864 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011865 // For this error we need a valid renderpass so create default one
11866 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11867 attach.attachment = 0;
11868 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11869 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11870 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11871 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11872 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11873 // Can't do a CLEAR load on READ_ONLY initialLayout
11874 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11875 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11876 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11878 " with invalid first layout "
11879 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11880 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011881 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11882 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011883
Cort3b021012016-12-07 12:00:57 -080011884 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11885 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11886 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011887 vkDestroyImage(m_device->device(), src_image, NULL);
11888 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011889 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011890}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011891
Tobin Ehlise0936662016-10-11 08:10:51 -060011892TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11893 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11894 VkResult err;
11895
11896 ASSERT_NO_FATAL_FAILURE(InitState());
11897
11898 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11899 VkImageTiling tiling;
11900 VkFormatProperties format_properties;
11901 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11902 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11903 tiling = VK_IMAGE_TILING_LINEAR;
11904 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11905 tiling = VK_IMAGE_TILING_OPTIMAL;
11906 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011907 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011908 return;
11909 }
11910
11911 VkDescriptorPoolSize ds_type = {};
11912 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11913 ds_type.descriptorCount = 1;
11914
11915 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11916 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11917 ds_pool_ci.maxSets = 1;
11918 ds_pool_ci.poolSizeCount = 1;
11919 ds_pool_ci.pPoolSizes = &ds_type;
11920 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11921
11922 VkDescriptorPool ds_pool;
11923 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11924 ASSERT_VK_SUCCESS(err);
11925
11926 VkDescriptorSetLayoutBinding dsl_binding = {};
11927 dsl_binding.binding = 0;
11928 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11929 dsl_binding.descriptorCount = 1;
11930 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11931 dsl_binding.pImmutableSamplers = NULL;
11932
11933 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11934 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11935 ds_layout_ci.pNext = NULL;
11936 ds_layout_ci.bindingCount = 1;
11937 ds_layout_ci.pBindings = &dsl_binding;
11938
11939 VkDescriptorSetLayout ds_layout;
11940 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11941 ASSERT_VK_SUCCESS(err);
11942
11943 VkDescriptorSetAllocateInfo alloc_info = {};
11944 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11945 alloc_info.descriptorSetCount = 1;
11946 alloc_info.descriptorPool = ds_pool;
11947 alloc_info.pSetLayouts = &ds_layout;
11948 VkDescriptorSet descriptor_set;
11949 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11950 ASSERT_VK_SUCCESS(err);
11951
11952 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11953 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11954 pipeline_layout_ci.pNext = NULL;
11955 pipeline_layout_ci.setLayoutCount = 1;
11956 pipeline_layout_ci.pSetLayouts = &ds_layout;
11957 VkPipelineLayout pipeline_layout;
11958 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11959 ASSERT_VK_SUCCESS(err);
11960
11961 VkImageObj image(m_device);
11962 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11963 ASSERT_TRUE(image.initialized());
11964 VkImageView view = image.targetView(tex_format);
11965
11966 VkDescriptorImageInfo image_info = {};
11967 image_info.imageView = view;
11968 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11969
11970 VkWriteDescriptorSet descriptor_write = {};
11971 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11972 descriptor_write.dstSet = descriptor_set;
11973 descriptor_write.dstBinding = 0;
11974 descriptor_write.descriptorCount = 1;
11975 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11976 descriptor_write.pImageInfo = &image_info;
11977
11978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11979 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11980 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11981 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11982 m_errorMonitor->VerifyFound();
11983
11984 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11985 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11986 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11987 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11988}
11989
Mark Mueller93b938f2016-08-18 10:27:40 -060011990TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011991 TEST_DESCRIPTION(
11992 "Use vkCmdExecuteCommands with invalid state "
11993 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011994
11995 ASSERT_NO_FATAL_FAILURE(InitState());
11996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11997
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011998 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011999 const char *simultaneous_use_message2 =
12000 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12001 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012002
12003 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012004 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012005 command_buffer_allocate_info.commandPool = m_commandPool;
12006 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12007 command_buffer_allocate_info.commandBufferCount = 1;
12008
12009 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012010 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012011 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12012 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012013 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012014 command_buffer_inheritance_info.renderPass = m_renderPass;
12015 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012016
Mark Mueller93b938f2016-08-18 10:27:40 -060012017 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012018 command_buffer_begin_info.flags =
12019 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012020 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12021
12022 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12023 vkEndCommandBuffer(secondary_command_buffer);
12024
Mark Mueller93b938f2016-08-18 10:27:40 -060012025 VkSubmitInfo submit_info = {};
12026 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12027 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012028 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012029
Mark Mueller4042b652016-09-05 22:52:21 -060012030 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012031 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12033 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012034 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012035 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012036 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12037 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012038
Dave Houltonfbf52152017-01-06 12:55:29 -070012039 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012040 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012041 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012042
Mark Mueller4042b652016-09-05 22:52:21 -060012043 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012044 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12045 m_errorMonitor->SetUnexpectedError(
12046 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12047 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012048 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012049 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012050
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12052 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012053 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012054 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12055 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012056
12057 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012058
12059 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012060}
12061
Tony Barbour626994c2017-02-08 15:29:37 -070012062TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12063 TEST_DESCRIPTION(
12064 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12065 "errors");
12066 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12067 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12068 ASSERT_NO_FATAL_FAILURE(InitState());
12069
12070 VkCommandBuffer cmd_bufs[2];
12071 VkCommandBufferAllocateInfo alloc_info;
12072 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12073 alloc_info.pNext = NULL;
12074 alloc_info.commandBufferCount = 2;
12075 alloc_info.commandPool = m_commandPool;
12076 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12077 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12078
12079 VkCommandBufferBeginInfo cb_binfo;
12080 cb_binfo.pNext = NULL;
12081 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12082 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12083 cb_binfo.flags = 0;
12084 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12085 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12086 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12087 vkEndCommandBuffer(cmd_bufs[0]);
12088 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12089
12090 VkSubmitInfo submit_info = {};
12091 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12092 submit_info.commandBufferCount = 2;
12093 submit_info.pCommandBuffers = duplicates;
12094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12095 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12096 m_errorMonitor->VerifyFound();
12097 vkQueueWaitIdle(m_device->m_queue);
12098
12099 // Set one time use and now look for one time submit
12100 duplicates[0] = duplicates[1] = cmd_bufs[1];
12101 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12102 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12103 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12104 vkEndCommandBuffer(cmd_bufs[1]);
12105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12106 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12107 m_errorMonitor->VerifyFound();
12108 vkQueueWaitIdle(m_device->m_queue);
12109}
12110
Tobin Ehlisb093da82017-01-19 12:05:27 -070012111TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012112 TEST_DESCRIPTION(
12113 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12114 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012115
12116 ASSERT_NO_FATAL_FAILURE(InitState());
12117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12118
12119 std::vector<const char *> device_extension_names;
12120 auto features = m_device->phy().features();
12121 // Make sure gs & ts are disabled
12122 features.geometryShader = false;
12123 features.tessellationShader = false;
12124 // The sacrificial device object
12125 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12126
12127 VkCommandPoolCreateInfo pool_create_info{};
12128 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12129 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12130
12131 VkCommandPool command_pool;
12132 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12133
12134 VkCommandBufferAllocateInfo cmd = {};
12135 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12136 cmd.pNext = NULL;
12137 cmd.commandPool = command_pool;
12138 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12139 cmd.commandBufferCount = 1;
12140
12141 VkCommandBuffer cmd_buffer;
12142 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12143 ASSERT_VK_SUCCESS(err);
12144
12145 VkEvent event;
12146 VkEventCreateInfo evci = {};
12147 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12148 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12149 ASSERT_VK_SUCCESS(result);
12150
12151 VkCommandBufferBeginInfo cbbi = {};
12152 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12153 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12155 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12156 m_errorMonitor->VerifyFound();
12157
12158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12159 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12160 m_errorMonitor->VerifyFound();
12161
12162 vkDestroyEvent(test_device.handle(), event, NULL);
12163 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12164}
12165
Mark Mueller917f6bc2016-08-30 10:57:19 -060012166TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012167 TEST_DESCRIPTION(
12168 "Use vkCmdExecuteCommands with invalid state "
12169 "in primary and secondary command buffers. "
12170 "Delete objects that are inuse. Call VkQueueSubmit "
12171 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012172
12173 ASSERT_NO_FATAL_FAILURE(InitState());
12174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12175
Tony Barbour552f6c02016-12-21 14:34:07 -070012176 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012177
12178 VkEvent event;
12179 VkEventCreateInfo event_create_info = {};
12180 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12181 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012182 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012183
Tony Barbour552f6c02016-12-21 14:34:07 -070012184 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012185 vkDestroyEvent(m_device->device(), event, nullptr);
12186
12187 VkSubmitInfo submit_info = {};
12188 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12189 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012190 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070012191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012193 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12194 m_errorMonitor->VerifyFound();
12195
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012196 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012197 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12198
12199 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12200
Mark Mueller917f6bc2016-08-30 10:57:19 -060012201 VkSemaphoreCreateInfo semaphore_create_info = {};
12202 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12203 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012204 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012205 VkFenceCreateInfo fence_create_info = {};
12206 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12207 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012208 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012209
12210 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012211 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012212 descriptor_pool_type_count.descriptorCount = 1;
12213
12214 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12215 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12216 descriptor_pool_create_info.maxSets = 1;
12217 descriptor_pool_create_info.poolSizeCount = 1;
12218 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012219 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012220
12221 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012222 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012223
12224 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012225 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012226 descriptorset_layout_binding.descriptorCount = 1;
12227 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12228
12229 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012230 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012231 descriptorset_layout_create_info.bindingCount = 1;
12232 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12233
12234 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012235 ASSERT_VK_SUCCESS(
12236 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012237
12238 VkDescriptorSet descriptorset;
12239 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012240 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012241 descriptorset_allocate_info.descriptorSetCount = 1;
12242 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12243 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012244 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012245
Mark Mueller4042b652016-09-05 22:52:21 -060012246 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12247
12248 VkDescriptorBufferInfo buffer_info = {};
12249 buffer_info.buffer = buffer_test.GetBuffer();
12250 buffer_info.offset = 0;
12251 buffer_info.range = 1024;
12252
12253 VkWriteDescriptorSet write_descriptor_set = {};
12254 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12255 write_descriptor_set.dstSet = descriptorset;
12256 write_descriptor_set.descriptorCount = 1;
12257 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12258 write_descriptor_set.pBufferInfo = &buffer_info;
12259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012260 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012262 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12263 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012264
12265 VkPipelineObj pipe(m_device);
12266 pipe.AddColorAttachment();
12267 pipe.AddShader(&vs);
12268 pipe.AddShader(&fs);
12269
12270 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012271 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012272 pipeline_layout_create_info.setLayoutCount = 1;
12273 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12274
12275 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012276 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012277
12278 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12279
Tony Barbour552f6c02016-12-21 14:34:07 -070012280 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012281 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012283 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12284 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12285 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012286
Tony Barbour552f6c02016-12-21 14:34:07 -070012287 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012288
Mark Mueller917f6bc2016-08-30 10:57:19 -060012289 submit_info.signalSemaphoreCount = 1;
12290 submit_info.pSignalSemaphores = &semaphore;
12291 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012292 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012293
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012295 vkDestroyEvent(m_device->device(), event, nullptr);
12296 m_errorMonitor->VerifyFound();
12297
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012299 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12300 m_errorMonitor->VerifyFound();
12301
Jeremy Hayes08369882017-02-02 10:31:06 -070012302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012303 vkDestroyFence(m_device->device(), fence, nullptr);
12304 m_errorMonitor->VerifyFound();
12305
Tobin Ehlis122207b2016-09-01 08:50:06 -070012306 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012307 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12308 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012309 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012310 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12311 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012312 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012313 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12314 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012315 vkDestroyEvent(m_device->device(), event, nullptr);
12316 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012317 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012318 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12319}
12320
Tobin Ehlis2adda372016-09-01 08:51:06 -070012321TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12322 TEST_DESCRIPTION("Delete in-use query pool.");
12323
12324 ASSERT_NO_FATAL_FAILURE(InitState());
12325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12326
12327 VkQueryPool query_pool;
12328 VkQueryPoolCreateInfo query_pool_ci{};
12329 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12330 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12331 query_pool_ci.queryCount = 1;
12332 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012333 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012334 // Reset query pool to create binding with cmd buffer
12335 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12336
Tony Barbour552f6c02016-12-21 14:34:07 -070012337 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012338
12339 VkSubmitInfo submit_info = {};
12340 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12341 submit_info.commandBufferCount = 1;
12342 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12343 // Submit cmd buffer and then destroy query pool while in-flight
12344 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12345
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012347 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12348 m_errorMonitor->VerifyFound();
12349
12350 vkQueueWaitIdle(m_device->m_queue);
12351 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012352 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12353 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012354 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12355}
12356
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012357TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12358 TEST_DESCRIPTION("Delete in-use pipeline.");
12359
12360 ASSERT_NO_FATAL_FAILURE(InitState());
12361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12362
12363 // Empty pipeline layout used for binding PSO
12364 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12365 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12366 pipeline_layout_ci.setLayoutCount = 0;
12367 pipeline_layout_ci.pSetLayouts = NULL;
12368
12369 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012370 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012371 ASSERT_VK_SUCCESS(err);
12372
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012374 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012375 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12376 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012377 // Store pipeline handle so we can actually delete it before test finishes
12378 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012379 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012380 VkPipelineObj pipe(m_device);
12381 pipe.AddShader(&vs);
12382 pipe.AddShader(&fs);
12383 pipe.AddColorAttachment();
12384 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12385 delete_this_pipeline = pipe.handle();
12386
Tony Barbour552f6c02016-12-21 14:34:07 -070012387 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012388 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012389 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012390
Tony Barbour552f6c02016-12-21 14:34:07 -070012391 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012392
12393 VkSubmitInfo submit_info = {};
12394 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12395 submit_info.commandBufferCount = 1;
12396 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12397 // Submit cmd buffer and then pipeline destroyed while in-flight
12398 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012399 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012400 m_errorMonitor->VerifyFound();
12401 // Make sure queue finished and then actually delete pipeline
12402 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012403 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12404 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012405 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12406 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12407}
12408
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012409TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12410 TEST_DESCRIPTION("Delete in-use imageView.");
12411
12412 ASSERT_NO_FATAL_FAILURE(InitState());
12413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12414
12415 VkDescriptorPoolSize ds_type_count;
12416 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12417 ds_type_count.descriptorCount = 1;
12418
12419 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12420 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12421 ds_pool_ci.maxSets = 1;
12422 ds_pool_ci.poolSizeCount = 1;
12423 ds_pool_ci.pPoolSizes = &ds_type_count;
12424
12425 VkDescriptorPool ds_pool;
12426 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12427 ASSERT_VK_SUCCESS(err);
12428
12429 VkSamplerCreateInfo sampler_ci = {};
12430 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12431 sampler_ci.pNext = NULL;
12432 sampler_ci.magFilter = VK_FILTER_NEAREST;
12433 sampler_ci.minFilter = VK_FILTER_NEAREST;
12434 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12435 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12436 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12437 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12438 sampler_ci.mipLodBias = 1.0;
12439 sampler_ci.anisotropyEnable = VK_FALSE;
12440 sampler_ci.maxAnisotropy = 1;
12441 sampler_ci.compareEnable = VK_FALSE;
12442 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12443 sampler_ci.minLod = 1.0;
12444 sampler_ci.maxLod = 1.0;
12445 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12446 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12447 VkSampler sampler;
12448
12449 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12450 ASSERT_VK_SUCCESS(err);
12451
12452 VkDescriptorSetLayoutBinding layout_binding;
12453 layout_binding.binding = 0;
12454 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12455 layout_binding.descriptorCount = 1;
12456 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12457 layout_binding.pImmutableSamplers = NULL;
12458
12459 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12460 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12461 ds_layout_ci.bindingCount = 1;
12462 ds_layout_ci.pBindings = &layout_binding;
12463 VkDescriptorSetLayout ds_layout;
12464 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12465 ASSERT_VK_SUCCESS(err);
12466
12467 VkDescriptorSetAllocateInfo alloc_info = {};
12468 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12469 alloc_info.descriptorSetCount = 1;
12470 alloc_info.descriptorPool = ds_pool;
12471 alloc_info.pSetLayouts = &ds_layout;
12472 VkDescriptorSet descriptor_set;
12473 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12474 ASSERT_VK_SUCCESS(err);
12475
12476 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12477 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12478 pipeline_layout_ci.pNext = NULL;
12479 pipeline_layout_ci.setLayoutCount = 1;
12480 pipeline_layout_ci.pSetLayouts = &ds_layout;
12481
12482 VkPipelineLayout pipeline_layout;
12483 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12484 ASSERT_VK_SUCCESS(err);
12485
12486 VkImageObj image(m_device);
12487 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12488 ASSERT_TRUE(image.initialized());
12489
12490 VkImageView view;
12491 VkImageViewCreateInfo ivci = {};
12492 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12493 ivci.image = image.handle();
12494 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12495 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12496 ivci.subresourceRange.layerCount = 1;
12497 ivci.subresourceRange.baseMipLevel = 0;
12498 ivci.subresourceRange.levelCount = 1;
12499 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12500
12501 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12502 ASSERT_VK_SUCCESS(err);
12503
12504 VkDescriptorImageInfo image_info{};
12505 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12506 image_info.imageView = view;
12507 image_info.sampler = sampler;
12508
12509 VkWriteDescriptorSet descriptor_write = {};
12510 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12511 descriptor_write.dstSet = descriptor_set;
12512 descriptor_write.dstBinding = 0;
12513 descriptor_write.descriptorCount = 1;
12514 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12515 descriptor_write.pImageInfo = &image_info;
12516
12517 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12518
12519 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012520 char const *vsSource =
12521 "#version 450\n"
12522 "\n"
12523 "out gl_PerVertex { \n"
12524 " vec4 gl_Position;\n"
12525 "};\n"
12526 "void main(){\n"
12527 " gl_Position = vec4(1);\n"
12528 "}\n";
12529 char const *fsSource =
12530 "#version 450\n"
12531 "\n"
12532 "layout(set=0, binding=0) uniform sampler2D s;\n"
12533 "layout(location=0) out vec4 x;\n"
12534 "void main(){\n"
12535 " x = texture(s, vec2(1));\n"
12536 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012537 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12538 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12539 VkPipelineObj pipe(m_device);
12540 pipe.AddShader(&vs);
12541 pipe.AddShader(&fs);
12542 pipe.AddColorAttachment();
12543 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12544
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012546
Tony Barbour552f6c02016-12-21 14:34:07 -070012547 m_commandBuffer->BeginCommandBuffer();
12548 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012549 // Bind pipeline to cmd buffer
12550 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12551 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12552 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012553
12554 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12555 VkRect2D scissor = {{0, 0}, {16, 16}};
12556 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12557 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12558
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012559 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012560 m_commandBuffer->EndRenderPass();
12561 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012562 // Submit cmd buffer then destroy sampler
12563 VkSubmitInfo submit_info = {};
12564 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12565 submit_info.commandBufferCount = 1;
12566 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12567 // Submit cmd buffer and then destroy imageView while in-flight
12568 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12569
12570 vkDestroyImageView(m_device->device(), view, nullptr);
12571 m_errorMonitor->VerifyFound();
12572 vkQueueWaitIdle(m_device->m_queue);
12573 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012574 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12575 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012576 vkDestroyImageView(m_device->device(), view, NULL);
12577 vkDestroySampler(m_device->device(), sampler, nullptr);
12578 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12579 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12580 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12581}
12582
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012583TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12584 TEST_DESCRIPTION("Delete in-use bufferView.");
12585
12586 ASSERT_NO_FATAL_FAILURE(InitState());
12587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12588
12589 VkDescriptorPoolSize ds_type_count;
12590 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12591 ds_type_count.descriptorCount = 1;
12592
12593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12595 ds_pool_ci.maxSets = 1;
12596 ds_pool_ci.poolSizeCount = 1;
12597 ds_pool_ci.pPoolSizes = &ds_type_count;
12598
12599 VkDescriptorPool ds_pool;
12600 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12601 ASSERT_VK_SUCCESS(err);
12602
12603 VkDescriptorSetLayoutBinding layout_binding;
12604 layout_binding.binding = 0;
12605 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12606 layout_binding.descriptorCount = 1;
12607 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12608 layout_binding.pImmutableSamplers = NULL;
12609
12610 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12611 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12612 ds_layout_ci.bindingCount = 1;
12613 ds_layout_ci.pBindings = &layout_binding;
12614 VkDescriptorSetLayout ds_layout;
12615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12616 ASSERT_VK_SUCCESS(err);
12617
12618 VkDescriptorSetAllocateInfo alloc_info = {};
12619 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12620 alloc_info.descriptorSetCount = 1;
12621 alloc_info.descriptorPool = ds_pool;
12622 alloc_info.pSetLayouts = &ds_layout;
12623 VkDescriptorSet descriptor_set;
12624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12625 ASSERT_VK_SUCCESS(err);
12626
12627 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12628 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12629 pipeline_layout_ci.pNext = NULL;
12630 pipeline_layout_ci.setLayoutCount = 1;
12631 pipeline_layout_ci.pSetLayouts = &ds_layout;
12632
12633 VkPipelineLayout pipeline_layout;
12634 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12635 ASSERT_VK_SUCCESS(err);
12636
12637 VkBuffer buffer;
12638 uint32_t queue_family_index = 0;
12639 VkBufferCreateInfo buffer_create_info = {};
12640 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12641 buffer_create_info.size = 1024;
12642 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12643 buffer_create_info.queueFamilyIndexCount = 1;
12644 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12645
12646 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12647 ASSERT_VK_SUCCESS(err);
12648
12649 VkMemoryRequirements memory_reqs;
12650 VkDeviceMemory buffer_memory;
12651
12652 VkMemoryAllocateInfo memory_info = {};
12653 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12654 memory_info.allocationSize = 0;
12655 memory_info.memoryTypeIndex = 0;
12656
12657 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12658 memory_info.allocationSize = memory_reqs.size;
12659 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12660 ASSERT_TRUE(pass);
12661
12662 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12663 ASSERT_VK_SUCCESS(err);
12664 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12665 ASSERT_VK_SUCCESS(err);
12666
12667 VkBufferView view;
12668 VkBufferViewCreateInfo bvci = {};
12669 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12670 bvci.buffer = buffer;
12671 bvci.format = VK_FORMAT_R8_UNORM;
12672 bvci.range = VK_WHOLE_SIZE;
12673
12674 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12675 ASSERT_VK_SUCCESS(err);
12676
12677 VkWriteDescriptorSet descriptor_write = {};
12678 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12679 descriptor_write.dstSet = descriptor_set;
12680 descriptor_write.dstBinding = 0;
12681 descriptor_write.descriptorCount = 1;
12682 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12683 descriptor_write.pTexelBufferView = &view;
12684
12685 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12686
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012687 char const *vsSource =
12688 "#version 450\n"
12689 "\n"
12690 "out gl_PerVertex { \n"
12691 " vec4 gl_Position;\n"
12692 "};\n"
12693 "void main(){\n"
12694 " gl_Position = vec4(1);\n"
12695 "}\n";
12696 char const *fsSource =
12697 "#version 450\n"
12698 "\n"
12699 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12700 "layout(location=0) out vec4 x;\n"
12701 "void main(){\n"
12702 " x = imageLoad(s, 0);\n"
12703 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012704 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12705 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12706 VkPipelineObj pipe(m_device);
12707 pipe.AddShader(&vs);
12708 pipe.AddShader(&fs);
12709 pipe.AddColorAttachment();
12710 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12711
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012713
Tony Barbour552f6c02016-12-21 14:34:07 -070012714 m_commandBuffer->BeginCommandBuffer();
12715 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012716 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12717 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12718 VkRect2D scissor = {{0, 0}, {16, 16}};
12719 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12720 // Bind pipeline to cmd buffer
12721 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12722 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12723 &descriptor_set, 0, nullptr);
12724 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012725 m_commandBuffer->EndRenderPass();
12726 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012727
12728 VkSubmitInfo submit_info = {};
12729 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12730 submit_info.commandBufferCount = 1;
12731 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12732 // Submit cmd buffer and then destroy bufferView while in-flight
12733 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12734
12735 vkDestroyBufferView(m_device->device(), view, nullptr);
12736 m_errorMonitor->VerifyFound();
12737 vkQueueWaitIdle(m_device->m_queue);
12738 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012739 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12740 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012741 vkDestroyBufferView(m_device->device(), view, NULL);
12742 vkDestroyBuffer(m_device->device(), buffer, NULL);
12743 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12744 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12746 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12747}
12748
Tobin Ehlis209532e2016-09-07 13:52:18 -060012749TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12750 TEST_DESCRIPTION("Delete in-use sampler.");
12751
12752 ASSERT_NO_FATAL_FAILURE(InitState());
12753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12754
12755 VkDescriptorPoolSize ds_type_count;
12756 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12757 ds_type_count.descriptorCount = 1;
12758
12759 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12760 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12761 ds_pool_ci.maxSets = 1;
12762 ds_pool_ci.poolSizeCount = 1;
12763 ds_pool_ci.pPoolSizes = &ds_type_count;
12764
12765 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012766 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012767 ASSERT_VK_SUCCESS(err);
12768
12769 VkSamplerCreateInfo sampler_ci = {};
12770 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12771 sampler_ci.pNext = NULL;
12772 sampler_ci.magFilter = VK_FILTER_NEAREST;
12773 sampler_ci.minFilter = VK_FILTER_NEAREST;
12774 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12775 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12776 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12777 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12778 sampler_ci.mipLodBias = 1.0;
12779 sampler_ci.anisotropyEnable = VK_FALSE;
12780 sampler_ci.maxAnisotropy = 1;
12781 sampler_ci.compareEnable = VK_FALSE;
12782 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12783 sampler_ci.minLod = 1.0;
12784 sampler_ci.maxLod = 1.0;
12785 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12786 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12787 VkSampler sampler;
12788
12789 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12790 ASSERT_VK_SUCCESS(err);
12791
12792 VkDescriptorSetLayoutBinding layout_binding;
12793 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012794 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012795 layout_binding.descriptorCount = 1;
12796 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12797 layout_binding.pImmutableSamplers = NULL;
12798
12799 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12800 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12801 ds_layout_ci.bindingCount = 1;
12802 ds_layout_ci.pBindings = &layout_binding;
12803 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012804 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012805 ASSERT_VK_SUCCESS(err);
12806
12807 VkDescriptorSetAllocateInfo alloc_info = {};
12808 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12809 alloc_info.descriptorSetCount = 1;
12810 alloc_info.descriptorPool = ds_pool;
12811 alloc_info.pSetLayouts = &ds_layout;
12812 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012813 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012814 ASSERT_VK_SUCCESS(err);
12815
12816 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12817 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12818 pipeline_layout_ci.pNext = NULL;
12819 pipeline_layout_ci.setLayoutCount = 1;
12820 pipeline_layout_ci.pSetLayouts = &ds_layout;
12821
12822 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012823 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012824 ASSERT_VK_SUCCESS(err);
12825
12826 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012827 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 -060012828 ASSERT_TRUE(image.initialized());
12829
12830 VkImageView view;
12831 VkImageViewCreateInfo ivci = {};
12832 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12833 ivci.image = image.handle();
12834 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12835 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12836 ivci.subresourceRange.layerCount = 1;
12837 ivci.subresourceRange.baseMipLevel = 0;
12838 ivci.subresourceRange.levelCount = 1;
12839 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12840
12841 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12842 ASSERT_VK_SUCCESS(err);
12843
12844 VkDescriptorImageInfo image_info{};
12845 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12846 image_info.imageView = view;
12847 image_info.sampler = sampler;
12848
12849 VkWriteDescriptorSet descriptor_write = {};
12850 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12851 descriptor_write.dstSet = descriptor_set;
12852 descriptor_write.dstBinding = 0;
12853 descriptor_write.descriptorCount = 1;
12854 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12855 descriptor_write.pImageInfo = &image_info;
12856
12857 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12858
12859 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012860 char const *vsSource =
12861 "#version 450\n"
12862 "\n"
12863 "out gl_PerVertex { \n"
12864 " vec4 gl_Position;\n"
12865 "};\n"
12866 "void main(){\n"
12867 " gl_Position = vec4(1);\n"
12868 "}\n";
12869 char const *fsSource =
12870 "#version 450\n"
12871 "\n"
12872 "layout(set=0, binding=0) uniform sampler2D s;\n"
12873 "layout(location=0) out vec4 x;\n"
12874 "void main(){\n"
12875 " x = texture(s, vec2(1));\n"
12876 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012877 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12878 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12879 VkPipelineObj pipe(m_device);
12880 pipe.AddShader(&vs);
12881 pipe.AddShader(&fs);
12882 pipe.AddColorAttachment();
12883 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12884
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012886
Tony Barbour552f6c02016-12-21 14:34:07 -070012887 m_commandBuffer->BeginCommandBuffer();
12888 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012889 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012890 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12891 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12892 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012893
12894 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12895 VkRect2D scissor = {{0, 0}, {16, 16}};
12896 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12897 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12898
Tobin Ehlis209532e2016-09-07 13:52:18 -060012899 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012900 m_commandBuffer->EndRenderPass();
12901 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012902 // Submit cmd buffer then destroy sampler
12903 VkSubmitInfo submit_info = {};
12904 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12905 submit_info.commandBufferCount = 1;
12906 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12907 // Submit cmd buffer and then destroy sampler while in-flight
12908 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12909
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012910 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012911 m_errorMonitor->VerifyFound();
12912 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012913
Tobin Ehlis209532e2016-09-07 13:52:18 -060012914 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012915 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12916 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012917 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012918 vkDestroyImageView(m_device->device(), view, NULL);
12919 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12920 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12921 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12922}
12923
Mark Mueller1cd9f412016-08-25 13:23:52 -060012924TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012925 TEST_DESCRIPTION(
12926 "Call VkQueueSubmit with a semaphore that is already "
12927 "signaled but not waited on by the queue. Wait on a "
12928 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012929
12930 ASSERT_NO_FATAL_FAILURE(InitState());
12931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12932
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012933 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 -070012934 const char *invalid_fence_wait_message =
12935 " which has not been submitted on a Queue or during "
12936 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012937
Tony Barbour552f6c02016-12-21 14:34:07 -070012938 m_commandBuffer->BeginCommandBuffer();
12939 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012940
12941 VkSemaphoreCreateInfo semaphore_create_info = {};
12942 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12943 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012944 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012945 VkSubmitInfo submit_info = {};
12946 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12947 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012948 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012949 submit_info.signalSemaphoreCount = 1;
12950 submit_info.pSignalSemaphores = &semaphore;
12951 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012952 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012953 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012954 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012955 m_commandBuffer->BeginCommandBuffer();
12956 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12959 m_errorMonitor->VerifyFound();
12960
Mark Mueller1cd9f412016-08-25 13:23:52 -060012961 VkFenceCreateInfo fence_create_info = {};
12962 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12963 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012964 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012967 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12968 m_errorMonitor->VerifyFound();
12969
Mark Mueller4042b652016-09-05 22:52:21 -060012970 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012971 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012972 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12973}
12974
Tobin Ehlis4af23302016-07-19 10:50:30 -060012975TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012976 TEST_DESCRIPTION(
12977 "Bind a secondary command buffer with with a framebuffer "
12978 "that does not match the framebuffer for the active "
12979 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012980 ASSERT_NO_FATAL_FAILURE(InitState());
12981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12982
12983 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012984 VkAttachmentDescription attachment = {0,
12985 VK_FORMAT_B8G8R8A8_UNORM,
12986 VK_SAMPLE_COUNT_1_BIT,
12987 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12988 VK_ATTACHMENT_STORE_OP_STORE,
12989 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12990 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12991 VK_IMAGE_LAYOUT_UNDEFINED,
12992 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012994 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012996 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012997
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012998 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012999
13000 VkRenderPass rp;
13001 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13002 ASSERT_VK_SUCCESS(err);
13003
13004 // A compatible framebuffer.
13005 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013006 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 -060013007 ASSERT_TRUE(image.initialized());
13008
13009 VkImageViewCreateInfo ivci = {
13010 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13011 nullptr,
13012 0,
13013 image.handle(),
13014 VK_IMAGE_VIEW_TYPE_2D,
13015 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013016 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13017 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013018 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13019 };
13020 VkImageView view;
13021 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13022 ASSERT_VK_SUCCESS(err);
13023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013024 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013025 VkFramebuffer fb;
13026 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13027 ASSERT_VK_SUCCESS(err);
13028
13029 VkCommandBufferAllocateInfo cbai = {};
13030 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13031 cbai.commandPool = m_commandPool;
13032 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13033 cbai.commandBufferCount = 1;
13034
13035 VkCommandBuffer sec_cb;
13036 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13037 ASSERT_VK_SUCCESS(err);
13038 VkCommandBufferBeginInfo cbbi = {};
13039 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013040 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013041 cbii.renderPass = renderPass();
13042 cbii.framebuffer = fb;
13043 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13044 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013045 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 -060013046 cbbi.pInheritanceInfo = &cbii;
13047 vkBeginCommandBuffer(sec_cb, &cbbi);
13048 vkEndCommandBuffer(sec_cb);
13049
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013050 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013051 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13052 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013055 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013056 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13057 m_errorMonitor->VerifyFound();
13058 // Cleanup
13059 vkDestroyImageView(m_device->device(), view, NULL);
13060 vkDestroyRenderPass(m_device->device(), rp, NULL);
13061 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13062}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013063
13064TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013065 TEST_DESCRIPTION(
13066 "If logicOp is available on the device, set it to an "
13067 "invalid value. If logicOp is not available, attempt to "
13068 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013069 ASSERT_NO_FATAL_FAILURE(InitState());
13070 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13071
13072 auto features = m_device->phy().features();
13073 // Set the expected error depending on whether or not logicOp available
13074 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13076 "If logic operations feature not "
13077 "enabled, logicOpEnable must be "
13078 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013079 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013081 }
13082 // Create a pipeline using logicOp
13083 VkResult err;
13084
13085 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13086 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13087
13088 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013089 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013090 ASSERT_VK_SUCCESS(err);
13091
13092 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13093 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13094 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013095 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013096 vp_state_ci.pViewports = &vp;
13097 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013098 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013099 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013100
13101 VkPipelineShaderStageCreateInfo shaderStages[2];
13102 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013104 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13105 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013106 shaderStages[0] = vs.GetStageCreateInfo();
13107 shaderStages[1] = fs.GetStageCreateInfo();
13108
13109 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13110 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13111
13112 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13113 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13114 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13115
13116 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13117 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013118 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013119
13120 VkPipelineColorBlendAttachmentState att = {};
13121 att.blendEnable = VK_FALSE;
13122 att.colorWriteMask = 0xf;
13123
13124 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13125 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13126 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13127 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013128 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013129 cb_ci.attachmentCount = 1;
13130 cb_ci.pAttachments = &att;
13131
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013132 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13133 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13134 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13135
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013136 VkGraphicsPipelineCreateInfo gp_ci = {};
13137 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13138 gp_ci.stageCount = 2;
13139 gp_ci.pStages = shaderStages;
13140 gp_ci.pVertexInputState = &vi_ci;
13141 gp_ci.pInputAssemblyState = &ia_ci;
13142 gp_ci.pViewportState = &vp_state_ci;
13143 gp_ci.pRasterizationState = &rs_ci;
13144 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013145 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013146 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13147 gp_ci.layout = pipeline_layout;
13148 gp_ci.renderPass = renderPass();
13149
13150 VkPipelineCacheCreateInfo pc_ci = {};
13151 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13152
13153 VkPipeline pipeline;
13154 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013155 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013156 ASSERT_VK_SUCCESS(err);
13157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013158 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013159 m_errorMonitor->VerifyFound();
13160 if (VK_SUCCESS == err) {
13161 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13162 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013163 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13164 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13165}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013166
Mike Stroyanaccf7692015-05-12 16:00:45 -060013167#if GTEST_IS_THREADSAFE
13168struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013169 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013170 VkEvent event;
13171 bool bailout;
13172};
13173
Karl Schultz6addd812016-02-02 17:17:23 -070013174extern "C" void *AddToCommandBuffer(void *arg) {
13175 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013176
Mike Stroyana6d14942016-07-13 15:10:05 -060013177 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013178 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013179 if (data->bailout) {
13180 break;
13181 }
13182 }
13183 return NULL;
13184}
13185
Karl Schultz6addd812016-02-02 17:17:23 -070013186TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013187 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013190
Mike Stroyanaccf7692015-05-12 16:00:45 -060013191 ASSERT_NO_FATAL_FAILURE(InitState());
13192 ASSERT_NO_FATAL_FAILURE(InitViewport());
13193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13194
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013195 // Calls AllocateCommandBuffers
13196 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013197
13198 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013199 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013200
13201 VkEventCreateInfo event_info;
13202 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013203 VkResult err;
13204
13205 memset(&event_info, 0, sizeof(event_info));
13206 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13207
Chia-I Wuf7458c52015-10-26 21:10:41 +080013208 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013209 ASSERT_VK_SUCCESS(err);
13210
Mike Stroyanaccf7692015-05-12 16:00:45 -060013211 err = vkResetEvent(device(), event);
13212 ASSERT_VK_SUCCESS(err);
13213
13214 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013215 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013216 data.event = event;
13217 data.bailout = false;
13218 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013219
13220 // First do some correct operations using multiple threads.
13221 // Add many entries to command buffer from another thread.
13222 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13223 // Make non-conflicting calls from this thread at the same time.
13224 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013225 uint32_t count;
13226 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013227 }
13228 test_platform_thread_join(thread, NULL);
13229
13230 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013231 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013232 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013233 // Add many entries to command buffer from this thread at the same time.
13234 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013235
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013236 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013237 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013238
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013239 m_errorMonitor->SetBailout(NULL);
13240
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013241 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013242
Chia-I Wuf7458c52015-10-26 21:10:41 +080013243 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013244}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013245#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013246
Karl Schultz6addd812016-02-02 17:17:23 -070013247TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013248 TEST_DESCRIPTION(
13249 "Test that an error is produced for a spirv module "
13250 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013253
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013254 ASSERT_NO_FATAL_FAILURE(InitState());
13255 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13256
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013257 VkShaderModule module;
13258 VkShaderModuleCreateInfo moduleCreateInfo;
13259 struct icd_spv_header spv;
13260
13261 spv.magic = ICD_SPV_MAGIC;
13262 spv.version = ICD_SPV_VERSION;
13263 spv.gen_magic = 0;
13264
13265 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13266 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013267 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013268 moduleCreateInfo.codeSize = 4;
13269 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013270 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013271
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013272 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013273}
13274
Karl Schultz6addd812016-02-02 17:17:23 -070013275TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013276 TEST_DESCRIPTION(
13277 "Test that an error is produced for a spirv module "
13278 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013279
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013281
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013282 ASSERT_NO_FATAL_FAILURE(InitState());
13283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13284
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013285 VkShaderModule module;
13286 VkShaderModuleCreateInfo moduleCreateInfo;
13287 struct icd_spv_header spv;
13288
13289 spv.magic = ~ICD_SPV_MAGIC;
13290 spv.version = ICD_SPV_VERSION;
13291 spv.gen_magic = 0;
13292
13293 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13294 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013295 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013296 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13297 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013298 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013299
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013300 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013301}
13302
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013303#if 0
13304// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013305TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013307 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013308
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013309 ASSERT_NO_FATAL_FAILURE(InitState());
13310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13311
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013312 VkShaderModule module;
13313 VkShaderModuleCreateInfo moduleCreateInfo;
13314 struct icd_spv_header spv;
13315
13316 spv.magic = ICD_SPV_MAGIC;
13317 spv.version = ~ICD_SPV_VERSION;
13318 spv.gen_magic = 0;
13319
13320 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13321 moduleCreateInfo.pNext = NULL;
13322
Karl Schultz6addd812016-02-02 17:17:23 -070013323 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013324 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13325 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013326 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013327
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013328 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013329}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013330#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013331
Karl Schultz6addd812016-02-02 17:17:23 -070013332TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013333 TEST_DESCRIPTION(
13334 "Test that a warning is produced for a vertex output that "
13335 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013337
Chris Forbes9f7ff632015-05-25 11:13:08 +120013338 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013340
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013341 char const *vsSource =
13342 "#version 450\n"
13343 "\n"
13344 "layout(location=0) out float x;\n"
13345 "out gl_PerVertex {\n"
13346 " vec4 gl_Position;\n"
13347 "};\n"
13348 "void main(){\n"
13349 " gl_Position = vec4(1);\n"
13350 " x = 0;\n"
13351 "}\n";
13352 char const *fsSource =
13353 "#version 450\n"
13354 "\n"
13355 "layout(location=0) out vec4 color;\n"
13356 "void main(){\n"
13357 " color = vec4(1);\n"
13358 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013359
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013360 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13361 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013362
13363 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013364 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013365 pipe.AddShader(&vs);
13366 pipe.AddShader(&fs);
13367
Chris Forbes9f7ff632015-05-25 11:13:08 +120013368 VkDescriptorSetObj descriptorSet(m_device);
13369 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013370 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013371
Tony Barbour5781e8f2015-08-04 16:23:11 -060013372 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013373
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013374 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013375}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013376
Mark Mueller098c9cb2016-09-08 09:01:57 -060013377TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13378 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13379
13380 ASSERT_NO_FATAL_FAILURE(InitState());
13381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13382
13383 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013384 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013385
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013386 char const *vsSource =
13387 "#version 450\n"
13388 "\n"
13389 "out gl_PerVertex {\n"
13390 " vec4 gl_Position;\n"
13391 "};\n"
13392 "void main(){\n"
13393 " gl_Position = vec4(1);\n"
13394 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013395
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013396 char const *fsSource =
13397 "#version 450\n"
13398 "\n"
13399 "layout (constant_id = 0) const float r = 0.0f;\n"
13400 "layout(location = 0) out vec4 uFragColor;\n"
13401 "void main(){\n"
13402 " uFragColor = vec4(r,1,0,1);\n"
13403 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013404
13405 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13406 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13407
13408 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13409 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13410
13411 VkPipelineLayout pipeline_layout;
13412 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13413
13414 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13415 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13416 vp_state_create_info.viewportCount = 1;
13417 VkViewport viewport = {};
13418 vp_state_create_info.pViewports = &viewport;
13419 vp_state_create_info.scissorCount = 1;
13420 VkRect2D scissors = {};
13421 vp_state_create_info.pScissors = &scissors;
13422
13423 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13424
13425 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13426 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13427 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13428 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13429
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013430 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013431
13432 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13433 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13434
13435 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13436 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13437 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13438
13439 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13440 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13441 rasterization_state_create_info.pNext = nullptr;
13442 rasterization_state_create_info.lineWidth = 1.0f;
13443 rasterization_state_create_info.rasterizerDiscardEnable = true;
13444
13445 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13446 color_blend_attachment_state.blendEnable = VK_FALSE;
13447 color_blend_attachment_state.colorWriteMask = 0xf;
13448
13449 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13450 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13451 color_blend_state_create_info.attachmentCount = 1;
13452 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13453
13454 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13455 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13456 graphicspipe_create_info.stageCount = 2;
13457 graphicspipe_create_info.pStages = shader_stage_create_info;
13458 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13459 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13460 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13461 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13462 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13463 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13464 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13465 graphicspipe_create_info.layout = pipeline_layout;
13466 graphicspipe_create_info.renderPass = renderPass();
13467
13468 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13469 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13470
13471 VkPipelineCache pipelineCache;
13472 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13473
13474 // This structure maps constant ids to data locations.
13475 const VkSpecializationMapEntry entry =
13476 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013477 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013478
13479 uint32_t data = 1;
13480
13481 // Set up the info describing spec map and data
13482 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013483 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013484 };
13485 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13486
13487 VkPipeline pipeline;
13488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13489 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13490 m_errorMonitor->VerifyFound();
13491
13492 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13493 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13494}
13495
13496TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13497 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13498
13499 ASSERT_NO_FATAL_FAILURE(InitState());
13500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13501
13502 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13503
13504 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13505 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13506 descriptor_pool_type_count[0].descriptorCount = 1;
13507 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13508 descriptor_pool_type_count[1].descriptorCount = 1;
13509
13510 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13511 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13512 descriptor_pool_create_info.maxSets = 1;
13513 descriptor_pool_create_info.poolSizeCount = 2;
13514 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13515 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13516
13517 VkDescriptorPool descriptorset_pool;
13518 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13519
13520 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13521 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13522 descriptorset_layout_binding.descriptorCount = 1;
13523 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13524
13525 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13526 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13527 descriptorset_layout_create_info.bindingCount = 1;
13528 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13529
13530 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013531 ASSERT_VK_SUCCESS(
13532 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013533
13534 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13535 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13536 descriptorset_allocate_info.descriptorSetCount = 1;
13537 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13538 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13539 VkDescriptorSet descriptorset;
13540 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13541
13542 // Challenge core_validation with a non uniform buffer type.
13543 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13544
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013545 char const *vsSource =
13546 "#version 450\n"
13547 "\n"
13548 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13549 " mat4 mvp;\n"
13550 "} ubuf;\n"
13551 "out gl_PerVertex {\n"
13552 " vec4 gl_Position;\n"
13553 "};\n"
13554 "void main(){\n"
13555 " gl_Position = ubuf.mvp * vec4(1);\n"
13556 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013557
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013558 char const *fsSource =
13559 "#version 450\n"
13560 "\n"
13561 "layout(location = 0) out vec4 uFragColor;\n"
13562 "void main(){\n"
13563 " uFragColor = vec4(0,1,0,1);\n"
13564 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013565
13566 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13567 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13568
13569 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13570 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13571 pipeline_layout_create_info.setLayoutCount = 1;
13572 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13573
13574 VkPipelineLayout pipeline_layout;
13575 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13576
13577 VkPipelineObj pipe(m_device);
13578 pipe.AddColorAttachment();
13579 pipe.AddShader(&vs);
13580 pipe.AddShader(&fs);
13581
13582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13583 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13584 m_errorMonitor->VerifyFound();
13585
13586 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13587 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13588 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13589}
13590
13591TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13592 TEST_DESCRIPTION(
13593 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13594
13595 ASSERT_NO_FATAL_FAILURE(InitState());
13596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13597
13598 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13599
13600 VkDescriptorPoolSize descriptor_pool_type_count = {};
13601 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13602 descriptor_pool_type_count.descriptorCount = 1;
13603
13604 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13605 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13606 descriptor_pool_create_info.maxSets = 1;
13607 descriptor_pool_create_info.poolSizeCount = 1;
13608 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13609 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13610
13611 VkDescriptorPool descriptorset_pool;
13612 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13613
13614 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13615 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13616 descriptorset_layout_binding.descriptorCount = 1;
13617 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13618 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13619
13620 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13621 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13622 descriptorset_layout_create_info.bindingCount = 1;
13623 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13624
13625 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013626 ASSERT_VK_SUCCESS(
13627 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013628
13629 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13630 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13631 descriptorset_allocate_info.descriptorSetCount = 1;
13632 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13633 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13634 VkDescriptorSet descriptorset;
13635 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13636
13637 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13638
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013639 char const *vsSource =
13640 "#version 450\n"
13641 "\n"
13642 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13643 " mat4 mvp;\n"
13644 "} ubuf;\n"
13645 "out gl_PerVertex {\n"
13646 " vec4 gl_Position;\n"
13647 "};\n"
13648 "void main(){\n"
13649 " gl_Position = ubuf.mvp * vec4(1);\n"
13650 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013651
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013652 char const *fsSource =
13653 "#version 450\n"
13654 "\n"
13655 "layout(location = 0) out vec4 uFragColor;\n"
13656 "void main(){\n"
13657 " uFragColor = vec4(0,1,0,1);\n"
13658 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013659
13660 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13661 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13662
13663 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13664 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13665 pipeline_layout_create_info.setLayoutCount = 1;
13666 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13667
13668 VkPipelineLayout pipeline_layout;
13669 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13670
13671 VkPipelineObj pipe(m_device);
13672 pipe.AddColorAttachment();
13673 pipe.AddShader(&vs);
13674 pipe.AddShader(&fs);
13675
13676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13677 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13678 m_errorMonitor->VerifyFound();
13679
13680 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13681 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13682 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13683}
13684
13685TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013686 TEST_DESCRIPTION(
13687 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13688 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013689
13690 ASSERT_NO_FATAL_FAILURE(InitState());
13691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13692
13693 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013694 "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 -060013695
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013696 char const *vsSource =
13697 "#version 450\n"
13698 "\n"
13699 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13700 "out gl_PerVertex {\n"
13701 " vec4 gl_Position;\n"
13702 "};\n"
13703 "void main(){\n"
13704 " gl_Position = vec4(consts.x);\n"
13705 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013706
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013707 char const *fsSource =
13708 "#version 450\n"
13709 "\n"
13710 "layout(location = 0) out vec4 uFragColor;\n"
13711 "void main(){\n"
13712 " uFragColor = vec4(0,1,0,1);\n"
13713 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013714
13715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13717
13718 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13719 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13720
13721 // Set up a push constant range
13722 VkPushConstantRange push_constant_ranges = {};
13723 // Set to the wrong stage to challenge core_validation
13724 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13725 push_constant_ranges.size = 4;
13726
13727 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13728 pipeline_layout_create_info.pushConstantRangeCount = 1;
13729
13730 VkPipelineLayout pipeline_layout;
13731 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13732
13733 VkPipelineObj pipe(m_device);
13734 pipe.AddColorAttachment();
13735 pipe.AddShader(&vs);
13736 pipe.AddShader(&fs);
13737
13738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13739 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13740 m_errorMonitor->VerifyFound();
13741
13742 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13743}
13744
13745TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13746 TEST_DESCRIPTION(
13747 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13748
13749 ASSERT_NO_FATAL_FAILURE(InitState());
13750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13751
13752 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013753 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013754
13755 // Some awkward steps are required to test with custom device features.
13756 std::vector<const char *> device_extension_names;
13757 auto features = m_device->phy().features();
13758 // Disable support for 64 bit floats
13759 features.shaderFloat64 = false;
13760 // The sacrificial device object
13761 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13762
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013763 char const *vsSource =
13764 "#version 450\n"
13765 "\n"
13766 "out gl_PerVertex {\n"
13767 " vec4 gl_Position;\n"
13768 "};\n"
13769 "void main(){\n"
13770 " gl_Position = vec4(1);\n"
13771 "}\n";
13772 char const *fsSource =
13773 "#version 450\n"
13774 "\n"
13775 "layout(location=0) out vec4 color;\n"
13776 "void main(){\n"
13777 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13778 " color = vec4(green);\n"
13779 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013780
13781 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13782 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13783
13784 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013785
13786 VkPipelineObj pipe(&test_device);
13787 pipe.AddColorAttachment();
13788 pipe.AddShader(&vs);
13789 pipe.AddShader(&fs);
13790
13791 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13792 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13793 VkPipelineLayout pipeline_layout;
13794 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13795
13796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13797 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13798 m_errorMonitor->VerifyFound();
13799
13800 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13801}
13802
13803TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13804 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13805
13806 ASSERT_NO_FATAL_FAILURE(InitState());
13807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13808
13809 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13810
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013811 char const *vsSource =
13812 "#version 450\n"
13813 "\n"
13814 "out gl_PerVertex {\n"
13815 " vec4 gl_Position;\n"
13816 "};\n"
13817 "layout(xfb_buffer = 1) out;"
13818 "void main(){\n"
13819 " gl_Position = vec4(1);\n"
13820 "}\n";
13821 char const *fsSource =
13822 "#version 450\n"
13823 "\n"
13824 "layout(location=0) out vec4 color;\n"
13825 "void main(){\n"
13826 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13827 " color = vec4(green);\n"
13828 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013829
13830 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13831 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13832
13833 VkPipelineObj pipe(m_device);
13834 pipe.AddColorAttachment();
13835 pipe.AddShader(&vs);
13836 pipe.AddShader(&fs);
13837
13838 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13839 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13840 VkPipelineLayout pipeline_layout;
13841 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13842
13843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13844 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13845 m_errorMonitor->VerifyFound();
13846
13847 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13848}
13849
Karl Schultz6addd812016-02-02 17:17:23 -070013850TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013851 TEST_DESCRIPTION(
13852 "Test that an error is produced for a fragment shader input "
13853 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013854
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013856
Chris Forbes59cb88d2015-05-25 11:13:13 +120013857 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013859
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013860 char const *vsSource =
13861 "#version 450\n"
13862 "\n"
13863 "out gl_PerVertex {\n"
13864 " vec4 gl_Position;\n"
13865 "};\n"
13866 "void main(){\n"
13867 " gl_Position = vec4(1);\n"
13868 "}\n";
13869 char const *fsSource =
13870 "#version 450\n"
13871 "\n"
13872 "layout(location=0) in float x;\n"
13873 "layout(location=0) out vec4 color;\n"
13874 "void main(){\n"
13875 " color = vec4(x);\n"
13876 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013877
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013878 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13879 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013880
13881 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013882 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013883 pipe.AddShader(&vs);
13884 pipe.AddShader(&fs);
13885
Chris Forbes59cb88d2015-05-25 11:13:13 +120013886 VkDescriptorSetObj descriptorSet(m_device);
13887 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013888 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013889
Tony Barbour5781e8f2015-08-04 16:23:11 -060013890 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013891
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013892 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013893}
13894
Karl Schultz6addd812016-02-02 17:17:23 -070013895TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013896 TEST_DESCRIPTION(
13897 "Test that an error is produced for a fragment shader input "
13898 "within an interace block, which is not present in the outputs "
13899 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013901
13902 ASSERT_NO_FATAL_FAILURE(InitState());
13903 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13904
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013905 char const *vsSource =
13906 "#version 450\n"
13907 "\n"
13908 "out gl_PerVertex {\n"
13909 " vec4 gl_Position;\n"
13910 "};\n"
13911 "void main(){\n"
13912 " gl_Position = vec4(1);\n"
13913 "}\n";
13914 char const *fsSource =
13915 "#version 450\n"
13916 "\n"
13917 "in block { layout(location=0) float x; } ins;\n"
13918 "layout(location=0) out vec4 color;\n"
13919 "void main(){\n"
13920 " color = vec4(ins.x);\n"
13921 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013922
13923 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13924 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13925
13926 VkPipelineObj pipe(m_device);
13927 pipe.AddColorAttachment();
13928 pipe.AddShader(&vs);
13929 pipe.AddShader(&fs);
13930
13931 VkDescriptorSetObj descriptorSet(m_device);
13932 descriptorSet.AppendDummy();
13933 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13934
13935 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13936
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013937 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013938}
13939
Karl Schultz6addd812016-02-02 17:17:23 -070013940TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013941 TEST_DESCRIPTION(
13942 "Test that an error is produced for mismatched array sizes "
13943 "across the vertex->fragment shader interface");
13944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13945 "Type mismatch on location 0.0: 'ptr to "
13946 "output arr[2] of float32' vs 'ptr to "
13947 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013948
13949 ASSERT_NO_FATAL_FAILURE(InitState());
13950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13951
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013952 char const *vsSource =
13953 "#version 450\n"
13954 "\n"
13955 "layout(location=0) out float x[2];\n"
13956 "out gl_PerVertex {\n"
13957 " vec4 gl_Position;\n"
13958 "};\n"
13959 "void main(){\n"
13960 " x[0] = 0; x[1] = 0;\n"
13961 " gl_Position = vec4(1);\n"
13962 "}\n";
13963 char const *fsSource =
13964 "#version 450\n"
13965 "\n"
13966 "layout(location=0) in float x[1];\n"
13967 "layout(location=0) out vec4 color;\n"
13968 "void main(){\n"
13969 " color = vec4(x[0]);\n"
13970 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013971
13972 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13973 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13974
13975 VkPipelineObj pipe(m_device);
13976 pipe.AddColorAttachment();
13977 pipe.AddShader(&vs);
13978 pipe.AddShader(&fs);
13979
13980 VkDescriptorSetObj descriptorSet(m_device);
13981 descriptorSet.AppendDummy();
13982 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13983
13984 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13985
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013986 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013987}
13988
Karl Schultz6addd812016-02-02 17:17:23 -070013989TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013990 TEST_DESCRIPTION(
13991 "Test that an error is produced for mismatched types across "
13992 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013994
Chris Forbesb56af562015-05-25 11:13:17 +120013995 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013997
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013998 char const *vsSource =
13999 "#version 450\n"
14000 "\n"
14001 "layout(location=0) out int x;\n"
14002 "out gl_PerVertex {\n"
14003 " vec4 gl_Position;\n"
14004 "};\n"
14005 "void main(){\n"
14006 " x = 0;\n"
14007 " gl_Position = vec4(1);\n"
14008 "}\n";
14009 char const *fsSource =
14010 "#version 450\n"
14011 "\n"
14012 "layout(location=0) in float x;\n" /* VS writes int */
14013 "layout(location=0) out vec4 color;\n"
14014 "void main(){\n"
14015 " color = vec4(x);\n"
14016 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014017
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014018 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14019 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014020
14021 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014022 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014023 pipe.AddShader(&vs);
14024 pipe.AddShader(&fs);
14025
Chris Forbesb56af562015-05-25 11:13:17 +120014026 VkDescriptorSetObj descriptorSet(m_device);
14027 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014028 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014029
Tony Barbour5781e8f2015-08-04 16:23:11 -060014030 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014031
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014032 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014033}
14034
Karl Schultz6addd812016-02-02 17:17:23 -070014035TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014036 TEST_DESCRIPTION(
14037 "Test that an error is produced for mismatched types across "
14038 "the vertex->fragment shader interface, when the variable is contained within "
14039 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014041
14042 ASSERT_NO_FATAL_FAILURE(InitState());
14043 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14044
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014045 char const *vsSource =
14046 "#version 450\n"
14047 "\n"
14048 "out block { layout(location=0) int x; } outs;\n"
14049 "out gl_PerVertex {\n"
14050 " vec4 gl_Position;\n"
14051 "};\n"
14052 "void main(){\n"
14053 " outs.x = 0;\n"
14054 " gl_Position = vec4(1);\n"
14055 "}\n";
14056 char const *fsSource =
14057 "#version 450\n"
14058 "\n"
14059 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14060 "layout(location=0) out vec4 color;\n"
14061 "void main(){\n"
14062 " color = vec4(ins.x);\n"
14063 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014064
14065 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14066 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14067
14068 VkPipelineObj pipe(m_device);
14069 pipe.AddColorAttachment();
14070 pipe.AddShader(&vs);
14071 pipe.AddShader(&fs);
14072
14073 VkDescriptorSetObj descriptorSet(m_device);
14074 descriptorSet.AppendDummy();
14075 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14076
14077 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14078
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014079 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014080}
14081
14082TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014083 TEST_DESCRIPTION(
14084 "Test that an error is produced for location mismatches across "
14085 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14086 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014087 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 +130014088
14089 ASSERT_NO_FATAL_FAILURE(InitState());
14090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14091
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014092 char const *vsSource =
14093 "#version 450\n"
14094 "\n"
14095 "out block { layout(location=1) float x; } outs;\n"
14096 "out gl_PerVertex {\n"
14097 " vec4 gl_Position;\n"
14098 "};\n"
14099 "void main(){\n"
14100 " outs.x = 0;\n"
14101 " gl_Position = vec4(1);\n"
14102 "}\n";
14103 char const *fsSource =
14104 "#version 450\n"
14105 "\n"
14106 "in block { layout(location=0) float x; } ins;\n"
14107 "layout(location=0) out vec4 color;\n"
14108 "void main(){\n"
14109 " color = vec4(ins.x);\n"
14110 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014111
14112 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14113 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14114
14115 VkPipelineObj pipe(m_device);
14116 pipe.AddColorAttachment();
14117 pipe.AddShader(&vs);
14118 pipe.AddShader(&fs);
14119
14120 VkDescriptorSetObj descriptorSet(m_device);
14121 descriptorSet.AppendDummy();
14122 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14123
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014124 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014125 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14126
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014127 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014128}
14129
14130TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014131 TEST_DESCRIPTION(
14132 "Test that an error is produced for component mismatches across the "
14133 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14134 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014135 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 +130014136
14137 ASSERT_NO_FATAL_FAILURE(InitState());
14138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14139
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014140 char const *vsSource =
14141 "#version 450\n"
14142 "\n"
14143 "out block { layout(location=0, component=0) float x; } outs;\n"
14144 "out gl_PerVertex {\n"
14145 " vec4 gl_Position;\n"
14146 "};\n"
14147 "void main(){\n"
14148 " outs.x = 0;\n"
14149 " gl_Position = vec4(1);\n"
14150 "}\n";
14151 char const *fsSource =
14152 "#version 450\n"
14153 "\n"
14154 "in block { layout(location=0, component=1) float x; } ins;\n"
14155 "layout(location=0) out vec4 color;\n"
14156 "void main(){\n"
14157 " color = vec4(ins.x);\n"
14158 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014159
14160 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14161 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14162
14163 VkPipelineObj pipe(m_device);
14164 pipe.AddColorAttachment();
14165 pipe.AddShader(&vs);
14166 pipe.AddShader(&fs);
14167
14168 VkDescriptorSetObj descriptorSet(m_device);
14169 descriptorSet.AppendDummy();
14170 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14171
14172 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14173
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014174 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014175}
14176
Chris Forbes1f3b0152016-11-30 12:48:40 +130014177TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14178 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14179
14180 ASSERT_NO_FATAL_FAILURE(InitState());
14181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14182
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014183 char const *vsSource =
14184 "#version 450\n"
14185 "layout(location=0) out mediump float x;\n"
14186 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14187 char const *fsSource =
14188 "#version 450\n"
14189 "layout(location=0) in highp float x;\n"
14190 "layout(location=0) out vec4 color;\n"
14191 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014192
14193 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14194 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14195
14196 VkPipelineObj pipe(m_device);
14197 pipe.AddColorAttachment();
14198 pipe.AddShader(&vs);
14199 pipe.AddShader(&fs);
14200
14201 VkDescriptorSetObj descriptorSet(m_device);
14202 descriptorSet.AppendDummy();
14203 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14204
14205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14206
14207 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14208
14209 m_errorMonitor->VerifyFound();
14210}
14211
Chris Forbes870a39e2016-11-30 12:55:56 +130014212TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14213 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14214
14215 ASSERT_NO_FATAL_FAILURE(InitState());
14216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14217
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014218 char const *vsSource =
14219 "#version 450\n"
14220 "out block { layout(location=0) mediump float x; };\n"
14221 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14222 char const *fsSource =
14223 "#version 450\n"
14224 "in block { layout(location=0) highp float x; };\n"
14225 "layout(location=0) out vec4 color;\n"
14226 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014227
14228 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14229 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14230
14231 VkPipelineObj pipe(m_device);
14232 pipe.AddColorAttachment();
14233 pipe.AddShader(&vs);
14234 pipe.AddShader(&fs);
14235
14236 VkDescriptorSetObj descriptorSet(m_device);
14237 descriptorSet.AppendDummy();
14238 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14239
14240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14241
14242 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14243
14244 m_errorMonitor->VerifyFound();
14245}
14246
Karl Schultz6addd812016-02-02 17:17:23 -070014247TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014248 TEST_DESCRIPTION(
14249 "Test that a warning is produced for a vertex attribute which is "
14250 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014252
Chris Forbesde136e02015-05-25 11:13:28 +120014253 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014255
14256 VkVertexInputBindingDescription input_binding;
14257 memset(&input_binding, 0, sizeof(input_binding));
14258
14259 VkVertexInputAttributeDescription input_attrib;
14260 memset(&input_attrib, 0, sizeof(input_attrib));
14261 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14262
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014263 char const *vsSource =
14264 "#version 450\n"
14265 "\n"
14266 "out gl_PerVertex {\n"
14267 " vec4 gl_Position;\n"
14268 "};\n"
14269 "void main(){\n"
14270 " gl_Position = vec4(1);\n"
14271 "}\n";
14272 char const *fsSource =
14273 "#version 450\n"
14274 "\n"
14275 "layout(location=0) out vec4 color;\n"
14276 "void main(){\n"
14277 " color = vec4(1);\n"
14278 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014279
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014280 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14281 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014282
14283 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014284 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014285 pipe.AddShader(&vs);
14286 pipe.AddShader(&fs);
14287
14288 pipe.AddVertexInputBindings(&input_binding, 1);
14289 pipe.AddVertexInputAttribs(&input_attrib, 1);
14290
Chris Forbesde136e02015-05-25 11:13:28 +120014291 VkDescriptorSetObj descriptorSet(m_device);
14292 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014293 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014294
Tony Barbour5781e8f2015-08-04 16:23:11 -060014295 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014296
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014297 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014298}
14299
Karl Schultz6addd812016-02-02 17:17:23 -070014300TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014301 TEST_DESCRIPTION(
14302 "Test that a warning is produced for a location mismatch on "
14303 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014305
14306 ASSERT_NO_FATAL_FAILURE(InitState());
14307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14308
14309 VkVertexInputBindingDescription input_binding;
14310 memset(&input_binding, 0, sizeof(input_binding));
14311
14312 VkVertexInputAttributeDescription input_attrib;
14313 memset(&input_attrib, 0, sizeof(input_attrib));
14314 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14315
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014316 char const *vsSource =
14317 "#version 450\n"
14318 "\n"
14319 "layout(location=1) in float x;\n"
14320 "out gl_PerVertex {\n"
14321 " vec4 gl_Position;\n"
14322 "};\n"
14323 "void main(){\n"
14324 " gl_Position = vec4(x);\n"
14325 "}\n";
14326 char const *fsSource =
14327 "#version 450\n"
14328 "\n"
14329 "layout(location=0) out vec4 color;\n"
14330 "void main(){\n"
14331 " color = vec4(1);\n"
14332 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014333
14334 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14335 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14336
14337 VkPipelineObj pipe(m_device);
14338 pipe.AddColorAttachment();
14339 pipe.AddShader(&vs);
14340 pipe.AddShader(&fs);
14341
14342 pipe.AddVertexInputBindings(&input_binding, 1);
14343 pipe.AddVertexInputAttribs(&input_attrib, 1);
14344
14345 VkDescriptorSetObj descriptorSet(m_device);
14346 descriptorSet.AppendDummy();
14347 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14348
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014349 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014350 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14351
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014352 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014353}
14354
Karl Schultz6addd812016-02-02 17:17:23 -070014355TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014356 TEST_DESCRIPTION(
14357 "Test that an error is produced for a vertex shader input which is not "
14358 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14360 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014361
Chris Forbes62e8e502015-05-25 11:13:29 +120014362 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014364
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014365 char const *vsSource =
14366 "#version 450\n"
14367 "\n"
14368 "layout(location=0) in vec4 x;\n" /* not provided */
14369 "out gl_PerVertex {\n"
14370 " vec4 gl_Position;\n"
14371 "};\n"
14372 "void main(){\n"
14373 " gl_Position = x;\n"
14374 "}\n";
14375 char const *fsSource =
14376 "#version 450\n"
14377 "\n"
14378 "layout(location=0) out vec4 color;\n"
14379 "void main(){\n"
14380 " color = vec4(1);\n"
14381 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014382
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014383 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14384 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014385
14386 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014387 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014388 pipe.AddShader(&vs);
14389 pipe.AddShader(&fs);
14390
Chris Forbes62e8e502015-05-25 11:13:29 +120014391 VkDescriptorSetObj descriptorSet(m_device);
14392 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014393 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014394
Tony Barbour5781e8f2015-08-04 16:23:11 -060014395 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014396
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014397 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014398}
14399
Karl Schultz6addd812016-02-02 17:17:23 -070014400TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014401 TEST_DESCRIPTION(
14402 "Test that an error is produced for a mismatch between the "
14403 "fundamental type (float/int/uint) of an attribute and the "
14404 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014405 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 -060014406
Chris Forbesc97d98e2015-05-25 11:13:31 +120014407 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014409
14410 VkVertexInputBindingDescription input_binding;
14411 memset(&input_binding, 0, sizeof(input_binding));
14412
14413 VkVertexInputAttributeDescription input_attrib;
14414 memset(&input_attrib, 0, sizeof(input_attrib));
14415 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14416
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014417 char const *vsSource =
14418 "#version 450\n"
14419 "\n"
14420 "layout(location=0) in int x;\n" /* attrib provided float */
14421 "out gl_PerVertex {\n"
14422 " vec4 gl_Position;\n"
14423 "};\n"
14424 "void main(){\n"
14425 " gl_Position = vec4(x);\n"
14426 "}\n";
14427 char const *fsSource =
14428 "#version 450\n"
14429 "\n"
14430 "layout(location=0) out vec4 color;\n"
14431 "void main(){\n"
14432 " color = vec4(1);\n"
14433 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014434
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014435 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14436 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014437
14438 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014439 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014440 pipe.AddShader(&vs);
14441 pipe.AddShader(&fs);
14442
14443 pipe.AddVertexInputBindings(&input_binding, 1);
14444 pipe.AddVertexInputAttribs(&input_attrib, 1);
14445
Chris Forbesc97d98e2015-05-25 11:13:31 +120014446 VkDescriptorSetObj descriptorSet(m_device);
14447 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014448 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014449
Tony Barbour5781e8f2015-08-04 16:23:11 -060014450 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014451
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014452 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014453}
14454
Chris Forbesc68b43c2016-04-06 11:18:47 +120014455TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014456 TEST_DESCRIPTION(
14457 "Test that an error is produced for a pipeline containing multiple "
14458 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14460 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014461
14462 ASSERT_NO_FATAL_FAILURE(InitState());
14463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14464
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014465 char const *vsSource =
14466 "#version 450\n"
14467 "\n"
14468 "out gl_PerVertex {\n"
14469 " vec4 gl_Position;\n"
14470 "};\n"
14471 "void main(){\n"
14472 " gl_Position = vec4(1);\n"
14473 "}\n";
14474 char const *fsSource =
14475 "#version 450\n"
14476 "\n"
14477 "layout(location=0) out vec4 color;\n"
14478 "void main(){\n"
14479 " color = vec4(1);\n"
14480 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014481
14482 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14483 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14484
14485 VkPipelineObj pipe(m_device);
14486 pipe.AddColorAttachment();
14487 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014488 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014489 pipe.AddShader(&fs);
14490
14491 VkDescriptorSetObj descriptorSet(m_device);
14492 descriptorSet.AppendDummy();
14493 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14494
14495 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14496
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014497 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014498}
14499
Chris Forbes82ff92a2016-09-09 10:50:24 +120014500TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014502
14503 ASSERT_NO_FATAL_FAILURE(InitState());
14504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14505
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014506 char const *vsSource =
14507 "#version 450\n"
14508 "out gl_PerVertex {\n"
14509 " vec4 gl_Position;\n"
14510 "};\n"
14511 "void main(){\n"
14512 " gl_Position = vec4(0);\n"
14513 "}\n";
14514 char const *fsSource =
14515 "#version 450\n"
14516 "\n"
14517 "layout(location=0) out vec4 color;\n"
14518 "void main(){\n"
14519 " color = vec4(1);\n"
14520 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014521
14522 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14523 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14524
14525 VkPipelineObj pipe(m_device);
14526 pipe.AddColorAttachment();
14527 pipe.AddShader(&vs);
14528 pipe.AddShader(&fs);
14529
14530 VkDescriptorSetObj descriptorSet(m_device);
14531 descriptorSet.AppendDummy();
14532 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14533
14534 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14535
14536 m_errorMonitor->VerifyFound();
14537}
14538
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014539TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14541 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14542 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014543
14544 ASSERT_NO_FATAL_FAILURE(InitState());
14545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14546
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014547 char const *vsSource =
14548 "#version 450\n"
14549 "void main(){ gl_Position = vec4(0); }\n";
14550 char const *fsSource =
14551 "#version 450\n"
14552 "\n"
14553 "layout(location=0) out vec4 color;\n"
14554 "void main(){\n"
14555 " color = vec4(1);\n"
14556 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014557
14558 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14559 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14560
14561 VkPipelineObj pipe(m_device);
14562 pipe.AddColorAttachment();
14563 pipe.AddShader(&vs);
14564 pipe.AddShader(&fs);
14565
14566 VkDescriptorSetObj descriptorSet(m_device);
14567 descriptorSet.AppendDummy();
14568 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14569
14570 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014571 {
14572 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14573 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14574 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014575 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014576 {
14577 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14578 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14579 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014580 },
14581 };
14582 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014583 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014584 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014585 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14586 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014587 VkRenderPass rp;
14588 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14589 ASSERT_VK_SUCCESS(err);
14590
14591 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14592
14593 m_errorMonitor->VerifyFound();
14594
14595 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14596}
14597
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014598TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014599 TEST_DESCRIPTION(
14600 "Test that an error is produced for a variable output from "
14601 "the TCS without the patch decoration, but consumed in the TES "
14602 "with the decoration.");
14603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14604 "is per-vertex in tessellation control shader stage "
14605 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014606
14607 ASSERT_NO_FATAL_FAILURE(InitState());
14608 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14609
Chris Forbesc1e852d2016-04-04 19:26:42 +120014610 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014611 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014612 return;
14613 }
14614
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014615 char const *vsSource =
14616 "#version 450\n"
14617 "void main(){}\n";
14618 char const *tcsSource =
14619 "#version 450\n"
14620 "layout(location=0) out int x[];\n"
14621 "layout(vertices=3) out;\n"
14622 "void main(){\n"
14623 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14624 " gl_TessLevelInner[0] = 1;\n"
14625 " x[gl_InvocationID] = gl_InvocationID;\n"
14626 "}\n";
14627 char const *tesSource =
14628 "#version 450\n"
14629 "layout(triangles, equal_spacing, cw) in;\n"
14630 "layout(location=0) patch in int x;\n"
14631 "out gl_PerVertex { vec4 gl_Position; };\n"
14632 "void main(){\n"
14633 " gl_Position.xyz = gl_TessCoord;\n"
14634 " gl_Position.w = x;\n"
14635 "}\n";
14636 char const *fsSource =
14637 "#version 450\n"
14638 "layout(location=0) out vec4 color;\n"
14639 "void main(){\n"
14640 " color = vec4(1);\n"
14641 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014642
14643 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14644 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14645 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14646 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14647
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014648 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14649 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014650
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014651 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014652
14653 VkPipelineObj pipe(m_device);
14654 pipe.SetInputAssembly(&iasci);
14655 pipe.SetTessellation(&tsci);
14656 pipe.AddColorAttachment();
14657 pipe.AddShader(&vs);
14658 pipe.AddShader(&tcs);
14659 pipe.AddShader(&tes);
14660 pipe.AddShader(&fs);
14661
14662 VkDescriptorSetObj descriptorSet(m_device);
14663 descriptorSet.AppendDummy();
14664 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14665
14666 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14667
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014668 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014669}
14670
Karl Schultz6addd812016-02-02 17:17:23 -070014671TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014672 TEST_DESCRIPTION(
14673 "Test that an error is produced for a vertex attribute setup where multiple "
14674 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14676 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014677
Chris Forbes280ba2c2015-06-12 11:16:41 +120014678 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014680
14681 /* Two binding descriptions for binding 0 */
14682 VkVertexInputBindingDescription input_bindings[2];
14683 memset(input_bindings, 0, sizeof(input_bindings));
14684
14685 VkVertexInputAttributeDescription input_attrib;
14686 memset(&input_attrib, 0, sizeof(input_attrib));
14687 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14688
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014689 char const *vsSource =
14690 "#version 450\n"
14691 "\n"
14692 "layout(location=0) in float x;\n" /* attrib provided float */
14693 "out gl_PerVertex {\n"
14694 " vec4 gl_Position;\n"
14695 "};\n"
14696 "void main(){\n"
14697 " gl_Position = vec4(x);\n"
14698 "}\n";
14699 char const *fsSource =
14700 "#version 450\n"
14701 "\n"
14702 "layout(location=0) out vec4 color;\n"
14703 "void main(){\n"
14704 " color = vec4(1);\n"
14705 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014706
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014707 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14708 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014709
14710 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014711 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014712 pipe.AddShader(&vs);
14713 pipe.AddShader(&fs);
14714
14715 pipe.AddVertexInputBindings(input_bindings, 2);
14716 pipe.AddVertexInputAttribs(&input_attrib, 1);
14717
Chris Forbes280ba2c2015-06-12 11:16:41 +120014718 VkDescriptorSetObj descriptorSet(m_device);
14719 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014720 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014721
Tony Barbour5781e8f2015-08-04 16:23:11 -060014722 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014723
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014724 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014725}
Chris Forbes8f68b562015-05-25 11:13:32 +120014726
Karl Schultz6addd812016-02-02 17:17:23 -070014727TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014728 TEST_DESCRIPTION(
14729 "Test that an error is produced for a fragment shader which does not "
14730 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014732
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014733 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014734
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014735 char const *vsSource =
14736 "#version 450\n"
14737 "\n"
14738 "out gl_PerVertex {\n"
14739 " vec4 gl_Position;\n"
14740 "};\n"
14741 "void main(){\n"
14742 " gl_Position = vec4(1);\n"
14743 "}\n";
14744 char const *fsSource =
14745 "#version 450\n"
14746 "\n"
14747 "void main(){\n"
14748 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014749
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014750 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14751 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014752
14753 VkPipelineObj pipe(m_device);
14754 pipe.AddShader(&vs);
14755 pipe.AddShader(&fs);
14756
Chia-I Wu08accc62015-07-07 11:50:03 +080014757 /* set up CB 0, not written */
14758 pipe.AddColorAttachment();
14759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014760
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014761 VkDescriptorSetObj descriptorSet(m_device);
14762 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014763 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014764
Tony Barbour5781e8f2015-08-04 16:23:11 -060014765 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014766
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014767 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014768}
14769
Karl Schultz6addd812016-02-02 17:17:23 -070014770TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014771 TEST_DESCRIPTION(
14772 "Test that a warning is produced for a fragment shader which provides a spurious "
14773 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014775 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014776
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014777 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014778
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014779 char const *vsSource =
14780 "#version 450\n"
14781 "\n"
14782 "out gl_PerVertex {\n"
14783 " vec4 gl_Position;\n"
14784 "};\n"
14785 "void main(){\n"
14786 " gl_Position = vec4(1);\n"
14787 "}\n";
14788 char const *fsSource =
14789 "#version 450\n"
14790 "\n"
14791 "layout(location=0) out vec4 x;\n"
14792 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14793 "void main(){\n"
14794 " x = vec4(1);\n"
14795 " y = vec4(1);\n"
14796 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014797
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014798 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14799 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014800
14801 VkPipelineObj pipe(m_device);
14802 pipe.AddShader(&vs);
14803 pipe.AddShader(&fs);
14804
Chia-I Wu08accc62015-07-07 11:50:03 +080014805 /* set up CB 0, not written */
14806 pipe.AddColorAttachment();
14807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014808 /* FS writes CB 1, but we don't configure it */
14809
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014810 VkDescriptorSetObj descriptorSet(m_device);
14811 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014812 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014813
Tony Barbour5781e8f2015-08-04 16:23:11 -060014814 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014815
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014816 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014817}
14818
Karl Schultz6addd812016-02-02 17:17:23 -070014819TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014820 TEST_DESCRIPTION(
14821 "Test that an error is produced for a mismatch between the fundamental "
14822 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014824
Chris Forbesa36d69e2015-05-25 11:13:44 +120014825 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014826
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014827 char const *vsSource =
14828 "#version 450\n"
14829 "\n"
14830 "out gl_PerVertex {\n"
14831 " vec4 gl_Position;\n"
14832 "};\n"
14833 "void main(){\n"
14834 " gl_Position = vec4(1);\n"
14835 "}\n";
14836 char const *fsSource =
14837 "#version 450\n"
14838 "\n"
14839 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14840 "void main(){\n"
14841 " x = ivec4(1);\n"
14842 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014843
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014844 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14845 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014846
14847 VkPipelineObj pipe(m_device);
14848 pipe.AddShader(&vs);
14849 pipe.AddShader(&fs);
14850
Chia-I Wu08accc62015-07-07 11:50:03 +080014851 /* set up CB 0; type is UNORM by default */
14852 pipe.AddColorAttachment();
14853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014854
Chris Forbesa36d69e2015-05-25 11:13:44 +120014855 VkDescriptorSetObj descriptorSet(m_device);
14856 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014858
Tony Barbour5781e8f2015-08-04 16:23:11 -060014859 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014860
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014861 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014862}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014863
Karl Schultz6addd812016-02-02 17:17:23 -070014864TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014865 TEST_DESCRIPTION(
14866 "Test that an error is produced for a shader consuming a uniform "
14867 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014869
Chris Forbes556c76c2015-08-14 12:04:59 +120014870 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014871
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014872 char const *vsSource =
14873 "#version 450\n"
14874 "\n"
14875 "out gl_PerVertex {\n"
14876 " vec4 gl_Position;\n"
14877 "};\n"
14878 "void main(){\n"
14879 " gl_Position = vec4(1);\n"
14880 "}\n";
14881 char const *fsSource =
14882 "#version 450\n"
14883 "\n"
14884 "layout(location=0) out vec4 x;\n"
14885 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14886 "void main(){\n"
14887 " x = vec4(bar.y);\n"
14888 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014889
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014890 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14891 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014892
Chris Forbes556c76c2015-08-14 12:04:59 +120014893 VkPipelineObj pipe(m_device);
14894 pipe.AddShader(&vs);
14895 pipe.AddShader(&fs);
14896
14897 /* set up CB 0; type is UNORM by default */
14898 pipe.AddColorAttachment();
14899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14900
14901 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014902 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014903
14904 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14905
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014906 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014907}
14908
Chris Forbes5c59e902016-02-26 16:56:09 +130014909TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014910 TEST_DESCRIPTION(
14911 "Test that an error is produced for a shader consuming push constants "
14912 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014914
14915 ASSERT_NO_FATAL_FAILURE(InitState());
14916
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014917 char const *vsSource =
14918 "#version 450\n"
14919 "\n"
14920 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14921 "out gl_PerVertex {\n"
14922 " vec4 gl_Position;\n"
14923 "};\n"
14924 "void main(){\n"
14925 " gl_Position = vec4(consts.x);\n"
14926 "}\n";
14927 char const *fsSource =
14928 "#version 450\n"
14929 "\n"
14930 "layout(location=0) out vec4 x;\n"
14931 "void main(){\n"
14932 " x = vec4(1);\n"
14933 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014934
14935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14937
14938 VkPipelineObj pipe(m_device);
14939 pipe.AddShader(&vs);
14940 pipe.AddShader(&fs);
14941
14942 /* set up CB 0; type is UNORM by default */
14943 pipe.AddColorAttachment();
14944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14945
14946 VkDescriptorSetObj descriptorSet(m_device);
14947 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14948
14949 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14950
14951 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014952 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014953}
14954
Chris Forbes3fb17902016-08-22 14:57:55 +120014955TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014956 TEST_DESCRIPTION(
14957 "Test that an error is produced for a shader consuming an input attachment "
14958 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14960 "consumes input attachment index 0 but not provided in subpass");
14961
14962 ASSERT_NO_FATAL_FAILURE(InitState());
14963
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014964 char const *vsSource =
14965 "#version 450\n"
14966 "\n"
14967 "out gl_PerVertex {\n"
14968 " vec4 gl_Position;\n"
14969 "};\n"
14970 "void main(){\n"
14971 " gl_Position = vec4(1);\n"
14972 "}\n";
14973 char const *fsSource =
14974 "#version 450\n"
14975 "\n"
14976 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14977 "layout(location=0) out vec4 color;\n"
14978 "void main() {\n"
14979 " color = subpassLoad(x);\n"
14980 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014981
14982 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14983 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14984
14985 VkPipelineObj pipe(m_device);
14986 pipe.AddShader(&vs);
14987 pipe.AddShader(&fs);
14988 pipe.AddColorAttachment();
14989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014991 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14992 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014993 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014994 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014995 ASSERT_VK_SUCCESS(err);
14996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014997 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014998 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014999 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015000 ASSERT_VK_SUCCESS(err);
15001
15002 // error here.
15003 pipe.CreateVKPipeline(pl, renderPass());
15004
15005 m_errorMonitor->VerifyFound();
15006
15007 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15008 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15009}
15010
Chris Forbes5a9a0472016-08-22 16:02:09 +120015011TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015012 TEST_DESCRIPTION(
15013 "Test that an error is produced for a shader consuming an input attachment "
15014 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15016 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15017
15018 ASSERT_NO_FATAL_FAILURE(InitState());
15019
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015020 char const *vsSource =
15021 "#version 450\n"
15022 "\n"
15023 "out gl_PerVertex {\n"
15024 " vec4 gl_Position;\n"
15025 "};\n"
15026 "void main(){\n"
15027 " gl_Position = vec4(1);\n"
15028 "}\n";
15029 char const *fsSource =
15030 "#version 450\n"
15031 "\n"
15032 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15033 "layout(location=0) out vec4 color;\n"
15034 "void main() {\n"
15035 " color = subpassLoad(x);\n"
15036 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015037
15038 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15039 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15040
15041 VkPipelineObj pipe(m_device);
15042 pipe.AddShader(&vs);
15043 pipe.AddShader(&fs);
15044 pipe.AddColorAttachment();
15045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15048 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015049 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015050 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015051 ASSERT_VK_SUCCESS(err);
15052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015054 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015055 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015056 ASSERT_VK_SUCCESS(err);
15057
15058 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015059 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15060 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15061 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15062 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15063 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 +120015064 };
15065 VkAttachmentReference color = {
15066 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15067 };
15068 VkAttachmentReference input = {
15069 1, VK_IMAGE_LAYOUT_GENERAL,
15070 };
15071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015072 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015074 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015075 VkRenderPass rp;
15076 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15077 ASSERT_VK_SUCCESS(err);
15078
15079 // error here.
15080 pipe.CreateVKPipeline(pl, rp);
15081
15082 m_errorMonitor->VerifyFound();
15083
15084 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15085 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15086 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15087}
15088
Chris Forbes541f7b02016-08-22 15:30:27 +120015089TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015090 TEST_DESCRIPTION(
15091 "Test that an error is produced for a shader consuming an input attachment "
15092 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015094 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015095
15096 ASSERT_NO_FATAL_FAILURE(InitState());
15097
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015098 char const *vsSource =
15099 "#version 450\n"
15100 "\n"
15101 "out gl_PerVertex {\n"
15102 " vec4 gl_Position;\n"
15103 "};\n"
15104 "void main(){\n"
15105 " gl_Position = vec4(1);\n"
15106 "}\n";
15107 char const *fsSource =
15108 "#version 450\n"
15109 "\n"
15110 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15111 "layout(location=0) out vec4 color;\n"
15112 "void main() {\n"
15113 " color = subpassLoad(xs[0]);\n"
15114 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015115
15116 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15117 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15118
15119 VkPipelineObj pipe(m_device);
15120 pipe.AddShader(&vs);
15121 pipe.AddShader(&fs);
15122 pipe.AddColorAttachment();
15123 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015125 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15126 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015127 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015128 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015129 ASSERT_VK_SUCCESS(err);
15130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015132 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015133 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015134 ASSERT_VK_SUCCESS(err);
15135
15136 // error here.
15137 pipe.CreateVKPipeline(pl, renderPass());
15138
15139 m_errorMonitor->VerifyFound();
15140
15141 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15142 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15143}
15144
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015145TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015146 TEST_DESCRIPTION(
15147 "Test that an error is produced for a compute pipeline consuming a "
15148 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015150
15151 ASSERT_NO_FATAL_FAILURE(InitState());
15152
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015153 char const *csSource =
15154 "#version 450\n"
15155 "\n"
15156 "layout(local_size_x=1) in;\n"
15157 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15158 "void main(){\n"
15159 " x = vec4(1);\n"
15160 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015161
15162 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15163
15164 VkDescriptorSetObj descriptorSet(m_device);
15165 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015167 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15168 nullptr,
15169 0,
15170 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15171 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15172 descriptorSet.GetPipelineLayout(),
15173 VK_NULL_HANDLE,
15174 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015175
15176 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015177 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015178
15179 m_errorMonitor->VerifyFound();
15180
15181 if (err == VK_SUCCESS) {
15182 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15183 }
15184}
15185
Chris Forbes22a9b092016-07-19 14:34:05 +120015186TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015187 TEST_DESCRIPTION(
15188 "Test that an error is produced for a pipeline consuming a "
15189 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15191 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015192
15193 ASSERT_NO_FATAL_FAILURE(InitState());
15194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015195 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15196 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015197 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015198 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015199 ASSERT_VK_SUCCESS(err);
15200
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015201 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015202 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015203 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015204 ASSERT_VK_SUCCESS(err);
15205
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015206 char const *csSource =
15207 "#version 450\n"
15208 "\n"
15209 "layout(local_size_x=1) in;\n"
15210 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15211 "void main() {\n"
15212 " x.x = 1.0f;\n"
15213 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015214 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015216 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15217 nullptr,
15218 0,
15219 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15220 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15221 pl,
15222 VK_NULL_HANDLE,
15223 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015224
15225 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015226 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015227
15228 m_errorMonitor->VerifyFound();
15229
15230 if (err == VK_SUCCESS) {
15231 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15232 }
15233
15234 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15235 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15236}
15237
Chris Forbes50020592016-07-27 13:52:41 +120015238TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015239 TEST_DESCRIPTION(
15240 "Test that an error is produced when an image view type "
15241 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015243 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 +120015244
15245 ASSERT_NO_FATAL_FAILURE(InitState());
15246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15247
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015248 char const *vsSource =
15249 "#version 450\n"
15250 "\n"
15251 "out gl_PerVertex { vec4 gl_Position; };\n"
15252 "void main() { gl_Position = vec4(0); }\n";
15253 char const *fsSource =
15254 "#version 450\n"
15255 "\n"
15256 "layout(set=0, binding=0) uniform sampler3D s;\n"
15257 "layout(location=0) out vec4 color;\n"
15258 "void main() {\n"
15259 " color = texture(s, vec3(0));\n"
15260 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015261 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15262 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15263
15264 VkPipelineObj pipe(m_device);
15265 pipe.AddShader(&vs);
15266 pipe.AddShader(&fs);
15267 pipe.AddColorAttachment();
15268
15269 VkTextureObj texture(m_device, nullptr);
15270 VkSamplerObj sampler(m_device);
15271
15272 VkDescriptorSetObj descriptorSet(m_device);
15273 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15274 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15275
15276 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15277 ASSERT_VK_SUCCESS(err);
15278
Tony Barbour552f6c02016-12-21 14:34:07 -070015279 m_commandBuffer->BeginCommandBuffer();
15280 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015281
15282 m_commandBuffer->BindPipeline(pipe);
15283 m_commandBuffer->BindDescriptorSet(descriptorSet);
15284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015285 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015286 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015288 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15289
15290 // error produced here.
15291 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15292
15293 m_errorMonitor->VerifyFound();
15294
Tony Barbour552f6c02016-12-21 14:34:07 -070015295 m_commandBuffer->EndRenderPass();
15296 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015297}
15298
Chris Forbes5533bfc2016-07-27 14:12:34 +120015299TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015300 TEST_DESCRIPTION(
15301 "Test that an error is produced when a multisampled images "
15302 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015305
15306 ASSERT_NO_FATAL_FAILURE(InitState());
15307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15308
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015309 char const *vsSource =
15310 "#version 450\n"
15311 "\n"
15312 "out gl_PerVertex { vec4 gl_Position; };\n"
15313 "void main() { gl_Position = vec4(0); }\n";
15314 char const *fsSource =
15315 "#version 450\n"
15316 "\n"
15317 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15318 "layout(location=0) out vec4 color;\n"
15319 "void main() {\n"
15320 " color = texelFetch(s, ivec2(0), 0);\n"
15321 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015322 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15323 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15324
15325 VkPipelineObj pipe(m_device);
15326 pipe.AddShader(&vs);
15327 pipe.AddShader(&fs);
15328 pipe.AddColorAttachment();
15329
15330 VkTextureObj texture(m_device, nullptr);
15331 VkSamplerObj sampler(m_device);
15332
15333 VkDescriptorSetObj descriptorSet(m_device);
15334 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15335 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15336
15337 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15338 ASSERT_VK_SUCCESS(err);
15339
Tony Barbour552f6c02016-12-21 14:34:07 -070015340 m_commandBuffer->BeginCommandBuffer();
15341 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015342
15343 m_commandBuffer->BindPipeline(pipe);
15344 m_commandBuffer->BindDescriptorSet(descriptorSet);
15345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015346 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015347 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015348 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015349 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15350
15351 // error produced here.
15352 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15353
15354 m_errorMonitor->VerifyFound();
15355
Tony Barbour552f6c02016-12-21 14:34:07 -070015356 m_commandBuffer->EndRenderPass();
15357 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015358}
15359
Mark Youngc48c4c12016-04-11 14:26:49 -060015360TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015362
15363 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015364
15365 // Create an image
15366 VkImage image;
15367
Karl Schultz6addd812016-02-02 17:17:23 -070015368 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15369 const int32_t tex_width = 32;
15370 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015371
15372 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015373 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15374 image_create_info.pNext = NULL;
15375 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15376 image_create_info.format = tex_format;
15377 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015378 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015379 image_create_info.extent.depth = 1;
15380 image_create_info.mipLevels = 1;
15381 image_create_info.arrayLayers = 1;
15382 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15383 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15384 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15385 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015386
15387 // Introduce error by sending down a bogus width extent
15388 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015389 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015390
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015391 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015392}
15393
Mark Youngc48c4c12016-04-11 14:26:49 -060015394TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015396
15397 ASSERT_NO_FATAL_FAILURE(InitState());
15398
15399 // Create an image
15400 VkImage image;
15401
15402 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15403 const int32_t tex_width = 32;
15404 const int32_t tex_height = 32;
15405
15406 VkImageCreateInfo image_create_info = {};
15407 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15408 image_create_info.pNext = NULL;
15409 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15410 image_create_info.format = tex_format;
15411 image_create_info.extent.width = tex_width;
15412 image_create_info.extent.height = tex_height;
15413 image_create_info.extent.depth = 1;
15414 image_create_info.mipLevels = 1;
15415 image_create_info.arrayLayers = 1;
15416 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15417 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15418 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15419 image_create_info.flags = 0;
15420
15421 // Introduce error by sending down a bogus width extent
15422 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015423 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015424 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15425
15426 m_errorMonitor->VerifyFound();
15427}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015428
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015429TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015430 TEST_DESCRIPTION(
15431 "Create a render pass with an attachment description "
15432 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015433
15434 ASSERT_NO_FATAL_FAILURE(InitState());
15435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15436
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015438
15439 VkAttachmentReference color_attach = {};
15440 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15441 color_attach.attachment = 0;
15442 VkSubpassDescription subpass = {};
15443 subpass.colorAttachmentCount = 1;
15444 subpass.pColorAttachments = &color_attach;
15445
15446 VkRenderPassCreateInfo rpci = {};
15447 rpci.subpassCount = 1;
15448 rpci.pSubpasses = &subpass;
15449 rpci.attachmentCount = 1;
15450 VkAttachmentDescription attach_desc = {};
15451 attach_desc.format = VK_FORMAT_UNDEFINED;
15452 rpci.pAttachments = &attach_desc;
15453 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15454 VkRenderPass rp;
15455 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15456
15457 m_errorMonitor->VerifyFound();
15458
15459 if (result == VK_SUCCESS) {
15460 vkDestroyRenderPass(m_device->device(), rp, NULL);
15461 }
15462}
15463
Karl Schultz6addd812016-02-02 17:17:23 -070015464TEST_F(VkLayerTest, InvalidImageView) {
15465 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015466
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015468
Tobin Ehliscde08892015-09-22 10:11:37 -060015469 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015470
Mike Stroyana3082432015-09-25 13:39:21 -060015471 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015472 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015473
Karl Schultz6addd812016-02-02 17:17:23 -070015474 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15475 const int32_t tex_width = 32;
15476 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015477
15478 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015479 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15480 image_create_info.pNext = NULL;
15481 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15482 image_create_info.format = tex_format;
15483 image_create_info.extent.width = tex_width;
15484 image_create_info.extent.height = tex_height;
15485 image_create_info.extent.depth = 1;
15486 image_create_info.mipLevels = 1;
15487 image_create_info.arrayLayers = 1;
15488 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15489 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15490 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15491 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015492
Chia-I Wuf7458c52015-10-26 21:10:41 +080015493 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015494 ASSERT_VK_SUCCESS(err);
15495
15496 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015497 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015498 image_view_create_info.image = image;
15499 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15500 image_view_create_info.format = tex_format;
15501 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015502 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015503 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015504 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015505
15506 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015507 m_errorMonitor->SetUnexpectedError(
15508 "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 -060015509 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015510
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015511 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015512 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015513}
Mike Stroyana3082432015-09-25 13:39:21 -060015514
Mark Youngd339ba32016-05-30 13:28:35 -060015515TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15516 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015518 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015519
15520 ASSERT_NO_FATAL_FAILURE(InitState());
15521
15522 // Create an image and try to create a view with no memory backing the image
15523 VkImage image;
15524
15525 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15526 const int32_t tex_width = 32;
15527 const int32_t tex_height = 32;
15528
15529 VkImageCreateInfo image_create_info = {};
15530 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15531 image_create_info.pNext = NULL;
15532 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15533 image_create_info.format = tex_format;
15534 image_create_info.extent.width = tex_width;
15535 image_create_info.extent.height = tex_height;
15536 image_create_info.extent.depth = 1;
15537 image_create_info.mipLevels = 1;
15538 image_create_info.arrayLayers = 1;
15539 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15540 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15541 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15542 image_create_info.flags = 0;
15543
15544 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15545 ASSERT_VK_SUCCESS(err);
15546
15547 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015548 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015549 image_view_create_info.image = image;
15550 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15551 image_view_create_info.format = tex_format;
15552 image_view_create_info.subresourceRange.layerCount = 1;
15553 image_view_create_info.subresourceRange.baseMipLevel = 0;
15554 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015555 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015556
15557 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015558 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015559
15560 m_errorMonitor->VerifyFound();
15561 vkDestroyImage(m_device->device(), image, NULL);
15562 // If last error is success, it still created the view, so delete it.
15563 if (err == VK_SUCCESS) {
15564 vkDestroyImageView(m_device->device(), view, NULL);
15565 }
Mark Youngd339ba32016-05-30 13:28:35 -060015566}
15567
Karl Schultz6addd812016-02-02 17:17:23 -070015568TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015569 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015571
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015572 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015573
Karl Schultz6addd812016-02-02 17:17:23 -070015574 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015575 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015576 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015577 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015578
15579 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015580 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015581 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015582 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15583 image_view_create_info.format = tex_format;
15584 image_view_create_info.subresourceRange.baseMipLevel = 0;
15585 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015586 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015587 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015588 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015589
15590 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015591 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015592
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015593 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015594}
15595
Mike Weiblena1e13f42017-02-09 21:25:59 -070015596TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15597 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15598
15599 ASSERT_NO_FATAL_FAILURE(InitState());
15600 VkSubresourceLayout subres_layout = {};
15601
15602 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15603 {
15604 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15605 VkImageObj img(m_device);
15606 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15607 ASSERT_TRUE(img.initialized());
15608
15609 VkImageSubresource subres = {};
15610 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15611 subres.mipLevel = 0;
15612 subres.arrayLayer = 0;
15613
15614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15615 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15616 m_errorMonitor->VerifyFound();
15617 }
15618
15619 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15620 {
15621 VkImageObj img(m_device);
15622 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15623 ASSERT_TRUE(img.initialized());
15624
15625 VkImageSubresource subres = {};
15626 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15627 subres.mipLevel = 0;
15628 subres.arrayLayer = 0;
15629
15630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15632 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15633 m_errorMonitor->VerifyFound();
15634 }
15635
15636 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15637 {
15638 VkImageObj img(m_device);
15639 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15640 ASSERT_TRUE(img.initialized());
15641
15642 VkImageSubresource subres = {};
15643 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15644 subres.mipLevel = 1; // ERROR: triggers VU 00739
15645 subres.arrayLayer = 0;
15646
15647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15648 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15649 m_errorMonitor->VerifyFound();
15650 }
15651
15652 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15653 {
15654 VkImageObj img(m_device);
15655 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15656 ASSERT_TRUE(img.initialized());
15657
15658 VkImageSubresource subres = {};
15659 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15660 subres.mipLevel = 0;
15661 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15662
15663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15664 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15665 m_errorMonitor->VerifyFound();
15666 }
15667}
15668
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015669TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015670 VkResult err;
15671 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015672
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015674
Mike Stroyana3082432015-09-25 13:39:21 -060015675 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015676
15677 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015678 VkImage srcImage;
15679 VkImage dstImage;
15680 VkDeviceMemory srcMem;
15681 VkDeviceMemory destMem;
15682 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015683
15684 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015685 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15686 image_create_info.pNext = NULL;
15687 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15688 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15689 image_create_info.extent.width = 32;
15690 image_create_info.extent.height = 32;
15691 image_create_info.extent.depth = 1;
15692 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015693 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015694 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15695 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15696 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15697 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015698
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015699 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015700 ASSERT_VK_SUCCESS(err);
15701
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015702 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015703 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015704 ASSERT_VK_SUCCESS(err);
15705
15706 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015707 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015708 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15709 memAlloc.pNext = NULL;
15710 memAlloc.allocationSize = 0;
15711 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015712
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015713 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015714 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015715 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015716 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015717 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015718 ASSERT_VK_SUCCESS(err);
15719
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015720 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015721 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015722 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015723 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015724 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015725 ASSERT_VK_SUCCESS(err);
15726
15727 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15728 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015729 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015730 ASSERT_VK_SUCCESS(err);
15731
Tony Barbour552f6c02016-12-21 14:34:07 -070015732 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015733 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015734 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015735 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015736 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015737 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015738 copyRegion.srcOffset.x = 0;
15739 copyRegion.srcOffset.y = 0;
15740 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015741 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015742 copyRegion.dstSubresource.mipLevel = 0;
15743 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015744 // Introduce failure by forcing the dst layerCount to differ from src
15745 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015746 copyRegion.dstOffset.x = 0;
15747 copyRegion.dstOffset.y = 0;
15748 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015749 copyRegion.extent.width = 1;
15750 copyRegion.extent.height = 1;
15751 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015752 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015753 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015754
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015755 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015756
Chia-I Wuf7458c52015-10-26 21:10:41 +080015757 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015758 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015759 vkFreeMemory(m_device->device(), srcMem, NULL);
15760 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015761}
15762
Tony Barbourd6673642016-05-05 14:46:39 -060015763TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015764 TEST_DESCRIPTION("Creating images with unsuported formats ");
15765
15766 ASSERT_NO_FATAL_FAILURE(InitState());
15767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15768 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015769 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 -060015770 VK_IMAGE_TILING_OPTIMAL, 0);
15771 ASSERT_TRUE(image.initialized());
15772
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015773 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015774 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015775 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15777 image_create_info.format = VK_FORMAT_UNDEFINED;
15778 image_create_info.extent.width = 32;
15779 image_create_info.extent.height = 32;
15780 image_create_info.extent.depth = 1;
15781 image_create_info.mipLevels = 1;
15782 image_create_info.arrayLayers = 1;
15783 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15784 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15785 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15788 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015789
15790 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015791 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15792 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15793 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15794 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015795 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15796 m_errorMonitor->VerifyFound();
15797
Tony Barbourd6673642016-05-05 14:46:39 -060015798 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015799 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015800 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15801 VkFormat format = static_cast<VkFormat>(f);
15802 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015803 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015804 unsupported = format;
15805 break;
15806 }
15807 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015808
Tony Barbourd6673642016-05-05 14:46:39 -060015809 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015810 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015812
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015813 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15814 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15815 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15816 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15817 m_errorMonitor->SetUnexpectedError(
15818 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15819 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15820 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015821 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015822 m_errorMonitor->VerifyFound();
15823 }
15824}
15825
15826TEST_F(VkLayerTest, ImageLayerViewTests) {
15827 VkResult ret;
15828 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15829
15830 ASSERT_NO_FATAL_FAILURE(InitState());
15831
15832 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015833 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 -060015834 VK_IMAGE_TILING_OPTIMAL, 0);
15835 ASSERT_TRUE(image.initialized());
15836
15837 VkImageView imgView;
15838 VkImageViewCreateInfo imgViewInfo = {};
15839 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15840 imgViewInfo.image = image.handle();
15841 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15842 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15843 imgViewInfo.subresourceRange.layerCount = 1;
15844 imgViewInfo.subresourceRange.baseMipLevel = 0;
15845 imgViewInfo.subresourceRange.levelCount = 1;
15846 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15847
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015849 // View can't have baseMipLevel >= image's mipLevels - Expect
15850 // VIEW_CREATE_ERROR
15851 imgViewInfo.subresourceRange.baseMipLevel = 1;
15852 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15853 m_errorMonitor->VerifyFound();
15854 imgViewInfo.subresourceRange.baseMipLevel = 0;
15855
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015857 // View can't have baseArrayLayer >= image's arraySize - Expect
15858 // VIEW_CREATE_ERROR
15859 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15860 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15861 m_errorMonitor->VerifyFound();
15862 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15863
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015865 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15866 imgViewInfo.subresourceRange.levelCount = 0;
15867 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15868 m_errorMonitor->VerifyFound();
15869 imgViewInfo.subresourceRange.levelCount = 1;
15870
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015871 m_errorMonitor->SetDesiredFailureMsg(
15872 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15873 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015874 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15875 imgViewInfo.subresourceRange.layerCount = 0;
15876 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15877 m_errorMonitor->VerifyFound();
15878 imgViewInfo.subresourceRange.layerCount = 1;
15879
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15881 "Formats MUST be IDENTICAL unless "
15882 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15883 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015884 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15885 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15886 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15887 m_errorMonitor->VerifyFound();
15888 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15889
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015891 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15892 // VIEW_CREATE_ERROR
15893 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15894 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15895 m_errorMonitor->VerifyFound();
15896 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15897
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015899 // TODO: Update framework to easily passing mutable flag into ImageObj init
15900 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015901 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15902 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15903 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015904 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15905 // VIEW_CREATE_ERROR
15906 VkImageCreateInfo mutImgInfo = image.create_info();
15907 VkImage mutImage;
15908 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015909 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015910 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15911 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15912 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15913 ASSERT_VK_SUCCESS(ret);
15914 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015915 m_errorMonitor->SetUnexpectedError(
15916 "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 -060015917 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15918 m_errorMonitor->VerifyFound();
15919 imgViewInfo.image = image.handle();
15920 vkDestroyImage(m_device->handle(), mutImage, NULL);
15921}
15922
Dave Houlton59a20702017-02-02 17:26:23 -070015923TEST_F(VkLayerTest, ImageBufferCopyTests) {
15924 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
15925
15926 ASSERT_NO_FATAL_FAILURE(InitState());
Dave Houlton584d51e2017-02-16 12:52:54 -070015927
15928 // Bail if any dimension of transfer granularity is 0.
15929 auto index = m_device->graphics_queue_node_index_;
15930 auto queue_family_properties = m_device->phy().queue_properties();
15931 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
15932 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
15933 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
15934 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
15935 return;
15936 }
15937
Dave Houlton59a20702017-02-02 17:26:23 -070015938 VkImageObj image_64k(m_device); // 128^2 texels, 64k
15939 VkImageObj image_16k(m_device); // 64^2 texels, 16k
15940 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070015941 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
15942 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
15943 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
15944 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
15945
Dave Houlton59a20702017-02-02 17:26:23 -070015946 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
15947 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15948 VK_IMAGE_TILING_OPTIMAL, 0);
15949 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
15950 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15951 VK_IMAGE_TILING_OPTIMAL, 0);
15952 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15953 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070015954 ASSERT_TRUE(image_64k.initialized());
15955 ASSERT_TRUE(image_16k.initialized());
15956 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070015957
Dave Houltonf3229d52017-02-21 15:59:08 -070015958 // Verify all needed Depth/Stencil formats are supported
15959 bool missing_ds_support = false;
15960 VkFormatProperties props = {0, 0, 0};
15961 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
15962 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15963 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
15964 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15965 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
15966 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15967 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
15968 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15969
15970 if (!missing_ds_support) {
15971 ds_image_4D_1S.init(
15972 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
15973 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15974 VK_IMAGE_TILING_OPTIMAL, 0);
15975 ASSERT_TRUE(ds_image_4D_1S.initialized());
15976
15977 ds_image_3D_1S.init(
15978 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
15979 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15980 VK_IMAGE_TILING_OPTIMAL, 0);
15981 ASSERT_TRUE(ds_image_3D_1S.initialized());
15982
15983 ds_image_2D.init(
15984 256, 256, VK_FORMAT_D16_UNORM,
15985 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15986 VK_IMAGE_TILING_OPTIMAL, 0);
15987 ASSERT_TRUE(ds_image_2D.initialized());
15988
15989 ds_image_1S.init(
15990 256, 256, VK_FORMAT_S8_UINT,
15991 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15992 VK_IMAGE_TILING_OPTIMAL, 0);
15993 ASSERT_TRUE(ds_image_1S.initialized());
15994 }
15995
15996 // Allocate buffers
15997 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070015998 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070015999 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16000 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16001 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16002 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016003
16004 VkBufferImageCopy region = {};
16005 region.bufferRowLength = 0;
16006 region.bufferImageHeight = 0;
16007 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16008 region.imageSubresource.layerCount = 1;
16009 region.imageOffset = {0, 0, 0};
16010 region.imageExtent = {64, 64, 1};
16011 region.bufferOffset = 0;
16012
16013 // attempt copies before putting command buffer in recording state
16014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16015 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16016 &region);
16017 m_errorMonitor->VerifyFound();
16018
16019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16020 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16021 &region);
16022 m_errorMonitor->VerifyFound();
16023
16024 // start recording
16025 m_commandBuffer->BeginCommandBuffer();
16026
16027 // successful copies
16028 m_errorMonitor->ExpectSuccess();
16029 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16030 &region);
16031 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16032 &region);
16033 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16034 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16035 &region);
16036 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16037 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16038 &region);
16039 region.imageOffset.x = 0;
16040 region.imageExtent.height = 64;
16041 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16042 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16043 &region);
16044 m_errorMonitor->VerifyNotFound();
16045
16046 // image/buffer too small (extent) on copy to image
16047 region.imageExtent = {65, 64, 1};
16048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16049 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16050 &region);
16051 m_errorMonitor->VerifyFound();
16052
16053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16054 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16055 &region);
16056 m_errorMonitor->VerifyFound();
16057
16058 // image/buffer too small (offset) on copy to image
16059 region.imageExtent = {64, 64, 1};
16060 region.imageOffset = {0, 4, 0};
16061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16062 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16063 &region);
16064 m_errorMonitor->VerifyFound();
16065
16066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16067 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16068 &region);
16069 m_errorMonitor->VerifyFound();
16070
16071 // image/buffer too small on copy to buffer
16072 region.imageExtent = {64, 64, 1};
16073 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016074 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16076 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16077 &region);
16078 m_errorMonitor->VerifyFound();
16079
16080 region.imageExtent = {64, 65, 1};
16081 region.bufferOffset = 0;
16082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16083 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16084 &region);
16085 m_errorMonitor->VerifyFound();
16086
16087 // buffer size ok but rowlength causes loose packing
16088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16089 region.imageExtent = {64, 64, 1};
16090 region.bufferRowLength = 68;
16091 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16092 &region);
16093 m_errorMonitor->VerifyFound();
16094
Dave Houlton59a20702017-02-02 17:26:23 -070016095 // aspect bits
16096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16097 region.imageExtent = {64, 64, 1};
16098 region.bufferRowLength = 0;
16099 region.bufferImageHeight = 0;
16100 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16101 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16102 buffer_16k.handle(), 1, &region);
16103 m_errorMonitor->VerifyFound();
16104
16105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16106 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16107 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16108 &region);
16109 m_errorMonitor->VerifyFound();
16110
16111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16112 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16113 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16114 buffer_16k.handle(), 1, &region);
16115 m_errorMonitor->VerifyFound();
16116
Dave Houltonf3229d52017-02-21 15:59:08 -070016117 // Test Depth/Stencil copies
16118 if (missing_ds_support) {
16119 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16120 } else {
16121 VkBufferImageCopy ds_region = {};
16122 ds_region.bufferOffset = 0;
16123 ds_region.bufferRowLength = 0;
16124 ds_region.bufferImageHeight = 0;
16125 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16126 ds_region.imageSubresource.mipLevel = 0;
16127 ds_region.imageSubresource.baseArrayLayer = 0;
16128 ds_region.imageSubresource.layerCount = 1;
16129 ds_region.imageOffset = {0, 0, 0};
16130 ds_region.imageExtent = {256, 256, 1};
16131
16132 // Depth copies that should succeed
16133 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16134 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16135 buffer_256k.handle(), 1, &ds_region);
16136 m_errorMonitor->VerifyNotFound();
16137
16138 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16139 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16140 buffer_256k.handle(), 1, &ds_region);
16141 m_errorMonitor->VerifyNotFound();
16142
16143 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16144 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16145 buffer_128k.handle(), 1, &ds_region);
16146 m_errorMonitor->VerifyNotFound();
16147
16148 // Depth copies that should fail
16149 ds_region.bufferOffset = 4;
16150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16151 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16152 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16153 buffer_256k.handle(), 1, &ds_region);
16154 m_errorMonitor->VerifyFound();
16155
16156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16157 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16158 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16159 buffer_256k.handle(), 1, &ds_region);
16160 m_errorMonitor->VerifyFound();
16161
16162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16163 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16164 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16165 buffer_128k.handle(), 1, &ds_region);
16166 m_errorMonitor->VerifyFound();
16167
16168 // Stencil copies that should succeed
16169 ds_region.bufferOffset = 0;
16170 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16171 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16172 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16173 buffer_64k.handle(), 1, &ds_region);
16174 m_errorMonitor->VerifyNotFound();
16175
16176 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16177 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16178 buffer_64k.handle(), 1, &ds_region);
16179 m_errorMonitor->VerifyNotFound();
16180
16181 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16182 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16183 buffer_64k.handle(), 1, &ds_region);
16184 m_errorMonitor->VerifyNotFound();
16185
16186 // Stencil copies that should fail
16187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16188 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16189 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16190 buffer_16k.handle(), 1, &ds_region);
16191 m_errorMonitor->VerifyFound();
16192
16193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16194 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16195 ds_region.bufferRowLength = 260;
16196 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16197 buffer_64k.handle(), 1, &ds_region);
16198 m_errorMonitor->VerifyFound();
16199
16200 ds_region.bufferRowLength = 0;
16201 ds_region.bufferOffset = 4;
16202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16203 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16204 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16205 buffer_64k.handle(), 1, &ds_region);
16206 m_errorMonitor->VerifyFound();
16207 }
16208
Dave Houlton584d51e2017-02-16 12:52:54 -070016209 // Test compressed formats, if supported
16210 VkPhysicalDeviceFeatures device_features;
16211 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016212 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16213 device_features.textureCompressionASTC_LDR)) {
16214 printf(" No compressed formats supported - block compression tests skipped.\n");
16215 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070016216 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16217 if (device_features.textureCompressionBC) {
16218 image_16k_4x4comp.init(32, 32, VK_FORMAT_BC5_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16219 } else if (device_features.textureCompressionETC2) {
16220 image_16k_4x4comp.init(32, 32, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16221 VK_IMAGE_TILING_OPTIMAL, 0);
16222 } else {
16223 image_16k_4x4comp.init(32, 32, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16224 0);
16225 }
16226 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016227
Dave Houlton584d51e2017-02-16 12:52:54 -070016228 // Just fits
16229 m_errorMonitor->ExpectSuccess();
16230 region.imageExtent = {128, 128, 1};
16231 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16232 buffer_16k.handle(), 1, &region);
16233 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016234
Dave Houlton584d51e2017-02-16 12:52:54 -070016235 // with offset, too big for buffer
16236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16237 region.bufferOffset = 16;
16238 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16239 buffer_16k.handle(), 1, &region);
16240 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016241
Dave Houlton584d51e2017-02-16 12:52:54 -070016242 // buffer offset must be a multiple of texel block size (16)
16243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16245 region.imageExtent = {64, 64, 1};
16246 region.bufferOffset = 24;
16247 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16248 buffer_16k.handle(), 1, &region);
16249 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016250
Dave Houlton584d51e2017-02-16 12:52:54 -070016251 // rowlength not a multiple of block width (4)
16252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16253 region.bufferOffset = 0;
16254 region.bufferRowLength = 130;
16255 region.bufferImageHeight = 0;
16256 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16257 buffer_64k.handle(), 1, &region);
16258 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016259
Dave Houlton584d51e2017-02-16 12:52:54 -070016260 // imageheight not a multiple of block height (4)
16261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16262 region.bufferRowLength = 0;
16263 region.bufferImageHeight = 130;
16264 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16265 buffer_64k.handle(), 1, &region);
16266 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016267
Dave Houlton584d51e2017-02-16 12:52:54 -070016268 // image extents must be multiple of block dimensions (4x4)
16269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16270 region.bufferImageHeight = 0;
16271 region.imageOffset = {4, 6, 0};
16272 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16273 buffer_64k.handle(), 1, &region);
16274 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016275
Dave Houlton584d51e2017-02-16 12:52:54 -070016276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16277 region.imageOffset = {22, 0, 0};
16278 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16279 buffer_64k.handle(), 1, &region);
16280 m_errorMonitor->VerifyFound();
16281 }
Dave Houlton59a20702017-02-02 17:26:23 -070016282}
16283
Tony Barbourd6673642016-05-05 14:46:39 -060016284TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016285 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016286
16287 ASSERT_NO_FATAL_FAILURE(InitState());
16288
Rene Lindsay135204f2016-12-22 17:11:09 -070016289 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016290 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016291 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 -070016292 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016293 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016294 vk_testing::Buffer buffer;
16295 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016296 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016297 VkBufferImageCopy region = {};
16298 region.bufferRowLength = 128;
16299 region.bufferImageHeight = 128;
16300 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16301 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016302 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016303 region.imageExtent.height = 4;
16304 region.imageExtent.width = 4;
16305 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016306
16307 VkImageObj image2(m_device);
16308 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 -070016309 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016310 ASSERT_TRUE(image2.initialized());
16311 vk_testing::Buffer buffer2;
16312 VkMemoryPropertyFlags reqs2 = 0;
16313 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16314 VkBufferImageCopy region2 = {};
16315 region2.bufferRowLength = 128;
16316 region2.bufferImageHeight = 128;
16317 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16318 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16319 region2.imageSubresource.layerCount = 1;
16320 region2.imageExtent.height = 4;
16321 region2.imageExtent.width = 4;
16322 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016323 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016324
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016325 // Image must have offset.z of 0 and extent.depth of 1
16326 // Introduce failure by setting imageExtent.depth to 0
16327 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016329 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016330 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016331 m_errorMonitor->VerifyFound();
16332
16333 region.imageExtent.depth = 1;
16334
16335 // Image must have offset.z of 0 and extent.depth of 1
16336 // Introduce failure by setting imageOffset.z to 4
16337 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016339 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016340 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016341 m_errorMonitor->VerifyFound();
16342
16343 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016344 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16345 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016346 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016348 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16349 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016350 m_errorMonitor->VerifyFound();
16351
16352 // BufferOffset must be a multiple of 4
16353 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016354 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016356 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16357 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016358 m_errorMonitor->VerifyFound();
16359
16360 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16361 region.bufferOffset = 0;
16362 region.imageExtent.height = 128;
16363 region.imageExtent.width = 128;
16364 // Introduce failure by setting bufferRowLength > 0 but less than width
16365 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016367 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16368 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016369 m_errorMonitor->VerifyFound();
16370
16371 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16372 region.bufferRowLength = 128;
16373 // Introduce failure by setting bufferRowHeight > 0 but less than height
16374 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016376 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16377 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016378 m_errorMonitor->VerifyFound();
16379
16380 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016381 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016382 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16383 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016384 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016385 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16386 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016387 VkImageBlit blitRegion = {};
16388 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16389 blitRegion.srcSubresource.baseArrayLayer = 0;
16390 blitRegion.srcSubresource.layerCount = 1;
16391 blitRegion.srcSubresource.mipLevel = 0;
16392 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16393 blitRegion.dstSubresource.baseArrayLayer = 0;
16394 blitRegion.dstSubresource.layerCount = 1;
16395 blitRegion.dstSubresource.mipLevel = 0;
16396
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016397 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016399 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016400 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16401 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016402 m_errorMonitor->VerifyFound();
16403
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016405 VkImageMemoryBarrier img_barrier;
16406 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16407 img_barrier.pNext = NULL;
16408 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16409 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16410 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16411 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16412 img_barrier.image = image.handle();
16413 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16414 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16415 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16416 img_barrier.subresourceRange.baseArrayLayer = 0;
16417 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016418 img_barrier.subresourceRange.layerCount = 0;
16419 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016420 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16421 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016422 m_errorMonitor->VerifyFound();
16423 img_barrier.subresourceRange.layerCount = 1;
16424}
16425
16426TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016427 TEST_DESCRIPTION("Exceed the limits of image format ");
16428
Cody Northropc31a84f2016-08-22 10:41:47 -060016429 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016431 VkImageCreateInfo image_create_info = {};
16432 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16433 image_create_info.pNext = NULL;
16434 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16435 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16436 image_create_info.extent.width = 32;
16437 image_create_info.extent.height = 32;
16438 image_create_info.extent.depth = 1;
16439 image_create_info.mipLevels = 1;
16440 image_create_info.arrayLayers = 1;
16441 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16442 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16443 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16445 image_create_info.flags = 0;
16446
16447 VkImage nullImg;
16448 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016449 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16450 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016451 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016452 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16453 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16454 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016455 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016458 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16459 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16460 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16461 m_errorMonitor->VerifyFound();
16462 image_create_info.mipLevels = 1;
16463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016465 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16466 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16467 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16468 m_errorMonitor->VerifyFound();
16469 image_create_info.arrayLayers = 1;
16470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016472 int samples = imgFmtProps.sampleCounts >> 1;
16473 image_create_info.samples = (VkSampleCountFlagBits)samples;
16474 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16475 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16476 m_errorMonitor->VerifyFound();
16477 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16480 "pCreateInfo->initialLayout, must be "
16481 "VK_IMAGE_LAYOUT_UNDEFINED or "
16482 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016483 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16484 // Expect INVALID_LAYOUT
16485 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16486 m_errorMonitor->VerifyFound();
16487 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16488}
16489
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016490TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016491 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016493
16494 ASSERT_NO_FATAL_FAILURE(InitState());
16495
16496 VkImageObj src_image(m_device);
16497 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16498 VkImageObj dst_image(m_device);
16499 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16500
Tony Barbour552f6c02016-12-21 14:34:07 -070016501 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016502 VkImageCopy copy_region;
16503 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16504 copy_region.srcSubresource.mipLevel = 0;
16505 copy_region.srcSubresource.baseArrayLayer = 0;
16506 copy_region.srcSubresource.layerCount = 0;
16507 copy_region.srcOffset.x = 0;
16508 copy_region.srcOffset.y = 0;
16509 copy_region.srcOffset.z = 0;
16510 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16511 copy_region.dstSubresource.mipLevel = 0;
16512 copy_region.dstSubresource.baseArrayLayer = 0;
16513 copy_region.dstSubresource.layerCount = 0;
16514 copy_region.dstOffset.x = 0;
16515 copy_region.dstOffset.y = 0;
16516 copy_region.dstOffset.z = 0;
16517 copy_region.extent.width = 64;
16518 copy_region.extent.height = 64;
16519 copy_region.extent.depth = 1;
16520 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16521 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016522 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016523
16524 m_errorMonitor->VerifyFound();
16525}
16526
16527TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016528 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016530
16531 ASSERT_NO_FATAL_FAILURE(InitState());
16532
16533 VkImageObj src_image(m_device);
16534 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16535 VkImageObj dst_image(m_device);
16536 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16537
Tony Barbour552f6c02016-12-21 14:34:07 -070016538 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016539 VkImageCopy copy_region;
16540 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16541 copy_region.srcSubresource.mipLevel = 0;
16542 copy_region.srcSubresource.baseArrayLayer = 0;
16543 copy_region.srcSubresource.layerCount = 0;
16544 copy_region.srcOffset.x = 0;
16545 copy_region.srcOffset.y = 0;
16546 copy_region.srcOffset.z = 0;
16547 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16548 copy_region.dstSubresource.mipLevel = 0;
16549 copy_region.dstSubresource.baseArrayLayer = 0;
16550 copy_region.dstSubresource.layerCount = 0;
16551 copy_region.dstOffset.x = 0;
16552 copy_region.dstOffset.y = 0;
16553 copy_region.dstOffset.z = 0;
16554 copy_region.extent.width = 64;
16555 copy_region.extent.height = 64;
16556 copy_region.extent.depth = 1;
16557 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16558 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016559 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016560
16561 m_errorMonitor->VerifyFound();
16562}
16563
Karl Schultz6addd812016-02-02 17:17:23 -070016564TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016565 VkResult err;
16566 bool pass;
16567
16568 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016570
16571 ASSERT_NO_FATAL_FAILURE(InitState());
16572
16573 // Create two images of different types and try to copy between them
16574 VkImage srcImage;
16575 VkImage dstImage;
16576 VkDeviceMemory srcMem;
16577 VkDeviceMemory destMem;
16578 VkMemoryRequirements memReqs;
16579
16580 VkImageCreateInfo image_create_info = {};
16581 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16582 image_create_info.pNext = NULL;
16583 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16584 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16585 image_create_info.extent.width = 32;
16586 image_create_info.extent.height = 32;
16587 image_create_info.extent.depth = 1;
16588 image_create_info.mipLevels = 1;
16589 image_create_info.arrayLayers = 1;
16590 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16591 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16592 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16593 image_create_info.flags = 0;
16594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016595 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016596 ASSERT_VK_SUCCESS(err);
16597
16598 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16599 // Introduce failure by creating second image with a different-sized format.
16600 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016602 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016603 ASSERT_VK_SUCCESS(err);
16604
16605 // Allocate memory
16606 VkMemoryAllocateInfo memAlloc = {};
16607 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16608 memAlloc.pNext = NULL;
16609 memAlloc.allocationSize = 0;
16610 memAlloc.memoryTypeIndex = 0;
16611
16612 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16613 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016614 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016615 ASSERT_TRUE(pass);
16616 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16617 ASSERT_VK_SUCCESS(err);
16618
16619 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16620 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016621 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016622 ASSERT_TRUE(pass);
16623 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16624 ASSERT_VK_SUCCESS(err);
16625
16626 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16627 ASSERT_VK_SUCCESS(err);
16628 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16629 ASSERT_VK_SUCCESS(err);
16630
Tony Barbour552f6c02016-12-21 14:34:07 -070016631 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016632 VkImageCopy copyRegion;
16633 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16634 copyRegion.srcSubresource.mipLevel = 0;
16635 copyRegion.srcSubresource.baseArrayLayer = 0;
16636 copyRegion.srcSubresource.layerCount = 0;
16637 copyRegion.srcOffset.x = 0;
16638 copyRegion.srcOffset.y = 0;
16639 copyRegion.srcOffset.z = 0;
16640 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16641 copyRegion.dstSubresource.mipLevel = 0;
16642 copyRegion.dstSubresource.baseArrayLayer = 0;
16643 copyRegion.dstSubresource.layerCount = 0;
16644 copyRegion.dstOffset.x = 0;
16645 copyRegion.dstOffset.y = 0;
16646 copyRegion.dstOffset.z = 0;
16647 copyRegion.extent.width = 1;
16648 copyRegion.extent.height = 1;
16649 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016650 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016651 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016652
16653 m_errorMonitor->VerifyFound();
16654
16655 vkDestroyImage(m_device->device(), srcImage, NULL);
16656 vkDestroyImage(m_device->device(), dstImage, NULL);
16657 vkFreeMemory(m_device->device(), srcMem, NULL);
16658 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016659}
16660
Karl Schultz6addd812016-02-02 17:17:23 -070016661TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16662 VkResult err;
16663 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016664
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016665 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16667 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016668
Mike Stroyana3082432015-09-25 13:39:21 -060016669 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016670
16671 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016672 VkImage srcImage;
16673 VkImage dstImage;
16674 VkDeviceMemory srcMem;
16675 VkDeviceMemory destMem;
16676 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016677
16678 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016679 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16680 image_create_info.pNext = NULL;
16681 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16682 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16683 image_create_info.extent.width = 32;
16684 image_create_info.extent.height = 32;
16685 image_create_info.extent.depth = 1;
16686 image_create_info.mipLevels = 1;
16687 image_create_info.arrayLayers = 1;
16688 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16689 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16690 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16691 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016693 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016694 ASSERT_VK_SUCCESS(err);
16695
Karl Schultzbdb75952016-04-19 11:36:49 -060016696 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16697
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016698 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016699 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016700 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016701 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016703 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016704 ASSERT_VK_SUCCESS(err);
16705
16706 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016707 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016708 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16709 memAlloc.pNext = NULL;
16710 memAlloc.allocationSize = 0;
16711 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016712
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016713 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016714 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016715 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016716 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016717 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016718 ASSERT_VK_SUCCESS(err);
16719
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016720 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016721 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016722 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016723 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016724 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016725 ASSERT_VK_SUCCESS(err);
16726
16727 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16728 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016729 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016730 ASSERT_VK_SUCCESS(err);
16731
Tony Barbour552f6c02016-12-21 14:34:07 -070016732 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016733 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016734 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016735 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016736 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016737 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016738 copyRegion.srcOffset.x = 0;
16739 copyRegion.srcOffset.y = 0;
16740 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016741 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016742 copyRegion.dstSubresource.mipLevel = 0;
16743 copyRegion.dstSubresource.baseArrayLayer = 0;
16744 copyRegion.dstSubresource.layerCount = 0;
16745 copyRegion.dstOffset.x = 0;
16746 copyRegion.dstOffset.y = 0;
16747 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016748 copyRegion.extent.width = 1;
16749 copyRegion.extent.height = 1;
16750 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016751 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016752 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016753
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016754 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016755
Chia-I Wuf7458c52015-10-26 21:10:41 +080016756 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016757 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016758 vkFreeMemory(m_device->device(), srcMem, NULL);
16759 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016760}
16761
Karl Schultz6addd812016-02-02 17:17:23 -070016762TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16763 VkResult err;
16764 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016765
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16767 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016768
Mike Stroyana3082432015-09-25 13:39:21 -060016769 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016770
16771 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016772 VkImage srcImage;
16773 VkImage dstImage;
16774 VkDeviceMemory srcMem;
16775 VkDeviceMemory destMem;
16776 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016777
16778 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016779 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16780 image_create_info.pNext = NULL;
16781 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16782 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16783 image_create_info.extent.width = 32;
16784 image_create_info.extent.height = 1;
16785 image_create_info.extent.depth = 1;
16786 image_create_info.mipLevels = 1;
16787 image_create_info.arrayLayers = 1;
16788 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16789 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16790 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16791 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016793 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016794 ASSERT_VK_SUCCESS(err);
16795
Karl Schultz6addd812016-02-02 17:17:23 -070016796 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016798 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016799 ASSERT_VK_SUCCESS(err);
16800
16801 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016802 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016803 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16804 memAlloc.pNext = NULL;
16805 memAlloc.allocationSize = 0;
16806 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016807
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016808 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016809 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016810 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016811 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016812 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016813 ASSERT_VK_SUCCESS(err);
16814
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016815 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016816 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016817 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016818 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016819 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016820 ASSERT_VK_SUCCESS(err);
16821
16822 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16823 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016824 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016825 ASSERT_VK_SUCCESS(err);
16826
Tony Barbour552f6c02016-12-21 14:34:07 -070016827 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016828 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016829 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16830 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016831 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016832 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016833 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016834 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016835 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016836 resolveRegion.srcOffset.x = 0;
16837 resolveRegion.srcOffset.y = 0;
16838 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016839 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016840 resolveRegion.dstSubresource.mipLevel = 0;
16841 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016842 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016843 resolveRegion.dstOffset.x = 0;
16844 resolveRegion.dstOffset.y = 0;
16845 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016846 resolveRegion.extent.width = 1;
16847 resolveRegion.extent.height = 1;
16848 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016849 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016850 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016851
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016852 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016853
Chia-I Wuf7458c52015-10-26 21:10:41 +080016854 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016855 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016856 vkFreeMemory(m_device->device(), srcMem, NULL);
16857 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016858}
16859
Karl Schultz6addd812016-02-02 17:17:23 -070016860TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16861 VkResult err;
16862 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16865 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016866
Mike Stroyana3082432015-09-25 13:39:21 -060016867 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016868
Chris Forbesa7530692016-05-08 12:35:39 +120016869 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016870 VkImage srcImage;
16871 VkImage dstImage;
16872 VkDeviceMemory srcMem;
16873 VkDeviceMemory destMem;
16874 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016875
16876 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016877 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16878 image_create_info.pNext = NULL;
16879 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16880 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16881 image_create_info.extent.width = 32;
16882 image_create_info.extent.height = 1;
16883 image_create_info.extent.depth = 1;
16884 image_create_info.mipLevels = 1;
16885 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016886 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016887 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16888 // Note: Some implementations expect color attachment usage for any
16889 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016890 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016891 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016893 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016894 ASSERT_VK_SUCCESS(err);
16895
Karl Schultz6addd812016-02-02 17:17:23 -070016896 // Note: Some implementations expect color attachment usage for any
16897 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016898 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016900 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016901 ASSERT_VK_SUCCESS(err);
16902
16903 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016904 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016905 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16906 memAlloc.pNext = NULL;
16907 memAlloc.allocationSize = 0;
16908 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016909
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016910 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016911 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016912 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016913 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016914 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016915 ASSERT_VK_SUCCESS(err);
16916
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016917 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016918 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016919 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016920 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016921 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016922 ASSERT_VK_SUCCESS(err);
16923
16924 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16925 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016926 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016927 ASSERT_VK_SUCCESS(err);
16928
Tony Barbour552f6c02016-12-21 14:34:07 -070016929 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016930 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016931 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16932 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016933 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016934 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016935 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016936 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016937 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016938 resolveRegion.srcOffset.x = 0;
16939 resolveRegion.srcOffset.y = 0;
16940 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016941 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016942 resolveRegion.dstSubresource.mipLevel = 0;
16943 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016944 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016945 resolveRegion.dstOffset.x = 0;
16946 resolveRegion.dstOffset.y = 0;
16947 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016948 resolveRegion.extent.width = 1;
16949 resolveRegion.extent.height = 1;
16950 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016951 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016952 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016953
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016954 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016955
Chia-I Wuf7458c52015-10-26 21:10:41 +080016956 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016957 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016958 vkFreeMemory(m_device->device(), srcMem, NULL);
16959 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016960}
16961
Karl Schultz6addd812016-02-02 17:17:23 -070016962TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16963 VkResult err;
16964 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016965
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016967 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016968
Mike Stroyana3082432015-09-25 13:39:21 -060016969 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016970
16971 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016972 VkImage srcImage;
16973 VkImage dstImage;
16974 VkDeviceMemory srcMem;
16975 VkDeviceMemory destMem;
16976 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016977
16978 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016979 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16980 image_create_info.pNext = NULL;
16981 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16982 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16983 image_create_info.extent.width = 32;
16984 image_create_info.extent.height = 1;
16985 image_create_info.extent.depth = 1;
16986 image_create_info.mipLevels = 1;
16987 image_create_info.arrayLayers = 1;
16988 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16989 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16990 // Note: Some implementations expect color attachment usage for any
16991 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016992 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016993 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016994
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016995 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016996 ASSERT_VK_SUCCESS(err);
16997
Karl Schultz6addd812016-02-02 17:17:23 -070016998 // Set format to something other than source image
16999 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17000 // Note: Some implementations expect color attachment usage for any
17001 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017002 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017003 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017005 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017006 ASSERT_VK_SUCCESS(err);
17007
17008 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017009 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017010 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17011 memAlloc.pNext = NULL;
17012 memAlloc.allocationSize = 0;
17013 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017014
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017015 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017016 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017017 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017018 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017019 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017020 ASSERT_VK_SUCCESS(err);
17021
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017022 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017023 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017024 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017025 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017026 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017027 ASSERT_VK_SUCCESS(err);
17028
17029 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17030 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017031 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017032 ASSERT_VK_SUCCESS(err);
17033
Tony Barbour552f6c02016-12-21 14:34:07 -070017034 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017035 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017036 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17037 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017038 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017039 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017040 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017041 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017042 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017043 resolveRegion.srcOffset.x = 0;
17044 resolveRegion.srcOffset.y = 0;
17045 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017046 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017047 resolveRegion.dstSubresource.mipLevel = 0;
17048 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017049 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017050 resolveRegion.dstOffset.x = 0;
17051 resolveRegion.dstOffset.y = 0;
17052 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017053 resolveRegion.extent.width = 1;
17054 resolveRegion.extent.height = 1;
17055 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017056 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017057 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017058
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017059 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017060
Chia-I Wuf7458c52015-10-26 21:10:41 +080017061 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017062 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017063 vkFreeMemory(m_device->device(), srcMem, NULL);
17064 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017065}
17066
Karl Schultz6addd812016-02-02 17:17:23 -070017067TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17068 VkResult err;
17069 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017070
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017072 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017073
Mike Stroyana3082432015-09-25 13:39:21 -060017074 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017075
17076 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017077 VkImage srcImage;
17078 VkImage dstImage;
17079 VkDeviceMemory srcMem;
17080 VkDeviceMemory destMem;
17081 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017082
17083 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017084 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17085 image_create_info.pNext = NULL;
17086 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17087 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17088 image_create_info.extent.width = 32;
17089 image_create_info.extent.height = 1;
17090 image_create_info.extent.depth = 1;
17091 image_create_info.mipLevels = 1;
17092 image_create_info.arrayLayers = 1;
17093 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17094 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17095 // Note: Some implementations expect color attachment usage for any
17096 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017097 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017098 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017100 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017101 ASSERT_VK_SUCCESS(err);
17102
Karl Schultz6addd812016-02-02 17:17:23 -070017103 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17104 // Note: Some implementations expect color attachment usage for any
17105 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017106 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017107 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017109 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017110 ASSERT_VK_SUCCESS(err);
17111
17112 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017113 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017114 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17115 memAlloc.pNext = NULL;
17116 memAlloc.allocationSize = 0;
17117 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017118
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017119 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017120 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017121 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017122 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017123 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017124 ASSERT_VK_SUCCESS(err);
17125
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017126 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017127 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017128 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017129 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017130 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017131 ASSERT_VK_SUCCESS(err);
17132
17133 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17134 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017135 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017136 ASSERT_VK_SUCCESS(err);
17137
Tony Barbour552f6c02016-12-21 14:34:07 -070017138 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017139 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017140 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17141 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017142 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017143 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017144 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017145 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017146 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017147 resolveRegion.srcOffset.x = 0;
17148 resolveRegion.srcOffset.y = 0;
17149 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017150 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017151 resolveRegion.dstSubresource.mipLevel = 0;
17152 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017153 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017154 resolveRegion.dstOffset.x = 0;
17155 resolveRegion.dstOffset.y = 0;
17156 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017157 resolveRegion.extent.width = 1;
17158 resolveRegion.extent.height = 1;
17159 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017160 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017161 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017162
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017163 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017164
Chia-I Wuf7458c52015-10-26 21:10:41 +080017165 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017166 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017167 vkFreeMemory(m_device->device(), srcMem, NULL);
17168 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017169}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017170
Karl Schultz6addd812016-02-02 17:17:23 -070017171TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017172 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017173 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17174 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017175 // The image format check comes 2nd in validation so we trigger it first,
17176 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017177 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17180 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017181
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017182 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017183
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017184 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017185 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17186 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017187
17188 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017189 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17190 ds_pool_ci.pNext = NULL;
17191 ds_pool_ci.maxSets = 1;
17192 ds_pool_ci.poolSizeCount = 1;
17193 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017194
17195 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017196 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017197 ASSERT_VK_SUCCESS(err);
17198
17199 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017200 dsl_binding.binding = 0;
17201 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17202 dsl_binding.descriptorCount = 1;
17203 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17204 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017205
17206 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017207 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17208 ds_layout_ci.pNext = NULL;
17209 ds_layout_ci.bindingCount = 1;
17210 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017211 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017212 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017213 ASSERT_VK_SUCCESS(err);
17214
17215 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017216 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017217 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017218 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017219 alloc_info.descriptorPool = ds_pool;
17220 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017221 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017222 ASSERT_VK_SUCCESS(err);
17223
Karl Schultz6addd812016-02-02 17:17:23 -070017224 VkImage image_bad;
17225 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017226 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017227 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017228 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017229 const int32_t tex_width = 32;
17230 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017231
17232 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017233 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17234 image_create_info.pNext = NULL;
17235 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17236 image_create_info.format = tex_format_bad;
17237 image_create_info.extent.width = tex_width;
17238 image_create_info.extent.height = tex_height;
17239 image_create_info.extent.depth = 1;
17240 image_create_info.mipLevels = 1;
17241 image_create_info.arrayLayers = 1;
17242 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17243 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017244 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017245 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017247 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017248 ASSERT_VK_SUCCESS(err);
17249 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017250 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17251 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017252 ASSERT_VK_SUCCESS(err);
17253
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017254 // ---Bind image memory---
17255 VkMemoryRequirements img_mem_reqs;
17256 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17257 VkMemoryAllocateInfo image_alloc_info = {};
17258 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17259 image_alloc_info.pNext = NULL;
17260 image_alloc_info.memoryTypeIndex = 0;
17261 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017262 bool pass =
17263 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 -070017264 ASSERT_TRUE(pass);
17265 VkDeviceMemory mem;
17266 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17267 ASSERT_VK_SUCCESS(err);
17268 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17269 ASSERT_VK_SUCCESS(err);
17270 // -----------------------
17271
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017272 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017273 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017274 image_view_create_info.image = image_bad;
17275 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17276 image_view_create_info.format = tex_format_bad;
17277 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17278 image_view_create_info.subresourceRange.baseMipLevel = 0;
17279 image_view_create_info.subresourceRange.layerCount = 1;
17280 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017281 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017282
17283 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017284 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017285
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017286 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017287
Chia-I Wuf7458c52015-10-26 21:10:41 +080017288 vkDestroyImage(m_device->device(), image_bad, NULL);
17289 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017290 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17291 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017292
17293 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017294}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017295
17296TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017297 TEST_DESCRIPTION(
17298 "Call ClearColorImage w/ a depth|stencil image and "
17299 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017300
17301 ASSERT_NO_FATAL_FAILURE(InitState());
17302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17303
Tony Barbour552f6c02016-12-21 14:34:07 -070017304 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017305
17306 // Color image
17307 VkClearColorValue clear_color;
17308 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17309 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17310 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17311 const int32_t img_width = 32;
17312 const int32_t img_height = 32;
17313 VkImageCreateInfo image_create_info = {};
17314 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17315 image_create_info.pNext = NULL;
17316 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17317 image_create_info.format = color_format;
17318 image_create_info.extent.width = img_width;
17319 image_create_info.extent.height = img_height;
17320 image_create_info.extent.depth = 1;
17321 image_create_info.mipLevels = 1;
17322 image_create_info.arrayLayers = 1;
17323 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17324 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17325 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17326
17327 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017328 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017330 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017331
17332 // Depth/Stencil image
17333 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017334 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017335 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17336 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17337 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17338 ds_image_create_info.extent.width = 64;
17339 ds_image_create_info.extent.height = 64;
17340 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017341 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 -060017342
17343 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017344 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017346 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 -060017347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017350 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017351 &color_range);
17352
17353 m_errorMonitor->VerifyFound();
17354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17356 "vkCmdClearColorImage called with "
17357 "image created without "
17358 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017359
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017360 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017361 &color_range);
17362
17363 m_errorMonitor->VerifyFound();
17364
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017365 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17367 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017368
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017369 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17370 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017371
17372 m_errorMonitor->VerifyFound();
17373}
Tobin Ehliscde08892015-09-22 10:11:37 -060017374
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017375// WSI Enabled Tests
17376//
Chris Forbes09368e42016-10-13 11:59:22 +130017377#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017378TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17379
17380#if defined(VK_USE_PLATFORM_XCB_KHR)
17381 VkSurfaceKHR surface = VK_NULL_HANDLE;
17382
17383 VkResult err;
17384 bool pass;
17385 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17386 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17387 // uint32_t swapchain_image_count = 0;
17388 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17389 // uint32_t image_index = 0;
17390 // VkPresentInfoKHR present_info = {};
17391
17392 ASSERT_NO_FATAL_FAILURE(InitState());
17393
17394 // Use the create function from one of the VK_KHR_*_surface extension in
17395 // order to create a surface, testing all known errors in the process,
17396 // before successfully creating a surface:
17397 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17399 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17400 pass = (err != VK_SUCCESS);
17401 ASSERT_TRUE(pass);
17402 m_errorMonitor->VerifyFound();
17403
17404 // Next, try to create a surface with the wrong
17405 // VkXcbSurfaceCreateInfoKHR::sType:
17406 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17407 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17409 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17410 pass = (err != VK_SUCCESS);
17411 ASSERT_TRUE(pass);
17412 m_errorMonitor->VerifyFound();
17413
17414 // Create a native window, and then correctly create a surface:
17415 xcb_connection_t *connection;
17416 xcb_screen_t *screen;
17417 xcb_window_t xcb_window;
17418 xcb_intern_atom_reply_t *atom_wm_delete_window;
17419
17420 const xcb_setup_t *setup;
17421 xcb_screen_iterator_t iter;
17422 int scr;
17423 uint32_t value_mask, value_list[32];
17424 int width = 1;
17425 int height = 1;
17426
17427 connection = xcb_connect(NULL, &scr);
17428 ASSERT_TRUE(connection != NULL);
17429 setup = xcb_get_setup(connection);
17430 iter = xcb_setup_roots_iterator(setup);
17431 while (scr-- > 0)
17432 xcb_screen_next(&iter);
17433 screen = iter.data;
17434
17435 xcb_window = xcb_generate_id(connection);
17436
17437 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17438 value_list[0] = screen->black_pixel;
17439 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17440
17441 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17442 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17443
17444 /* Magic code that will send notification when window is destroyed */
17445 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17446 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17447
17448 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17449 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17450 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17451 free(reply);
17452
17453 xcb_map_window(connection, xcb_window);
17454
17455 // Force the x/y coordinates to 100,100 results are identical in consecutive
17456 // runs
17457 const uint32_t coords[] = { 100, 100 };
17458 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17459
17460 // Finally, try to correctly create a surface:
17461 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17462 xcb_create_info.pNext = NULL;
17463 xcb_create_info.flags = 0;
17464 xcb_create_info.connection = connection;
17465 xcb_create_info.window = xcb_window;
17466 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17467 pass = (err == VK_SUCCESS);
17468 ASSERT_TRUE(pass);
17469
17470 // Check if surface supports presentation:
17471
17472 // 1st, do so without having queried the queue families:
17473 VkBool32 supported = false;
17474 // TODO: Get the following error to come out:
17475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17476 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17477 "function");
17478 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17479 pass = (err != VK_SUCCESS);
17480 // ASSERT_TRUE(pass);
17481 // m_errorMonitor->VerifyFound();
17482
17483 // Next, query a queue family index that's too large:
17484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17485 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17486 pass = (err != VK_SUCCESS);
17487 ASSERT_TRUE(pass);
17488 m_errorMonitor->VerifyFound();
17489
17490 // Finally, do so correctly:
17491 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17492 // SUPPORTED
17493 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17494 pass = (err == VK_SUCCESS);
17495 ASSERT_TRUE(pass);
17496
17497 // Before proceeding, try to create a swapchain without having called
17498 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17499 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17500 swapchain_create_info.pNext = NULL;
17501 swapchain_create_info.flags = 0;
17502 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17503 swapchain_create_info.surface = surface;
17504 swapchain_create_info.imageArrayLayers = 1;
17505 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17506 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17508 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17509 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17510 pass = (err != VK_SUCCESS);
17511 ASSERT_TRUE(pass);
17512 m_errorMonitor->VerifyFound();
17513
17514 // Get the surface capabilities:
17515 VkSurfaceCapabilitiesKHR surface_capabilities;
17516
17517 // Do so correctly (only error logged by this entrypoint is if the
17518 // extension isn't enabled):
17519 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17520 pass = (err == VK_SUCCESS);
17521 ASSERT_TRUE(pass);
17522
17523 // Get the surface formats:
17524 uint32_t surface_format_count;
17525
17526 // First, try without a pointer to surface_format_count:
17527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17528 "specified as NULL");
17529 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17530 pass = (err == VK_SUCCESS);
17531 ASSERT_TRUE(pass);
17532 m_errorMonitor->VerifyFound();
17533
17534 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17535 // correctly done a 1st try (to get the count):
17536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17537 surface_format_count = 0;
17538 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17539 pass = (err == VK_SUCCESS);
17540 ASSERT_TRUE(pass);
17541 m_errorMonitor->VerifyFound();
17542
17543 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17544 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17545 pass = (err == VK_SUCCESS);
17546 ASSERT_TRUE(pass);
17547
17548 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17549 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17550
17551 // Next, do a 2nd try with surface_format_count being set too high:
17552 surface_format_count += 5;
17553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17554 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17555 pass = (err == VK_SUCCESS);
17556 ASSERT_TRUE(pass);
17557 m_errorMonitor->VerifyFound();
17558
17559 // Finally, do a correct 1st and 2nd try:
17560 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17561 pass = (err == VK_SUCCESS);
17562 ASSERT_TRUE(pass);
17563 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17564 pass = (err == VK_SUCCESS);
17565 ASSERT_TRUE(pass);
17566
17567 // Get the surface present modes:
17568 uint32_t surface_present_mode_count;
17569
17570 // First, try without a pointer to surface_format_count:
17571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17572 "specified as NULL");
17573
17574 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17575 pass = (err == VK_SUCCESS);
17576 ASSERT_TRUE(pass);
17577 m_errorMonitor->VerifyFound();
17578
17579 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17580 // correctly done a 1st try (to get the count):
17581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17582 surface_present_mode_count = 0;
17583 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17584 (VkPresentModeKHR *)&surface_present_mode_count);
17585 pass = (err == VK_SUCCESS);
17586 ASSERT_TRUE(pass);
17587 m_errorMonitor->VerifyFound();
17588
17589 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17590 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17591 pass = (err == VK_SUCCESS);
17592 ASSERT_TRUE(pass);
17593
17594 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17595 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17596
17597 // Next, do a 2nd try with surface_format_count being set too high:
17598 surface_present_mode_count += 5;
17599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17600 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17601 pass = (err == VK_SUCCESS);
17602 ASSERT_TRUE(pass);
17603 m_errorMonitor->VerifyFound();
17604
17605 // Finally, do a correct 1st and 2nd try:
17606 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17607 pass = (err == VK_SUCCESS);
17608 ASSERT_TRUE(pass);
17609 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17610 pass = (err == VK_SUCCESS);
17611 ASSERT_TRUE(pass);
17612
17613 // Create a swapchain:
17614
17615 // First, try without a pointer to swapchain_create_info:
17616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17617 "specified as NULL");
17618
17619 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17620 pass = (err != VK_SUCCESS);
17621 ASSERT_TRUE(pass);
17622 m_errorMonitor->VerifyFound();
17623
17624 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17625 // sType:
17626 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17628
17629 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17630 pass = (err != VK_SUCCESS);
17631 ASSERT_TRUE(pass);
17632 m_errorMonitor->VerifyFound();
17633
17634 // Next, call with a NULL swapchain pointer:
17635 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17636 swapchain_create_info.pNext = NULL;
17637 swapchain_create_info.flags = 0;
17638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17639 "specified as NULL");
17640
17641 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17642 pass = (err != VK_SUCCESS);
17643 ASSERT_TRUE(pass);
17644 m_errorMonitor->VerifyFound();
17645
17646 // TODO: Enhance swapchain layer so that
17647 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17648
17649 // Next, call with a queue family index that's too large:
17650 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17651 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17652 swapchain_create_info.queueFamilyIndexCount = 2;
17653 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17655 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17656 pass = (err != VK_SUCCESS);
17657 ASSERT_TRUE(pass);
17658 m_errorMonitor->VerifyFound();
17659
17660 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17661 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17662 swapchain_create_info.queueFamilyIndexCount = 1;
17663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17664 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17665 "pCreateInfo->pQueueFamilyIndices).");
17666 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17667 pass = (err != VK_SUCCESS);
17668 ASSERT_TRUE(pass);
17669 m_errorMonitor->VerifyFound();
17670
17671 // Next, call with an invalid imageSharingMode:
17672 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17673 swapchain_create_info.queueFamilyIndexCount = 1;
17674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17675 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17676 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17677 pass = (err != VK_SUCCESS);
17678 ASSERT_TRUE(pass);
17679 m_errorMonitor->VerifyFound();
17680 // Fix for the future:
17681 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17682 // SUPPORTED
17683 swapchain_create_info.queueFamilyIndexCount = 0;
17684 queueFamilyIndex[0] = 0;
17685 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17686
17687 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17688 // Get the images from a swapchain:
17689 // Acquire an image from a swapchain:
17690 // Present an image to a swapchain:
17691 // Destroy the swapchain:
17692
17693 // TODOs:
17694 //
17695 // - Try destroying the device without first destroying the swapchain
17696 //
17697 // - Try destroying the device without first destroying the surface
17698 //
17699 // - Try destroying the surface without first destroying the swapchain
17700
17701 // Destroy the surface:
17702 vkDestroySurfaceKHR(instance(), surface, NULL);
17703
17704 // Tear down the window:
17705 xcb_destroy_window(connection, xcb_window);
17706 xcb_disconnect(connection);
17707
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017708#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017709 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017710#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017711}
Chris Forbes09368e42016-10-13 11:59:22 +130017712#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017713
17714//
17715// POSITIVE VALIDATION TESTS
17716//
17717// These tests do not expect to encounter ANY validation errors pass only if this is true
17718
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070017719TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
17720 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
17721 ASSERT_NO_FATAL_FAILURE(InitState());
17722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17723
17724 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17725 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17726 command_buffer_allocate_info.commandPool = m_commandPool;
17727 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17728 command_buffer_allocate_info.commandBufferCount = 1;
17729
17730 VkCommandBuffer secondary_command_buffer;
17731 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17732 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17733 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17734 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17735 command_buffer_inheritance_info.renderPass = m_renderPass;
17736 command_buffer_inheritance_info.framebuffer = m_framebuffer;
17737
17738 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17739 command_buffer_begin_info.flags =
17740 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
17741 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17742
17743 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17744 VkClearAttachment color_attachment;
17745 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17746 color_attachment.clearValue.color.float32[0] = 0;
17747 color_attachment.clearValue.color.float32[1] = 0;
17748 color_attachment.clearValue.color.float32[2] = 0;
17749 color_attachment.clearValue.color.float32[3] = 0;
17750 color_attachment.colorAttachment = 0;
17751 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
17752 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
17753}
17754
Tobin Ehlise0006882016-11-03 10:14:28 -060017755TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017756 TEST_DESCRIPTION(
17757 "Perform an image layout transition in a secondary command buffer followed "
17758 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017759 VkResult err;
17760 m_errorMonitor->ExpectSuccess();
17761 ASSERT_NO_FATAL_FAILURE(InitState());
17762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17763 // Allocate a secondary and primary cmd buffer
17764 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17765 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17766 command_buffer_allocate_info.commandPool = m_commandPool;
17767 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17768 command_buffer_allocate_info.commandBufferCount = 1;
17769
17770 VkCommandBuffer secondary_command_buffer;
17771 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17772 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17773 VkCommandBuffer primary_command_buffer;
17774 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17775 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17776 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17777 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17778 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17779 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17780 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17781
17782 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17783 ASSERT_VK_SUCCESS(err);
17784 VkImageObj image(m_device);
17785 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17786 ASSERT_TRUE(image.initialized());
17787 VkImageMemoryBarrier img_barrier = {};
17788 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17789 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17790 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17791 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17792 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17793 img_barrier.image = image.handle();
17794 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17795 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17796 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17797 img_barrier.subresourceRange.baseArrayLayer = 0;
17798 img_barrier.subresourceRange.baseMipLevel = 0;
17799 img_barrier.subresourceRange.layerCount = 1;
17800 img_barrier.subresourceRange.levelCount = 1;
17801 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17802 0, nullptr, 1, &img_barrier);
17803 err = vkEndCommandBuffer(secondary_command_buffer);
17804 ASSERT_VK_SUCCESS(err);
17805
17806 // Now update primary cmd buffer to execute secondary and transitions image
17807 command_buffer_begin_info.pInheritanceInfo = nullptr;
17808 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17809 ASSERT_VK_SUCCESS(err);
17810 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17811 VkImageMemoryBarrier img_barrier2 = {};
17812 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17813 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17814 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17815 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17816 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17817 img_barrier2.image = image.handle();
17818 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17819 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17820 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17821 img_barrier2.subresourceRange.baseArrayLayer = 0;
17822 img_barrier2.subresourceRange.baseMipLevel = 0;
17823 img_barrier2.subresourceRange.layerCount = 1;
17824 img_barrier2.subresourceRange.levelCount = 1;
17825 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17826 nullptr, 1, &img_barrier2);
17827 err = vkEndCommandBuffer(primary_command_buffer);
17828 ASSERT_VK_SUCCESS(err);
17829 VkSubmitInfo submit_info = {};
17830 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17831 submit_info.commandBufferCount = 1;
17832 submit_info.pCommandBuffers = &primary_command_buffer;
17833 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17834 ASSERT_VK_SUCCESS(err);
17835 m_errorMonitor->VerifyNotFound();
17836 err = vkDeviceWaitIdle(m_device->device());
17837 ASSERT_VK_SUCCESS(err);
17838 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17839 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17840}
17841
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017842// This is a positive test. No failures are expected.
17843TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017844 TEST_DESCRIPTION(
17845 "Ensure that the vkUpdateDescriptorSets validation code "
17846 "is ignoring VkWriteDescriptorSet members that are not "
17847 "related to the descriptor type specified by "
17848 "VkWriteDescriptorSet::descriptorType. Correct "
17849 "validation behavior will result in the test running to "
17850 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017851
17852 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17853
17854 ASSERT_NO_FATAL_FAILURE(InitState());
17855
17856 // Image Case
17857 {
17858 m_errorMonitor->ExpectSuccess();
17859
17860 VkImage image;
17861 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17862 const int32_t tex_width = 32;
17863 const int32_t tex_height = 32;
17864 VkImageCreateInfo image_create_info = {};
17865 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17866 image_create_info.pNext = NULL;
17867 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17868 image_create_info.format = tex_format;
17869 image_create_info.extent.width = tex_width;
17870 image_create_info.extent.height = tex_height;
17871 image_create_info.extent.depth = 1;
17872 image_create_info.mipLevels = 1;
17873 image_create_info.arrayLayers = 1;
17874 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17875 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17876 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17877 image_create_info.flags = 0;
17878 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17879 ASSERT_VK_SUCCESS(err);
17880
17881 VkMemoryRequirements memory_reqs;
17882 VkDeviceMemory image_memory;
17883 bool pass;
17884 VkMemoryAllocateInfo memory_info = {};
17885 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17886 memory_info.pNext = NULL;
17887 memory_info.allocationSize = 0;
17888 memory_info.memoryTypeIndex = 0;
17889 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17890 memory_info.allocationSize = memory_reqs.size;
17891 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17892 ASSERT_TRUE(pass);
17893 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17894 ASSERT_VK_SUCCESS(err);
17895 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17896 ASSERT_VK_SUCCESS(err);
17897
17898 VkImageViewCreateInfo image_view_create_info = {};
17899 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17900 image_view_create_info.image = image;
17901 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17902 image_view_create_info.format = tex_format;
17903 image_view_create_info.subresourceRange.layerCount = 1;
17904 image_view_create_info.subresourceRange.baseMipLevel = 0;
17905 image_view_create_info.subresourceRange.levelCount = 1;
17906 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17907
17908 VkImageView view;
17909 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17910 ASSERT_VK_SUCCESS(err);
17911
17912 VkDescriptorPoolSize ds_type_count = {};
17913 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17914 ds_type_count.descriptorCount = 1;
17915
17916 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17917 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17918 ds_pool_ci.pNext = NULL;
17919 ds_pool_ci.maxSets = 1;
17920 ds_pool_ci.poolSizeCount = 1;
17921 ds_pool_ci.pPoolSizes = &ds_type_count;
17922
17923 VkDescriptorPool ds_pool;
17924 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17925 ASSERT_VK_SUCCESS(err);
17926
17927 VkDescriptorSetLayoutBinding dsl_binding = {};
17928 dsl_binding.binding = 0;
17929 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17930 dsl_binding.descriptorCount = 1;
17931 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17932 dsl_binding.pImmutableSamplers = NULL;
17933
17934 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17935 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17936 ds_layout_ci.pNext = NULL;
17937 ds_layout_ci.bindingCount = 1;
17938 ds_layout_ci.pBindings = &dsl_binding;
17939 VkDescriptorSetLayout ds_layout;
17940 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17941 ASSERT_VK_SUCCESS(err);
17942
17943 VkDescriptorSet descriptor_set;
17944 VkDescriptorSetAllocateInfo alloc_info = {};
17945 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17946 alloc_info.descriptorSetCount = 1;
17947 alloc_info.descriptorPool = ds_pool;
17948 alloc_info.pSetLayouts = &ds_layout;
17949 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17950 ASSERT_VK_SUCCESS(err);
17951
17952 VkDescriptorImageInfo image_info = {};
17953 image_info.imageView = view;
17954 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17955
17956 VkWriteDescriptorSet descriptor_write;
17957 memset(&descriptor_write, 0, sizeof(descriptor_write));
17958 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17959 descriptor_write.dstSet = descriptor_set;
17960 descriptor_write.dstBinding = 0;
17961 descriptor_write.descriptorCount = 1;
17962 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17963 descriptor_write.pImageInfo = &image_info;
17964
17965 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17966 // be
17967 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17968 // This will most likely produce a crash if the parameter_validation
17969 // layer
17970 // does not correctly ignore pBufferInfo.
17971 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17972 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17973
17974 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17975
17976 m_errorMonitor->VerifyNotFound();
17977
17978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17980 vkDestroyImageView(m_device->device(), view, NULL);
17981 vkDestroyImage(m_device->device(), image, NULL);
17982 vkFreeMemory(m_device->device(), image_memory, NULL);
17983 }
17984
17985 // Buffer Case
17986 {
17987 m_errorMonitor->ExpectSuccess();
17988
17989 VkBuffer buffer;
17990 uint32_t queue_family_index = 0;
17991 VkBufferCreateInfo buffer_create_info = {};
17992 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17993 buffer_create_info.size = 1024;
17994 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17995 buffer_create_info.queueFamilyIndexCount = 1;
17996 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17997
17998 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17999 ASSERT_VK_SUCCESS(err);
18000
18001 VkMemoryRequirements memory_reqs;
18002 VkDeviceMemory buffer_memory;
18003 bool pass;
18004 VkMemoryAllocateInfo memory_info = {};
18005 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18006 memory_info.pNext = NULL;
18007 memory_info.allocationSize = 0;
18008 memory_info.memoryTypeIndex = 0;
18009
18010 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18011 memory_info.allocationSize = memory_reqs.size;
18012 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18013 ASSERT_TRUE(pass);
18014
18015 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18016 ASSERT_VK_SUCCESS(err);
18017 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18018 ASSERT_VK_SUCCESS(err);
18019
18020 VkDescriptorPoolSize ds_type_count = {};
18021 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18022 ds_type_count.descriptorCount = 1;
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 VkDescriptorSetLayoutBinding dsl_binding = {};
18036 dsl_binding.binding = 0;
18037 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18038 dsl_binding.descriptorCount = 1;
18039 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18040 dsl_binding.pImmutableSamplers = NULL;
18041
18042 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18043 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18044 ds_layout_ci.pNext = NULL;
18045 ds_layout_ci.bindingCount = 1;
18046 ds_layout_ci.pBindings = &dsl_binding;
18047 VkDescriptorSetLayout ds_layout;
18048 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18049 ASSERT_VK_SUCCESS(err);
18050
18051 VkDescriptorSet descriptor_set;
18052 VkDescriptorSetAllocateInfo alloc_info = {};
18053 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18054 alloc_info.descriptorSetCount = 1;
18055 alloc_info.descriptorPool = ds_pool;
18056 alloc_info.pSetLayouts = &ds_layout;
18057 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18058 ASSERT_VK_SUCCESS(err);
18059
18060 VkDescriptorBufferInfo buffer_info = {};
18061 buffer_info.buffer = buffer;
18062 buffer_info.offset = 0;
18063 buffer_info.range = 1024;
18064
18065 VkWriteDescriptorSet descriptor_write;
18066 memset(&descriptor_write, 0, sizeof(descriptor_write));
18067 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18068 descriptor_write.dstSet = descriptor_set;
18069 descriptor_write.dstBinding = 0;
18070 descriptor_write.descriptorCount = 1;
18071 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18072 descriptor_write.pBufferInfo = &buffer_info;
18073
18074 // Set pImageInfo and pTexelBufferView to invalid values, which should
18075 // be
18076 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18077 // This will most likely produce a crash if the parameter_validation
18078 // layer
18079 // does not correctly ignore pImageInfo.
18080 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18081 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18082
18083 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18084
18085 m_errorMonitor->VerifyNotFound();
18086
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018087 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18088 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18089 vkDestroyBuffer(m_device->device(), buffer, NULL);
18090 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18091 }
18092
18093 // Texel Buffer Case
18094 {
18095 m_errorMonitor->ExpectSuccess();
18096
18097 VkBuffer buffer;
18098 uint32_t queue_family_index = 0;
18099 VkBufferCreateInfo buffer_create_info = {};
18100 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18101 buffer_create_info.size = 1024;
18102 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18103 buffer_create_info.queueFamilyIndexCount = 1;
18104 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18105
18106 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18107 ASSERT_VK_SUCCESS(err);
18108
18109 VkMemoryRequirements memory_reqs;
18110 VkDeviceMemory buffer_memory;
18111 bool pass;
18112 VkMemoryAllocateInfo memory_info = {};
18113 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18114 memory_info.pNext = NULL;
18115 memory_info.allocationSize = 0;
18116 memory_info.memoryTypeIndex = 0;
18117
18118 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18119 memory_info.allocationSize = memory_reqs.size;
18120 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18121 ASSERT_TRUE(pass);
18122
18123 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18124 ASSERT_VK_SUCCESS(err);
18125 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18126 ASSERT_VK_SUCCESS(err);
18127
18128 VkBufferViewCreateInfo buff_view_ci = {};
18129 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18130 buff_view_ci.buffer = buffer;
18131 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18132 buff_view_ci.range = VK_WHOLE_SIZE;
18133 VkBufferView buffer_view;
18134 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18135
18136 VkDescriptorPoolSize ds_type_count = {};
18137 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18138 ds_type_count.descriptorCount = 1;
18139
18140 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18141 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18142 ds_pool_ci.pNext = NULL;
18143 ds_pool_ci.maxSets = 1;
18144 ds_pool_ci.poolSizeCount = 1;
18145 ds_pool_ci.pPoolSizes = &ds_type_count;
18146
18147 VkDescriptorPool ds_pool;
18148 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18149 ASSERT_VK_SUCCESS(err);
18150
18151 VkDescriptorSetLayoutBinding dsl_binding = {};
18152 dsl_binding.binding = 0;
18153 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18154 dsl_binding.descriptorCount = 1;
18155 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18156 dsl_binding.pImmutableSamplers = NULL;
18157
18158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18160 ds_layout_ci.pNext = NULL;
18161 ds_layout_ci.bindingCount = 1;
18162 ds_layout_ci.pBindings = &dsl_binding;
18163 VkDescriptorSetLayout ds_layout;
18164 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18165 ASSERT_VK_SUCCESS(err);
18166
18167 VkDescriptorSet descriptor_set;
18168 VkDescriptorSetAllocateInfo alloc_info = {};
18169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18170 alloc_info.descriptorSetCount = 1;
18171 alloc_info.descriptorPool = ds_pool;
18172 alloc_info.pSetLayouts = &ds_layout;
18173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18174 ASSERT_VK_SUCCESS(err);
18175
18176 VkWriteDescriptorSet descriptor_write;
18177 memset(&descriptor_write, 0, sizeof(descriptor_write));
18178 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18179 descriptor_write.dstSet = descriptor_set;
18180 descriptor_write.dstBinding = 0;
18181 descriptor_write.descriptorCount = 1;
18182 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18183 descriptor_write.pTexelBufferView = &buffer_view;
18184
18185 // Set pImageInfo and pBufferInfo to invalid values, which should be
18186 // ignored for descriptorType ==
18187 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18188 // This will most likely produce a crash if the parameter_validation
18189 // layer
18190 // does not correctly ignore pImageInfo and pBufferInfo.
18191 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18192 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18193
18194 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18195
18196 m_errorMonitor->VerifyNotFound();
18197
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018198 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18199 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18200 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18201 vkDestroyBuffer(m_device->device(), buffer, NULL);
18202 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18203 }
18204}
18205
Tobin Ehlisf7428442016-10-25 07:58:24 -060018206TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18207 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18208
18209 ASSERT_NO_FATAL_FAILURE(InitState());
18210 // Create layout where two binding #s are "1"
18211 static const uint32_t NUM_BINDINGS = 3;
18212 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18213 dsl_binding[0].binding = 1;
18214 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18215 dsl_binding[0].descriptorCount = 1;
18216 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18217 dsl_binding[0].pImmutableSamplers = NULL;
18218 dsl_binding[1].binding = 0;
18219 dsl_binding[1].descriptorCount = 1;
18220 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18221 dsl_binding[1].descriptorCount = 1;
18222 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18223 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018224 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018225 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18226 dsl_binding[2].descriptorCount = 1;
18227 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18228 dsl_binding[2].pImmutableSamplers = NULL;
18229
18230 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18231 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18232 ds_layout_ci.pNext = NULL;
18233 ds_layout_ci.bindingCount = NUM_BINDINGS;
18234 ds_layout_ci.pBindings = dsl_binding;
18235 VkDescriptorSetLayout ds_layout;
18236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18237 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18238 m_errorMonitor->VerifyFound();
18239}
18240
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018241TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018242 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18243
18244 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018245
Tony Barbour552f6c02016-12-21 14:34:07 -070018246 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018247
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018248 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18249
18250 {
18251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18252 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18253 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18254 m_errorMonitor->VerifyFound();
18255 }
18256
18257 {
18258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18259 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18260 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18261 m_errorMonitor->VerifyFound();
18262 }
18263
18264 {
18265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18266 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18267 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18268 m_errorMonitor->VerifyFound();
18269 }
18270
18271 {
18272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18273 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18274 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18275 m_errorMonitor->VerifyFound();
18276 }
18277
18278 {
18279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18280 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18281 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18282 m_errorMonitor->VerifyFound();
18283 }
18284
18285 {
18286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18287 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18288 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18289 m_errorMonitor->VerifyFound();
18290 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018291
18292 {
18293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18294 VkRect2D scissor = {{-1, 0}, {16, 16}};
18295 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18296 m_errorMonitor->VerifyFound();
18297 }
18298
18299 {
18300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18301 VkRect2D scissor = {{0, -2}, {16, 16}};
18302 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18303 m_errorMonitor->VerifyFound();
18304 }
18305
18306 {
18307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18308 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18309 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18310 m_errorMonitor->VerifyFound();
18311 }
18312
18313 {
18314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18315 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18316 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18317 m_errorMonitor->VerifyFound();
18318 }
18319
Tony Barbour552f6c02016-12-21 14:34:07 -070018320 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018321}
18322
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018323// This is a positive test. No failures are expected.
18324TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18325 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18326 VkResult err;
18327
18328 ASSERT_NO_FATAL_FAILURE(InitState());
18329 m_errorMonitor->ExpectSuccess();
18330 VkDescriptorPoolSize ds_type_count = {};
18331 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18332 ds_type_count.descriptorCount = 2;
18333
18334 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18335 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18336 ds_pool_ci.pNext = NULL;
18337 ds_pool_ci.maxSets = 1;
18338 ds_pool_ci.poolSizeCount = 1;
18339 ds_pool_ci.pPoolSizes = &ds_type_count;
18340
18341 VkDescriptorPool ds_pool;
18342 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18343 ASSERT_VK_SUCCESS(err);
18344
18345 // Create layout with two uniform buffer descriptors w/ empty binding between them
18346 static const uint32_t NUM_BINDINGS = 3;
18347 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18348 dsl_binding[0].binding = 0;
18349 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18350 dsl_binding[0].descriptorCount = 1;
18351 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18352 dsl_binding[0].pImmutableSamplers = NULL;
18353 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018354 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018355 dsl_binding[2].binding = 2;
18356 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18357 dsl_binding[2].descriptorCount = 1;
18358 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18359 dsl_binding[2].pImmutableSamplers = NULL;
18360
18361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18363 ds_layout_ci.pNext = NULL;
18364 ds_layout_ci.bindingCount = NUM_BINDINGS;
18365 ds_layout_ci.pBindings = dsl_binding;
18366 VkDescriptorSetLayout ds_layout;
18367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18368 ASSERT_VK_SUCCESS(err);
18369
18370 VkDescriptorSet descriptor_set = {};
18371 VkDescriptorSetAllocateInfo alloc_info = {};
18372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18373 alloc_info.descriptorSetCount = 1;
18374 alloc_info.descriptorPool = ds_pool;
18375 alloc_info.pSetLayouts = &ds_layout;
18376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18377 ASSERT_VK_SUCCESS(err);
18378
18379 // Create a buffer to be used for update
18380 VkBufferCreateInfo buff_ci = {};
18381 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18382 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18383 buff_ci.size = 256;
18384 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18385 VkBuffer buffer;
18386 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18387 ASSERT_VK_SUCCESS(err);
18388 // Have to bind memory to buffer before descriptor update
18389 VkMemoryAllocateInfo mem_alloc = {};
18390 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18391 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018392 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018393 mem_alloc.memoryTypeIndex = 0;
18394
18395 VkMemoryRequirements mem_reqs;
18396 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18397 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18398 if (!pass) {
18399 vkDestroyBuffer(m_device->device(), buffer, NULL);
18400 return;
18401 }
18402
18403 VkDeviceMemory mem;
18404 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18405 ASSERT_VK_SUCCESS(err);
18406 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18407 ASSERT_VK_SUCCESS(err);
18408
18409 // Only update the descriptor at binding 2
18410 VkDescriptorBufferInfo buff_info = {};
18411 buff_info.buffer = buffer;
18412 buff_info.offset = 0;
18413 buff_info.range = VK_WHOLE_SIZE;
18414 VkWriteDescriptorSet descriptor_write = {};
18415 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18416 descriptor_write.dstBinding = 2;
18417 descriptor_write.descriptorCount = 1;
18418 descriptor_write.pTexelBufferView = nullptr;
18419 descriptor_write.pBufferInfo = &buff_info;
18420 descriptor_write.pImageInfo = nullptr;
18421 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18422 descriptor_write.dstSet = descriptor_set;
18423
18424 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18425
18426 m_errorMonitor->VerifyNotFound();
18427 // Cleanup
18428 vkFreeMemory(m_device->device(), mem, NULL);
18429 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18430 vkDestroyBuffer(m_device->device(), buffer, NULL);
18431 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18432}
18433
18434// This is a positive test. No failures are expected.
18435TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18436 VkResult err;
18437 bool pass;
18438
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018439 TEST_DESCRIPTION(
18440 "Create a buffer, allocate memory, bind memory, destroy "
18441 "the buffer, create an image, and bind the same memory to "
18442 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018443
18444 m_errorMonitor->ExpectSuccess();
18445
18446 ASSERT_NO_FATAL_FAILURE(InitState());
18447
18448 VkBuffer buffer;
18449 VkImage image;
18450 VkDeviceMemory mem;
18451 VkMemoryRequirements mem_reqs;
18452
18453 VkBufferCreateInfo buf_info = {};
18454 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18455 buf_info.pNext = NULL;
18456 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18457 buf_info.size = 256;
18458 buf_info.queueFamilyIndexCount = 0;
18459 buf_info.pQueueFamilyIndices = NULL;
18460 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18461 buf_info.flags = 0;
18462 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18463 ASSERT_VK_SUCCESS(err);
18464
18465 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18466
18467 VkMemoryAllocateInfo alloc_info = {};
18468 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18469 alloc_info.pNext = NULL;
18470 alloc_info.memoryTypeIndex = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070018471
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018472 // Ensure memory is big enough for both bindings
18473 alloc_info.allocationSize = 0x10000;
18474
18475 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18476 if (!pass) {
18477 vkDestroyBuffer(m_device->device(), buffer, NULL);
18478 return;
18479 }
18480
18481 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18482 ASSERT_VK_SUCCESS(err);
18483
18484 uint8_t *pData;
18485 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18486 ASSERT_VK_SUCCESS(err);
18487
18488 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18489
18490 vkUnmapMemory(m_device->device(), mem);
18491
18492 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18493 ASSERT_VK_SUCCESS(err);
18494
18495 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18496 // memory. In fact, it was never used by the GPU.
18497 // Just be be sure, wait for idle.
18498 vkDestroyBuffer(m_device->device(), buffer, NULL);
18499 vkDeviceWaitIdle(m_device->device());
18500
Tobin Ehlis6a005702016-12-28 15:25:56 -070018501 // Use optimal as some platforms report linear support but then fail image creation
18502 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18503 VkImageFormatProperties image_format_properties;
18504 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18505 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18506 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018507 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018508 vkFreeMemory(m_device->device(), mem, NULL);
18509 return;
18510 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018511 VkImageCreateInfo image_create_info = {};
18512 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18513 image_create_info.pNext = NULL;
18514 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18515 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18516 image_create_info.extent.width = 64;
18517 image_create_info.extent.height = 64;
18518 image_create_info.extent.depth = 1;
18519 image_create_info.mipLevels = 1;
18520 image_create_info.arrayLayers = 1;
18521 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018522 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018523 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18524 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18525 image_create_info.queueFamilyIndexCount = 0;
18526 image_create_info.pQueueFamilyIndices = NULL;
18527 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18528 image_create_info.flags = 0;
18529
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018530 /* Create a mappable image. It will be the texture if linear images are ok
18531 * to be textures or it will be the staging image if they are not.
18532 */
18533 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18534 ASSERT_VK_SUCCESS(err);
18535
18536 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18537
Tobin Ehlis6a005702016-12-28 15:25:56 -070018538 VkMemoryAllocateInfo mem_alloc = {};
18539 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18540 mem_alloc.pNext = NULL;
18541 mem_alloc.allocationSize = 0;
18542 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018543 mem_alloc.allocationSize = mem_reqs.size;
18544
18545 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18546 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018547 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018548 vkDestroyImage(m_device->device(), image, NULL);
18549 return;
18550 }
18551
18552 // VALIDATION FAILURE:
18553 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18554 ASSERT_VK_SUCCESS(err);
18555
18556 m_errorMonitor->VerifyNotFound();
18557
18558 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018559 vkDestroyImage(m_device->device(), image, NULL);
18560}
18561
Tony Barbourab713912017-02-02 14:17:35 -070018562// This is a positive test. No failures are expected.
18563TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18564 VkResult err;
18565
18566 TEST_DESCRIPTION(
18567 "Call all applicable destroy and free routines with NULL"
18568 "handles, expecting no validation errors");
18569
18570 m_errorMonitor->ExpectSuccess();
18571
18572 ASSERT_NO_FATAL_FAILURE(InitState());
18573 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18574 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18575 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18576 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18577 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18578 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18579 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18580 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18581 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18582 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18583 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18584 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18585 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18586 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18587 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18588 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18589 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18590 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18591 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18592 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18593
18594 VkCommandPool command_pool;
18595 VkCommandPoolCreateInfo pool_create_info{};
18596 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18597 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18598 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18599 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18600 VkCommandBuffer command_buffers[3] = {};
18601 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18602 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18603 command_buffer_allocate_info.commandPool = command_pool;
18604 command_buffer_allocate_info.commandBufferCount = 1;
18605 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18606 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18607 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18608 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18609
18610 VkDescriptorPoolSize ds_type_count = {};
18611 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18612 ds_type_count.descriptorCount = 1;
18613
18614 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18615 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18616 ds_pool_ci.pNext = NULL;
18617 ds_pool_ci.maxSets = 1;
18618 ds_pool_ci.poolSizeCount = 1;
18619 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18620 ds_pool_ci.pPoolSizes = &ds_type_count;
18621
18622 VkDescriptorPool ds_pool;
18623 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18624 ASSERT_VK_SUCCESS(err);
18625
18626 VkDescriptorSetLayoutBinding dsl_binding = {};
18627 dsl_binding.binding = 2;
18628 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18629 dsl_binding.descriptorCount = 1;
18630 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18631 dsl_binding.pImmutableSamplers = NULL;
18632 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18633 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18634 ds_layout_ci.pNext = NULL;
18635 ds_layout_ci.bindingCount = 1;
18636 ds_layout_ci.pBindings = &dsl_binding;
18637 VkDescriptorSetLayout ds_layout;
18638 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18639 ASSERT_VK_SUCCESS(err);
18640
18641 VkDescriptorSet descriptor_sets[3] = {};
18642 VkDescriptorSetAllocateInfo alloc_info = {};
18643 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18644 alloc_info.descriptorSetCount = 1;
18645 alloc_info.descriptorPool = ds_pool;
18646 alloc_info.pSetLayouts = &ds_layout;
18647 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18648 ASSERT_VK_SUCCESS(err);
18649 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18650 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18651 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18652
18653 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18654
18655 m_errorMonitor->VerifyNotFound();
18656}
18657
Tony Barbour626994c2017-02-08 15:29:37 -070018658TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018659 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018660
18661 m_errorMonitor->ExpectSuccess();
18662
18663 ASSERT_NO_FATAL_FAILURE(InitState());
18664 VkCommandBuffer cmd_bufs[4];
18665 VkCommandBufferAllocateInfo alloc_info;
18666 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18667 alloc_info.pNext = NULL;
18668 alloc_info.commandBufferCount = 4;
18669 alloc_info.commandPool = m_commandPool;
18670 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18671 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18672 VkImageObj image(m_device);
18673 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18674 ASSERT_TRUE(image.initialized());
18675 VkCommandBufferBeginInfo cb_binfo;
18676 cb_binfo.pNext = NULL;
18677 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18678 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18679 cb_binfo.flags = 0;
18680 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18681 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18682 VkImageMemoryBarrier img_barrier = {};
18683 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18684 img_barrier.pNext = NULL;
18685 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18686 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18687 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18688 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18689 img_barrier.image = image.handle();
18690 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18691 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18692 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18693 img_barrier.subresourceRange.baseArrayLayer = 0;
18694 img_barrier.subresourceRange.baseMipLevel = 0;
18695 img_barrier.subresourceRange.layerCount = 1;
18696 img_barrier.subresourceRange.levelCount = 1;
18697 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18698 &img_barrier);
18699 vkEndCommandBuffer(cmd_bufs[0]);
18700 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18701 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18702 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18703 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18704 &img_barrier);
18705 vkEndCommandBuffer(cmd_bufs[1]);
18706 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18707 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18708 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18709 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18710 &img_barrier);
18711 vkEndCommandBuffer(cmd_bufs[2]);
18712 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18713 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18714 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18715 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18716 &img_barrier);
18717 vkEndCommandBuffer(cmd_bufs[3]);
18718
18719 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18720 VkSemaphore semaphore1, semaphore2;
18721 VkSemaphoreCreateInfo semaphore_create_info{};
18722 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18723 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18724 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18725 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18726 VkSubmitInfo submit_info[3];
18727 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18728 submit_info[0].pNext = nullptr;
18729 submit_info[0].commandBufferCount = 1;
18730 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18731 submit_info[0].signalSemaphoreCount = 1;
18732 submit_info[0].pSignalSemaphores = &semaphore1;
18733 submit_info[0].waitSemaphoreCount = 0;
18734 submit_info[0].pWaitDstStageMask = nullptr;
18735 submit_info[0].pWaitDstStageMask = flags;
18736 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18737 submit_info[1].pNext = nullptr;
18738 submit_info[1].commandBufferCount = 1;
18739 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18740 submit_info[1].waitSemaphoreCount = 1;
18741 submit_info[1].pWaitSemaphores = &semaphore1;
18742 submit_info[1].signalSemaphoreCount = 1;
18743 submit_info[1].pSignalSemaphores = &semaphore2;
18744 submit_info[1].pWaitDstStageMask = flags;
18745 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18746 submit_info[2].pNext = nullptr;
18747 submit_info[2].commandBufferCount = 2;
18748 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18749 submit_info[2].waitSemaphoreCount = 1;
18750 submit_info[2].pWaitSemaphores = &semaphore2;
18751 submit_info[2].signalSemaphoreCount = 0;
18752 submit_info[2].pSignalSemaphores = nullptr;
18753 submit_info[2].pWaitDstStageMask = flags;
18754 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18755 vkQueueWaitIdle(m_device->m_queue);
18756
18757 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18758 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18759 m_errorMonitor->VerifyNotFound();
18760}
18761
Tobin Ehlis953e8392016-11-17 10:54:13 -070018762TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18763 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18764 // We previously had a bug where dynamic offset of inactive bindings was still being used
18765 VkResult err;
18766 m_errorMonitor->ExpectSuccess();
18767
18768 ASSERT_NO_FATAL_FAILURE(InitState());
18769 ASSERT_NO_FATAL_FAILURE(InitViewport());
18770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18771
18772 VkDescriptorPoolSize ds_type_count = {};
18773 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18774 ds_type_count.descriptorCount = 3;
18775
18776 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18777 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18778 ds_pool_ci.pNext = NULL;
18779 ds_pool_ci.maxSets = 1;
18780 ds_pool_ci.poolSizeCount = 1;
18781 ds_pool_ci.pPoolSizes = &ds_type_count;
18782
18783 VkDescriptorPool ds_pool;
18784 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18785 ASSERT_VK_SUCCESS(err);
18786
18787 const uint32_t BINDING_COUNT = 3;
18788 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018789 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018790 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18791 dsl_binding[0].descriptorCount = 1;
18792 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18793 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018794 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018795 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18796 dsl_binding[1].descriptorCount = 1;
18797 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18798 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018799 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018800 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18801 dsl_binding[2].descriptorCount = 1;
18802 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18803 dsl_binding[2].pImmutableSamplers = NULL;
18804
18805 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18806 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18807 ds_layout_ci.pNext = NULL;
18808 ds_layout_ci.bindingCount = BINDING_COUNT;
18809 ds_layout_ci.pBindings = dsl_binding;
18810 VkDescriptorSetLayout ds_layout;
18811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18812 ASSERT_VK_SUCCESS(err);
18813
18814 VkDescriptorSet descriptor_set;
18815 VkDescriptorSetAllocateInfo alloc_info = {};
18816 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18817 alloc_info.descriptorSetCount = 1;
18818 alloc_info.descriptorPool = ds_pool;
18819 alloc_info.pSetLayouts = &ds_layout;
18820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18821 ASSERT_VK_SUCCESS(err);
18822
18823 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18824 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18825 pipeline_layout_ci.pNext = NULL;
18826 pipeline_layout_ci.setLayoutCount = 1;
18827 pipeline_layout_ci.pSetLayouts = &ds_layout;
18828
18829 VkPipelineLayout pipeline_layout;
18830 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18831 ASSERT_VK_SUCCESS(err);
18832
18833 // Create two buffers to update the descriptors with
18834 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18835 uint32_t qfi = 0;
18836 VkBufferCreateInfo buffCI = {};
18837 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18838 buffCI.size = 2048;
18839 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18840 buffCI.queueFamilyIndexCount = 1;
18841 buffCI.pQueueFamilyIndices = &qfi;
18842
18843 VkBuffer dyub1;
18844 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18845 ASSERT_VK_SUCCESS(err);
18846 // buffer2
18847 buffCI.size = 1024;
18848 VkBuffer dyub2;
18849 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18850 ASSERT_VK_SUCCESS(err);
18851 // Allocate memory and bind to buffers
18852 VkMemoryAllocateInfo mem_alloc[2] = {};
18853 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18854 mem_alloc[0].pNext = NULL;
18855 mem_alloc[0].memoryTypeIndex = 0;
18856 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18857 mem_alloc[1].pNext = NULL;
18858 mem_alloc[1].memoryTypeIndex = 0;
18859
18860 VkMemoryRequirements mem_reqs1;
18861 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18862 VkMemoryRequirements mem_reqs2;
18863 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18864 mem_alloc[0].allocationSize = mem_reqs1.size;
18865 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18866 mem_alloc[1].allocationSize = mem_reqs2.size;
18867 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18868 if (!pass) {
18869 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18870 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18871 return;
18872 }
18873
18874 VkDeviceMemory mem1;
18875 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18876 ASSERT_VK_SUCCESS(err);
18877 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18878 ASSERT_VK_SUCCESS(err);
18879 VkDeviceMemory mem2;
18880 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18881 ASSERT_VK_SUCCESS(err);
18882 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18883 ASSERT_VK_SUCCESS(err);
18884 // Update descriptors
18885 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18886 buff_info[0].buffer = dyub1;
18887 buff_info[0].offset = 0;
18888 buff_info[0].range = 256;
18889 buff_info[1].buffer = dyub1;
18890 buff_info[1].offset = 256;
18891 buff_info[1].range = 512;
18892 buff_info[2].buffer = dyub2;
18893 buff_info[2].offset = 0;
18894 buff_info[2].range = 512;
18895
18896 VkWriteDescriptorSet descriptor_write;
18897 memset(&descriptor_write, 0, sizeof(descriptor_write));
18898 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18899 descriptor_write.dstSet = descriptor_set;
18900 descriptor_write.dstBinding = 0;
18901 descriptor_write.descriptorCount = BINDING_COUNT;
18902 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18903 descriptor_write.pBufferInfo = buff_info;
18904
18905 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18906
Tony Barbour552f6c02016-12-21 14:34:07 -070018907 m_commandBuffer->BeginCommandBuffer();
18908 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018909
18910 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018911 char const *vsSource =
18912 "#version 450\n"
18913 "\n"
18914 "out gl_PerVertex { \n"
18915 " vec4 gl_Position;\n"
18916 "};\n"
18917 "void main(){\n"
18918 " gl_Position = vec4(1);\n"
18919 "}\n";
18920 char const *fsSource =
18921 "#version 450\n"
18922 "\n"
18923 "layout(location=0) out vec4 x;\n"
18924 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18925 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18926 "void main(){\n"
18927 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18928 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18931 VkPipelineObj pipe(m_device);
18932 pipe.SetViewport(m_viewports);
18933 pipe.SetScissor(m_scissors);
18934 pipe.AddShader(&vs);
18935 pipe.AddShader(&fs);
18936 pipe.AddColorAttachment();
18937 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18938
18939 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18940 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18941 // we used to have a bug in this case.
18942 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18943 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18944 &descriptor_set, BINDING_COUNT, dyn_off);
18945 Draw(1, 0, 0, 0);
18946 m_errorMonitor->VerifyNotFound();
18947
18948 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18949 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18950 vkFreeMemory(m_device->device(), mem1, NULL);
18951 vkFreeMemory(m_device->device(), mem2, NULL);
18952
18953 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18954 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18955 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18956}
18957
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018958TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018959 TEST_DESCRIPTION(
18960 "Ensure that validations handling of non-coherent memory "
18961 "mapping while using VK_WHOLE_SIZE does not cause access "
18962 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018963 VkResult err;
18964 uint8_t *pData;
18965 ASSERT_NO_FATAL_FAILURE(InitState());
18966
18967 VkDeviceMemory mem;
18968 VkMemoryRequirements mem_reqs;
18969 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018970 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018971 VkMemoryAllocateInfo alloc_info = {};
18972 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18973 alloc_info.pNext = NULL;
18974 alloc_info.memoryTypeIndex = 0;
18975
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018976 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018977 alloc_info.allocationSize = allocation_size;
18978
18979 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
18980 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 -070018981 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018982 if (!pass) {
18983 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018984 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
18985 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018986 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018987 pass = m_device->phy().set_memory_type(
18988 mem_reqs.memoryTypeBits, &alloc_info,
18989 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
18990 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018991 if (!pass) {
18992 return;
18993 }
18994 }
18995 }
18996
18997 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18998 ASSERT_VK_SUCCESS(err);
18999
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019000 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019001 m_errorMonitor->ExpectSuccess();
19002 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19003 ASSERT_VK_SUCCESS(err);
19004 VkMappedMemoryRange mmr = {};
19005 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19006 mmr.memory = mem;
19007 mmr.offset = 0;
19008 mmr.size = VK_WHOLE_SIZE;
19009 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19010 ASSERT_VK_SUCCESS(err);
19011 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19012 ASSERT_VK_SUCCESS(err);
19013 m_errorMonitor->VerifyNotFound();
19014 vkUnmapMemory(m_device->device(), mem);
19015
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019016 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019017 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019018 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019019 ASSERT_VK_SUCCESS(err);
19020 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19021 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019022 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019023 mmr.size = VK_WHOLE_SIZE;
19024 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19025 ASSERT_VK_SUCCESS(err);
19026 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19027 ASSERT_VK_SUCCESS(err);
19028 m_errorMonitor->VerifyNotFound();
19029 vkUnmapMemory(m_device->device(), mem);
19030
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019031 // Map with offset and size
19032 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019033 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019034 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019035 ASSERT_VK_SUCCESS(err);
19036 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19037 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019038 mmr.offset = 4 * atom_size;
19039 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019040 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19041 ASSERT_VK_SUCCESS(err);
19042 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19043 ASSERT_VK_SUCCESS(err);
19044 m_errorMonitor->VerifyNotFound();
19045 vkUnmapMemory(m_device->device(), mem);
19046
19047 // Map without offset and flush WHOLE_SIZE with two separate offsets
19048 m_errorMonitor->ExpectSuccess();
19049 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19050 ASSERT_VK_SUCCESS(err);
19051 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19052 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019053 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019054 mmr.size = VK_WHOLE_SIZE;
19055 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19056 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019057 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019058 mmr.size = VK_WHOLE_SIZE;
19059 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19060 ASSERT_VK_SUCCESS(err);
19061 m_errorMonitor->VerifyNotFound();
19062 vkUnmapMemory(m_device->device(), mem);
19063
19064 vkFreeMemory(m_device->device(), mem, NULL);
19065}
19066
19067// This is a positive test. We used to expect error in this case but spec now allows it
19068TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19069 m_errorMonitor->ExpectSuccess();
19070 vk_testing::Fence testFence;
19071 VkFenceCreateInfo fenceInfo = {};
19072 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19073 fenceInfo.pNext = NULL;
19074
19075 ASSERT_NO_FATAL_FAILURE(InitState());
19076 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019077 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019078 VkResult result = vkResetFences(m_device->device(), 1, fences);
19079 ASSERT_VK_SUCCESS(result);
19080
19081 m_errorMonitor->VerifyNotFound();
19082}
19083
19084TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19085 m_errorMonitor->ExpectSuccess();
19086
19087 ASSERT_NO_FATAL_FAILURE(InitState());
19088 VkResult err;
19089
19090 // Record (empty!) command buffer that can be submitted multiple times
19091 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019092 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19093 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019094 m_commandBuffer->BeginCommandBuffer(&cbbi);
19095 m_commandBuffer->EndCommandBuffer();
19096
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019097 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019098 VkFence fence;
19099 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19100 ASSERT_VK_SUCCESS(err);
19101
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019102 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019103 VkSemaphore s1, s2;
19104 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19105 ASSERT_VK_SUCCESS(err);
19106 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19107 ASSERT_VK_SUCCESS(err);
19108
19109 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019110 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019111 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19112 ASSERT_VK_SUCCESS(err);
19113
19114 // Submit CB again, signaling s2.
19115 si.pSignalSemaphores = &s2;
19116 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19117 ASSERT_VK_SUCCESS(err);
19118
19119 // Wait for fence.
19120 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19121 ASSERT_VK_SUCCESS(err);
19122
19123 // CB is still in flight from second submission, but semaphore s1 is no
19124 // longer in flight. delete it.
19125 vkDestroySemaphore(m_device->device(), s1, nullptr);
19126
19127 m_errorMonitor->VerifyNotFound();
19128
19129 // Force device idle and clean up remaining objects
19130 vkDeviceWaitIdle(m_device->device());
19131 vkDestroySemaphore(m_device->device(), s2, nullptr);
19132 vkDestroyFence(m_device->device(), fence, nullptr);
19133}
19134
19135TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19136 m_errorMonitor->ExpectSuccess();
19137
19138 ASSERT_NO_FATAL_FAILURE(InitState());
19139 VkResult err;
19140
19141 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019142 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019143 VkFence f1;
19144 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19145 ASSERT_VK_SUCCESS(err);
19146
19147 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019148 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019149 VkFence f2;
19150 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19151 ASSERT_VK_SUCCESS(err);
19152
19153 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019154 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019155 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19156
19157 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019158 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019159 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19160
19161 // Should have both retired!
19162 vkDestroyFence(m_device->device(), f1, nullptr);
19163 vkDestroyFence(m_device->device(), f2, nullptr);
19164
19165 m_errorMonitor->VerifyNotFound();
19166}
19167
19168TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019169 TEST_DESCRIPTION(
19170 "Verify that creating an image view from an image with valid usage "
19171 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019172
19173 ASSERT_NO_FATAL_FAILURE(InitState());
19174
19175 m_errorMonitor->ExpectSuccess();
19176 // Verify that we can create a view with usage INPUT_ATTACHMENT
19177 VkImageObj image(m_device);
19178 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19179 ASSERT_TRUE(image.initialized());
19180 VkImageView imageView;
19181 VkImageViewCreateInfo ivci = {};
19182 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19183 ivci.image = image.handle();
19184 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19185 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19186 ivci.subresourceRange.layerCount = 1;
19187 ivci.subresourceRange.baseMipLevel = 0;
19188 ivci.subresourceRange.levelCount = 1;
19189 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19190
19191 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19192 m_errorMonitor->VerifyNotFound();
19193 vkDestroyImageView(m_device->device(), imageView, NULL);
19194}
19195
19196// This is a positive test. No failures are expected.
19197TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019198 TEST_DESCRIPTION(
19199 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19200 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019201
19202 ASSERT_NO_FATAL_FAILURE(InitState());
19203
19204 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019205 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019206
19207 m_errorMonitor->ExpectSuccess();
19208
19209 VkImage image;
19210 VkImageCreateInfo image_create_info = {};
19211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19212 image_create_info.pNext = NULL;
19213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19214 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19215 image_create_info.extent.width = 64;
19216 image_create_info.extent.height = 64;
19217 image_create_info.extent.depth = 1;
19218 image_create_info.mipLevels = 1;
19219 image_create_info.arrayLayers = 1;
19220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19221 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19222 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19223 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19224 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19225 ASSERT_VK_SUCCESS(err);
19226
19227 VkMemoryRequirements memory_reqs;
19228 VkDeviceMemory memory_one, memory_two;
19229 bool pass;
19230 VkMemoryAllocateInfo memory_info = {};
19231 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19232 memory_info.pNext = NULL;
19233 memory_info.allocationSize = 0;
19234 memory_info.memoryTypeIndex = 0;
19235 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19236 // Find an image big enough to allow sparse mapping of 2 memory regions
19237 // Increase the image size until it is at least twice the
19238 // size of the required alignment, to ensure we can bind both
19239 // allocated memory blocks to the image on aligned offsets.
19240 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19241 vkDestroyImage(m_device->device(), image, nullptr);
19242 image_create_info.extent.width *= 2;
19243 image_create_info.extent.height *= 2;
19244 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19245 ASSERT_VK_SUCCESS(err);
19246 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19247 }
19248 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19249 // at the end of the first
19250 memory_info.allocationSize = memory_reqs.alignment;
19251 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19252 ASSERT_TRUE(pass);
19253 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19254 ASSERT_VK_SUCCESS(err);
19255 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19256 ASSERT_VK_SUCCESS(err);
19257 VkSparseMemoryBind binds[2];
19258 binds[0].flags = 0;
19259 binds[0].memory = memory_one;
19260 binds[0].memoryOffset = 0;
19261 binds[0].resourceOffset = 0;
19262 binds[0].size = memory_info.allocationSize;
19263 binds[1].flags = 0;
19264 binds[1].memory = memory_two;
19265 binds[1].memoryOffset = 0;
19266 binds[1].resourceOffset = memory_info.allocationSize;
19267 binds[1].size = memory_info.allocationSize;
19268
19269 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19270 opaqueBindInfo.image = image;
19271 opaqueBindInfo.bindCount = 2;
19272 opaqueBindInfo.pBinds = binds;
19273
19274 VkFence fence = VK_NULL_HANDLE;
19275 VkBindSparseInfo bindSparseInfo = {};
19276 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19277 bindSparseInfo.imageOpaqueBindCount = 1;
19278 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19279
19280 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19281 vkQueueWaitIdle(m_device->m_queue);
19282 vkDestroyImage(m_device->device(), image, NULL);
19283 vkFreeMemory(m_device->device(), memory_one, NULL);
19284 vkFreeMemory(m_device->device(), memory_two, NULL);
19285 m_errorMonitor->VerifyNotFound();
19286}
19287
19288TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019289 TEST_DESCRIPTION(
19290 "Ensure that CmdBeginRenderPass with an attachment's "
19291 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19292 "the command buffer has prior knowledge of that "
19293 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019294
19295 m_errorMonitor->ExpectSuccess();
19296
19297 ASSERT_NO_FATAL_FAILURE(InitState());
19298
19299 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019300 VkAttachmentDescription attachment = {0,
19301 VK_FORMAT_R8G8B8A8_UNORM,
19302 VK_SAMPLE_COUNT_1_BIT,
19303 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19304 VK_ATTACHMENT_STORE_OP_STORE,
19305 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19306 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19307 VK_IMAGE_LAYOUT_UNDEFINED,
19308 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019309
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019310 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019311
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019312 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019313
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019314 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019315
19316 VkRenderPass rp;
19317 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19318 ASSERT_VK_SUCCESS(err);
19319
19320 // A compatible framebuffer.
19321 VkImageObj image(m_device);
19322 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19323 ASSERT_TRUE(image.initialized());
19324
19325 VkImageViewCreateInfo ivci = {
19326 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19327 nullptr,
19328 0,
19329 image.handle(),
19330 VK_IMAGE_VIEW_TYPE_2D,
19331 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019332 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19333 VK_COMPONENT_SWIZZLE_IDENTITY},
19334 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019335 };
19336 VkImageView view;
19337 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19338 ASSERT_VK_SUCCESS(err);
19339
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019340 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019341 VkFramebuffer fb;
19342 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19343 ASSERT_VK_SUCCESS(err);
19344
19345 // Record a single command buffer which uses this renderpass twice. The
19346 // bug is triggered at the beginning of the second renderpass, when the
19347 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019348 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 -070019349 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019350 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19351 vkCmdEndRenderPass(m_commandBuffer->handle());
19352 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19353
19354 m_errorMonitor->VerifyNotFound();
19355
19356 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019357 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019358
19359 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19360 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19361 vkDestroyImageView(m_device->device(), view, nullptr);
19362}
19363
19364TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019365 TEST_DESCRIPTION(
19366 "This test should pass. Create a Framebuffer and "
19367 "command buffer, bind them together, then destroy "
19368 "command pool and framebuffer and verify there are no "
19369 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019370
19371 m_errorMonitor->ExpectSuccess();
19372
19373 ASSERT_NO_FATAL_FAILURE(InitState());
19374
19375 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019376 VkAttachmentDescription attachment = {0,
19377 VK_FORMAT_R8G8B8A8_UNORM,
19378 VK_SAMPLE_COUNT_1_BIT,
19379 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19380 VK_ATTACHMENT_STORE_OP_STORE,
19381 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19382 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19383 VK_IMAGE_LAYOUT_UNDEFINED,
19384 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019385
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019386 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019387
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019388 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019389
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019390 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019391
19392 VkRenderPass rp;
19393 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19394 ASSERT_VK_SUCCESS(err);
19395
19396 // A compatible framebuffer.
19397 VkImageObj image(m_device);
19398 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19399 ASSERT_TRUE(image.initialized());
19400
19401 VkImageViewCreateInfo ivci = {
19402 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19403 nullptr,
19404 0,
19405 image.handle(),
19406 VK_IMAGE_VIEW_TYPE_2D,
19407 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019408 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19409 VK_COMPONENT_SWIZZLE_IDENTITY},
19410 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019411 };
19412 VkImageView view;
19413 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19414 ASSERT_VK_SUCCESS(err);
19415
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019416 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019417 VkFramebuffer fb;
19418 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19419 ASSERT_VK_SUCCESS(err);
19420
19421 // Explicitly create a command buffer to bind the FB to so that we can then
19422 // destroy the command pool in order to implicitly free command buffer
19423 VkCommandPool command_pool;
19424 VkCommandPoolCreateInfo pool_create_info{};
19425 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19426 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19427 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19428 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19429
19430 VkCommandBuffer command_buffer;
19431 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19432 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19433 command_buffer_allocate_info.commandPool = command_pool;
19434 command_buffer_allocate_info.commandBufferCount = 1;
19435 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19436 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19437
19438 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019439 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 -060019440 VkCommandBufferBeginInfo begin_info{};
19441 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19442 vkBeginCommandBuffer(command_buffer, &begin_info);
19443
19444 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19445 vkCmdEndRenderPass(command_buffer);
19446 vkEndCommandBuffer(command_buffer);
19447 vkDestroyImageView(m_device->device(), view, nullptr);
19448 // Destroy command pool to implicitly free command buffer
19449 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19450 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19451 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19452 m_errorMonitor->VerifyNotFound();
19453}
19454
19455TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019456 TEST_DESCRIPTION(
19457 "Ensure that CmdBeginRenderPass applies the layout "
19458 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019459
19460 m_errorMonitor->ExpectSuccess();
19461
19462 ASSERT_NO_FATAL_FAILURE(InitState());
19463
19464 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019465 VkAttachmentDescription attachment = {0,
19466 VK_FORMAT_R8G8B8A8_UNORM,
19467 VK_SAMPLE_COUNT_1_BIT,
19468 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19469 VK_ATTACHMENT_STORE_OP_STORE,
19470 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19471 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19472 VK_IMAGE_LAYOUT_UNDEFINED,
19473 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019474
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019475 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019476
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019477 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019478
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019479 VkSubpassDependency dep = {0,
19480 0,
19481 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19482 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19483 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19484 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19485 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019486
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019487 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019488
19489 VkResult err;
19490 VkRenderPass rp;
19491 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19492 ASSERT_VK_SUCCESS(err);
19493
19494 // A compatible framebuffer.
19495 VkImageObj image(m_device);
19496 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19497 ASSERT_TRUE(image.initialized());
19498
19499 VkImageViewCreateInfo ivci = {
19500 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19501 nullptr,
19502 0,
19503 image.handle(),
19504 VK_IMAGE_VIEW_TYPE_2D,
19505 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019506 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19507 VK_COMPONENT_SWIZZLE_IDENTITY},
19508 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019509 };
19510 VkImageView view;
19511 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19512 ASSERT_VK_SUCCESS(err);
19513
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019514 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019515 VkFramebuffer fb;
19516 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19517 ASSERT_VK_SUCCESS(err);
19518
19519 // Record a single command buffer which issues a pipeline barrier w/
19520 // image memory barrier for the attachment. This detects the previously
19521 // missing tracking of the subpass layout by throwing a validation error
19522 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019523 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 -070019524 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019525 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19526
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019527 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19528 nullptr,
19529 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19530 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19531 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19532 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19533 VK_QUEUE_FAMILY_IGNORED,
19534 VK_QUEUE_FAMILY_IGNORED,
19535 image.handle(),
19536 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019537 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019538 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19539 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019540
19541 vkCmdEndRenderPass(m_commandBuffer->handle());
19542 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019543 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019544
19545 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19546 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19547 vkDestroyImageView(m_device->device(), view, nullptr);
19548}
19549
19550TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019551 TEST_DESCRIPTION(
19552 "Validate that when an imageView of a depth/stencil image "
19553 "is used as a depth/stencil framebuffer attachment, the "
19554 "aspectMask is ignored and both depth and stencil image "
19555 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019556
19557 VkFormatProperties format_properties;
19558 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19559 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19560 return;
19561 }
19562
19563 m_errorMonitor->ExpectSuccess();
19564
19565 ASSERT_NO_FATAL_FAILURE(InitState());
19566
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019567 VkAttachmentDescription attachment = {0,
19568 VK_FORMAT_D32_SFLOAT_S8_UINT,
19569 VK_SAMPLE_COUNT_1_BIT,
19570 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19571 VK_ATTACHMENT_STORE_OP_STORE,
19572 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19573 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19574 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19575 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019576
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019577 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019578
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019579 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019580
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019581 VkSubpassDependency dep = {0,
19582 0,
19583 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19584 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19585 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19586 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19587 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019588
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019589 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019590
19591 VkResult err;
19592 VkRenderPass rp;
19593 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19594 ASSERT_VK_SUCCESS(err);
19595
19596 VkImageObj image(m_device);
19597 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019598 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019599 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019600 ASSERT_TRUE(image.initialized());
19601 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19602
19603 VkImageViewCreateInfo ivci = {
19604 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19605 nullptr,
19606 0,
19607 image.handle(),
19608 VK_IMAGE_VIEW_TYPE_2D,
19609 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019610 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19611 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019612 };
19613 VkImageView view;
19614 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19615 ASSERT_VK_SUCCESS(err);
19616
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019617 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019618 VkFramebuffer fb;
19619 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19620 ASSERT_VK_SUCCESS(err);
19621
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019622 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 -070019623 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019624 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19625
19626 VkImageMemoryBarrier imb = {};
19627 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19628 imb.pNext = nullptr;
19629 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19630 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19631 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19632 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19633 imb.srcQueueFamilyIndex = 0;
19634 imb.dstQueueFamilyIndex = 0;
19635 imb.image = image.handle();
19636 imb.subresourceRange.aspectMask = 0x6;
19637 imb.subresourceRange.baseMipLevel = 0;
19638 imb.subresourceRange.levelCount = 0x1;
19639 imb.subresourceRange.baseArrayLayer = 0;
19640 imb.subresourceRange.layerCount = 0x1;
19641
19642 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019643 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19644 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019645
19646 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019647 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019648 QueueCommandBuffer(false);
19649 m_errorMonitor->VerifyNotFound();
19650
19651 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19652 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19653 vkDestroyImageView(m_device->device(), view, nullptr);
19654}
19655
19656TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019657 TEST_DESCRIPTION(
19658 "Ensure that layout transitions work correctly without "
19659 "errors, when an attachment reference is "
19660 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019661
19662 m_errorMonitor->ExpectSuccess();
19663
19664 ASSERT_NO_FATAL_FAILURE(InitState());
19665
19666 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019667 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019668
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019669 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019670
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019671 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019672
19673 VkRenderPass rp;
19674 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19675 ASSERT_VK_SUCCESS(err);
19676
19677 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019678 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019679 VkFramebuffer fb;
19680 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19681 ASSERT_VK_SUCCESS(err);
19682
19683 // Record a command buffer which just begins and ends the renderpass. The
19684 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019685 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 -070019686 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019687 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19688 vkCmdEndRenderPass(m_commandBuffer->handle());
19689 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019690 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019691
19692 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19693 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19694}
19695
19696// This is a positive test. No errors are expected.
19697TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019698 TEST_DESCRIPTION(
19699 "Create a stencil-only attachment with a LOAD_OP set to "
19700 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019701 VkResult result = VK_SUCCESS;
19702 VkImageFormatProperties formatProps;
19703 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019704 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19705 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019706 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19707 return;
19708 }
19709
19710 ASSERT_NO_FATAL_FAILURE(InitState());
19711 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19712 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019713 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019714 VkAttachmentDescription att = {};
19715 VkAttachmentReference ref = {};
19716 att.format = depth_stencil_fmt;
19717 att.samples = VK_SAMPLE_COUNT_1_BIT;
19718 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19719 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19720 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19721 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19722 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19723 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19724
19725 VkClearValue clear;
19726 clear.depthStencil.depth = 1.0;
19727 clear.depthStencil.stencil = 0;
19728 ref.attachment = 0;
19729 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19730
19731 VkSubpassDescription subpass = {};
19732 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19733 subpass.flags = 0;
19734 subpass.inputAttachmentCount = 0;
19735 subpass.pInputAttachments = NULL;
19736 subpass.colorAttachmentCount = 0;
19737 subpass.pColorAttachments = NULL;
19738 subpass.pResolveAttachments = NULL;
19739 subpass.pDepthStencilAttachment = &ref;
19740 subpass.preserveAttachmentCount = 0;
19741 subpass.pPreserveAttachments = NULL;
19742
19743 VkRenderPass rp;
19744 VkRenderPassCreateInfo rp_info = {};
19745 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19746 rp_info.attachmentCount = 1;
19747 rp_info.pAttachments = &att;
19748 rp_info.subpassCount = 1;
19749 rp_info.pSubpasses = &subpass;
19750 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19751 ASSERT_VK_SUCCESS(result);
19752
19753 VkImageView *depthView = m_depthStencil->BindInfo();
19754 VkFramebufferCreateInfo fb_info = {};
19755 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19756 fb_info.pNext = NULL;
19757 fb_info.renderPass = rp;
19758 fb_info.attachmentCount = 1;
19759 fb_info.pAttachments = depthView;
19760 fb_info.width = 100;
19761 fb_info.height = 100;
19762 fb_info.layers = 1;
19763 VkFramebuffer fb;
19764 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19765 ASSERT_VK_SUCCESS(result);
19766
19767 VkRenderPassBeginInfo rpbinfo = {};
19768 rpbinfo.clearValueCount = 1;
19769 rpbinfo.pClearValues = &clear;
19770 rpbinfo.pNext = NULL;
19771 rpbinfo.renderPass = rp;
19772 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19773 rpbinfo.renderArea.extent.width = 100;
19774 rpbinfo.renderArea.extent.height = 100;
19775 rpbinfo.renderArea.offset.x = 0;
19776 rpbinfo.renderArea.offset.y = 0;
19777 rpbinfo.framebuffer = fb;
19778
19779 VkFence fence = {};
19780 VkFenceCreateInfo fence_ci = {};
19781 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19782 fence_ci.pNext = nullptr;
19783 fence_ci.flags = 0;
19784 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19785 ASSERT_VK_SUCCESS(result);
19786
19787 m_commandBuffer->BeginCommandBuffer();
19788 m_commandBuffer->BeginRenderPass(rpbinfo);
19789 m_commandBuffer->EndRenderPass();
19790 m_commandBuffer->EndCommandBuffer();
19791 m_commandBuffer->QueueCommandBuffer(fence);
19792
19793 VkImageObj destImage(m_device);
19794 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 -070019795 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019796 VkImageMemoryBarrier barrier = {};
19797 VkImageSubresourceRange range;
19798 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19799 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19800 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19801 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19802 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19803 barrier.image = m_depthStencil->handle();
19804 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19805 range.baseMipLevel = 0;
19806 range.levelCount = 1;
19807 range.baseArrayLayer = 0;
19808 range.layerCount = 1;
19809 barrier.subresourceRange = range;
19810 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19811 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19812 cmdbuf.BeginCommandBuffer();
19813 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 -070019814 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019815 barrier.srcAccessMask = 0;
19816 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19817 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19818 barrier.image = destImage.handle();
19819 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19820 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 -070019821 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019822 VkImageCopy cregion;
19823 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19824 cregion.srcSubresource.mipLevel = 0;
19825 cregion.srcSubresource.baseArrayLayer = 0;
19826 cregion.srcSubresource.layerCount = 1;
19827 cregion.srcOffset.x = 0;
19828 cregion.srcOffset.y = 0;
19829 cregion.srcOffset.z = 0;
19830 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19831 cregion.dstSubresource.mipLevel = 0;
19832 cregion.dstSubresource.baseArrayLayer = 0;
19833 cregion.dstSubresource.layerCount = 1;
19834 cregion.dstOffset.x = 0;
19835 cregion.dstOffset.y = 0;
19836 cregion.dstOffset.z = 0;
19837 cregion.extent.width = 100;
19838 cregion.extent.height = 100;
19839 cregion.extent.depth = 1;
19840 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019841 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019842 cmdbuf.EndCommandBuffer();
19843
19844 VkSubmitInfo submit_info;
19845 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19846 submit_info.pNext = NULL;
19847 submit_info.waitSemaphoreCount = 0;
19848 submit_info.pWaitSemaphores = NULL;
19849 submit_info.pWaitDstStageMask = NULL;
19850 submit_info.commandBufferCount = 1;
19851 submit_info.pCommandBuffers = &cmdbuf.handle();
19852 submit_info.signalSemaphoreCount = 0;
19853 submit_info.pSignalSemaphores = NULL;
19854
19855 m_errorMonitor->ExpectSuccess();
19856 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19857 m_errorMonitor->VerifyNotFound();
19858
19859 vkQueueWaitIdle(m_device->m_queue);
19860 vkDestroyFence(m_device->device(), fence, nullptr);
19861 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19862 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19863}
19864
19865// This is a positive test. No errors should be generated.
19866TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19867 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19868
19869 m_errorMonitor->ExpectSuccess();
19870 ASSERT_NO_FATAL_FAILURE(InitState());
19871
19872 VkEvent event;
19873 VkEventCreateInfo event_create_info{};
19874 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19875 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19876
19877 VkCommandPool command_pool;
19878 VkCommandPoolCreateInfo pool_create_info{};
19879 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19880 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19881 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19882 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19883
19884 VkCommandBuffer command_buffer;
19885 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19886 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19887 command_buffer_allocate_info.commandPool = command_pool;
19888 command_buffer_allocate_info.commandBufferCount = 1;
19889 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19890 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19891
19892 VkQueue queue = VK_NULL_HANDLE;
19893 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19894
19895 {
19896 VkCommandBufferBeginInfo begin_info{};
19897 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19898 vkBeginCommandBuffer(command_buffer, &begin_info);
19899
19900 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 -070019901 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019902 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19903 vkEndCommandBuffer(command_buffer);
19904 }
19905 {
19906 VkSubmitInfo submit_info{};
19907 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19908 submit_info.commandBufferCount = 1;
19909 submit_info.pCommandBuffers = &command_buffer;
19910 submit_info.signalSemaphoreCount = 0;
19911 submit_info.pSignalSemaphores = nullptr;
19912 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19913 }
19914 { vkSetEvent(m_device->device(), event); }
19915
19916 vkQueueWaitIdle(queue);
19917
19918 vkDestroyEvent(m_device->device(), event, nullptr);
19919 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19920 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19921
19922 m_errorMonitor->VerifyNotFound();
19923}
19924// This is a positive test. No errors should be generated.
19925TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19926 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19927
19928 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019929 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019930
19931 m_errorMonitor->ExpectSuccess();
19932
19933 VkQueryPool query_pool;
19934 VkQueryPoolCreateInfo query_pool_create_info{};
19935 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19936 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19937 query_pool_create_info.queryCount = 1;
19938 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19939
19940 VkCommandPool command_pool;
19941 VkCommandPoolCreateInfo pool_create_info{};
19942 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19943 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19944 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19945 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19946
19947 VkCommandBuffer command_buffer;
19948 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19949 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19950 command_buffer_allocate_info.commandPool = command_pool;
19951 command_buffer_allocate_info.commandBufferCount = 1;
19952 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19953 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19954
19955 VkCommandBuffer secondary_command_buffer;
19956 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19957 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
19958
19959 VkQueue queue = VK_NULL_HANDLE;
19960 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19961
19962 uint32_t qfi = 0;
19963 VkBufferCreateInfo buff_create_info = {};
19964 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19965 buff_create_info.size = 1024;
19966 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19967 buff_create_info.queueFamilyIndexCount = 1;
19968 buff_create_info.pQueueFamilyIndices = &qfi;
19969
19970 VkResult err;
19971 VkBuffer buffer;
19972 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19973 ASSERT_VK_SUCCESS(err);
19974 VkMemoryAllocateInfo mem_alloc = {};
19975 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19976 mem_alloc.pNext = NULL;
19977 mem_alloc.allocationSize = 1024;
19978 mem_alloc.memoryTypeIndex = 0;
19979
19980 VkMemoryRequirements memReqs;
19981 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19982 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19983 if (!pass) {
19984 vkDestroyBuffer(m_device->device(), buffer, NULL);
19985 return;
19986 }
19987
19988 VkDeviceMemory mem;
19989 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19990 ASSERT_VK_SUCCESS(err);
19991 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19992 ASSERT_VK_SUCCESS(err);
19993
19994 VkCommandBufferInheritanceInfo hinfo = {};
19995 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19996 hinfo.renderPass = VK_NULL_HANDLE;
19997 hinfo.subpass = 0;
19998 hinfo.framebuffer = VK_NULL_HANDLE;
19999 hinfo.occlusionQueryEnable = VK_FALSE;
20000 hinfo.queryFlags = 0;
20001 hinfo.pipelineStatistics = 0;
20002
20003 {
20004 VkCommandBufferBeginInfo begin_info{};
20005 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20006 begin_info.pInheritanceInfo = &hinfo;
20007 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20008
20009 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20010 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20011
20012 vkEndCommandBuffer(secondary_command_buffer);
20013
20014 begin_info.pInheritanceInfo = nullptr;
20015 vkBeginCommandBuffer(command_buffer, &begin_info);
20016
20017 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20018 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20019
20020 vkEndCommandBuffer(command_buffer);
20021 }
20022 {
20023 VkSubmitInfo submit_info{};
20024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20025 submit_info.commandBufferCount = 1;
20026 submit_info.pCommandBuffers = &command_buffer;
20027 submit_info.signalSemaphoreCount = 0;
20028 submit_info.pSignalSemaphores = nullptr;
20029 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20030 }
20031
20032 vkQueueWaitIdle(queue);
20033
20034 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20035 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20036 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20037 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20038 vkDestroyBuffer(m_device->device(), buffer, NULL);
20039 vkFreeMemory(m_device->device(), mem, NULL);
20040
20041 m_errorMonitor->VerifyNotFound();
20042}
20043
20044// This is a positive test. No errors should be generated.
20045TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20046 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20047
20048 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020049 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020050
20051 m_errorMonitor->ExpectSuccess();
20052
20053 VkQueryPool query_pool;
20054 VkQueryPoolCreateInfo query_pool_create_info{};
20055 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20056 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20057 query_pool_create_info.queryCount = 1;
20058 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20059
20060 VkCommandPool command_pool;
20061 VkCommandPoolCreateInfo pool_create_info{};
20062 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20063 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20064 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20065 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20066
20067 VkCommandBuffer command_buffer[2];
20068 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20069 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20070 command_buffer_allocate_info.commandPool = command_pool;
20071 command_buffer_allocate_info.commandBufferCount = 2;
20072 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20073 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20074
20075 VkQueue queue = VK_NULL_HANDLE;
20076 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20077
20078 uint32_t qfi = 0;
20079 VkBufferCreateInfo buff_create_info = {};
20080 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20081 buff_create_info.size = 1024;
20082 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20083 buff_create_info.queueFamilyIndexCount = 1;
20084 buff_create_info.pQueueFamilyIndices = &qfi;
20085
20086 VkResult err;
20087 VkBuffer buffer;
20088 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20089 ASSERT_VK_SUCCESS(err);
20090 VkMemoryAllocateInfo mem_alloc = {};
20091 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20092 mem_alloc.pNext = NULL;
20093 mem_alloc.allocationSize = 1024;
20094 mem_alloc.memoryTypeIndex = 0;
20095
20096 VkMemoryRequirements memReqs;
20097 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20098 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20099 if (!pass) {
20100 vkDestroyBuffer(m_device->device(), buffer, NULL);
20101 return;
20102 }
20103
20104 VkDeviceMemory mem;
20105 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20106 ASSERT_VK_SUCCESS(err);
20107 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20108 ASSERT_VK_SUCCESS(err);
20109
20110 {
20111 VkCommandBufferBeginInfo begin_info{};
20112 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20113 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20114
20115 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20116 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20117
20118 vkEndCommandBuffer(command_buffer[0]);
20119
20120 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20121
20122 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20123
20124 vkEndCommandBuffer(command_buffer[1]);
20125 }
20126 {
20127 VkSubmitInfo submit_info{};
20128 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20129 submit_info.commandBufferCount = 2;
20130 submit_info.pCommandBuffers = command_buffer;
20131 submit_info.signalSemaphoreCount = 0;
20132 submit_info.pSignalSemaphores = nullptr;
20133 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20134 }
20135
20136 vkQueueWaitIdle(queue);
20137
20138 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20139 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20140 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20141 vkDestroyBuffer(m_device->device(), buffer, NULL);
20142 vkFreeMemory(m_device->device(), mem, NULL);
20143
20144 m_errorMonitor->VerifyNotFound();
20145}
20146
Tony Barbourc46924f2016-11-04 11:49:52 -060020147TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020148 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20149
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020150 ASSERT_NO_FATAL_FAILURE(InitState());
20151 VkEvent event;
20152 VkEventCreateInfo event_create_info{};
20153 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20154 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20155
20156 VkCommandPool command_pool;
20157 VkCommandPoolCreateInfo pool_create_info{};
20158 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20159 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20160 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20161 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20162
20163 VkCommandBuffer command_buffer;
20164 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20165 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20166 command_buffer_allocate_info.commandPool = command_pool;
20167 command_buffer_allocate_info.commandBufferCount = 1;
20168 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20169 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20170
20171 VkQueue queue = VK_NULL_HANDLE;
20172 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20173
20174 {
20175 VkCommandBufferBeginInfo begin_info{};
20176 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20177 vkBeginCommandBuffer(command_buffer, &begin_info);
20178
20179 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020180 vkEndCommandBuffer(command_buffer);
20181 }
20182 {
20183 VkSubmitInfo submit_info{};
20184 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20185 submit_info.commandBufferCount = 1;
20186 submit_info.pCommandBuffers = &command_buffer;
20187 submit_info.signalSemaphoreCount = 0;
20188 submit_info.pSignalSemaphores = nullptr;
20189 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20190 }
20191 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20193 "that is already in use by a "
20194 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020195 vkSetEvent(m_device->device(), event);
20196 m_errorMonitor->VerifyFound();
20197 }
20198
20199 vkQueueWaitIdle(queue);
20200
20201 vkDestroyEvent(m_device->device(), event, nullptr);
20202 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20203 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20204}
20205
20206// This is a positive test. No errors should be generated.
20207TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020208 TEST_DESCRIPTION(
20209 "Two command buffers with two separate fences are each "
20210 "run through a Submit & WaitForFences cycle 3 times. This "
20211 "previously revealed a bug so running this positive test "
20212 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020213 m_errorMonitor->ExpectSuccess();
20214
20215 ASSERT_NO_FATAL_FAILURE(InitState());
20216 VkQueue queue = VK_NULL_HANDLE;
20217 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20218
20219 static const uint32_t NUM_OBJECTS = 2;
20220 static const uint32_t NUM_FRAMES = 3;
20221 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20222 VkFence fences[NUM_OBJECTS] = {};
20223
20224 VkCommandPool cmd_pool;
20225 VkCommandPoolCreateInfo cmd_pool_ci = {};
20226 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20227 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20228 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20229 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20230 ASSERT_VK_SUCCESS(err);
20231
20232 VkCommandBufferAllocateInfo cmd_buf_info = {};
20233 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20234 cmd_buf_info.commandPool = cmd_pool;
20235 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20236 cmd_buf_info.commandBufferCount = 1;
20237
20238 VkFenceCreateInfo fence_ci = {};
20239 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20240 fence_ci.pNext = nullptr;
20241 fence_ci.flags = 0;
20242
20243 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20244 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20245 ASSERT_VK_SUCCESS(err);
20246 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20247 ASSERT_VK_SUCCESS(err);
20248 }
20249
20250 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20251 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20252 // Create empty cmd buffer
20253 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20254 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20255
20256 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20257 ASSERT_VK_SUCCESS(err);
20258 err = vkEndCommandBuffer(cmd_buffers[obj]);
20259 ASSERT_VK_SUCCESS(err);
20260
20261 VkSubmitInfo submit_info = {};
20262 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20263 submit_info.commandBufferCount = 1;
20264 submit_info.pCommandBuffers = &cmd_buffers[obj];
20265 // Submit cmd buffer and wait for fence
20266 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20267 ASSERT_VK_SUCCESS(err);
20268 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20269 ASSERT_VK_SUCCESS(err);
20270 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20271 ASSERT_VK_SUCCESS(err);
20272 }
20273 }
20274 m_errorMonitor->VerifyNotFound();
20275 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20276 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20277 vkDestroyFence(m_device->device(), fences[i], nullptr);
20278 }
20279}
20280// This is a positive test. No errors should be generated.
20281TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020282 TEST_DESCRIPTION(
20283 "Two command buffers, each in a separate QueueSubmit call "
20284 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020285
20286 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020287 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020288
20289 m_errorMonitor->ExpectSuccess();
20290
20291 VkSemaphore semaphore;
20292 VkSemaphoreCreateInfo semaphore_create_info{};
20293 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20294 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20295
20296 VkCommandPool command_pool;
20297 VkCommandPoolCreateInfo pool_create_info{};
20298 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20299 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20300 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20301 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20302
20303 VkCommandBuffer command_buffer[2];
20304 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20305 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20306 command_buffer_allocate_info.commandPool = command_pool;
20307 command_buffer_allocate_info.commandBufferCount = 2;
20308 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20309 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20310
20311 VkQueue queue = VK_NULL_HANDLE;
20312 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20313
20314 {
20315 VkCommandBufferBeginInfo begin_info{};
20316 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20317 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20318
20319 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 -070020320 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020321
20322 VkViewport viewport{};
20323 viewport.maxDepth = 1.0f;
20324 viewport.minDepth = 0.0f;
20325 viewport.width = 512;
20326 viewport.height = 512;
20327 viewport.x = 0;
20328 viewport.y = 0;
20329 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20330 vkEndCommandBuffer(command_buffer[0]);
20331 }
20332 {
20333 VkCommandBufferBeginInfo begin_info{};
20334 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20335 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20336
20337 VkViewport viewport{};
20338 viewport.maxDepth = 1.0f;
20339 viewport.minDepth = 0.0f;
20340 viewport.width = 512;
20341 viewport.height = 512;
20342 viewport.x = 0;
20343 viewport.y = 0;
20344 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20345 vkEndCommandBuffer(command_buffer[1]);
20346 }
20347 {
20348 VkSubmitInfo submit_info{};
20349 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20350 submit_info.commandBufferCount = 1;
20351 submit_info.pCommandBuffers = &command_buffer[0];
20352 submit_info.signalSemaphoreCount = 1;
20353 submit_info.pSignalSemaphores = &semaphore;
20354 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20355 }
20356 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020357 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020358 VkSubmitInfo submit_info{};
20359 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20360 submit_info.commandBufferCount = 1;
20361 submit_info.pCommandBuffers = &command_buffer[1];
20362 submit_info.waitSemaphoreCount = 1;
20363 submit_info.pWaitSemaphores = &semaphore;
20364 submit_info.pWaitDstStageMask = flags;
20365 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20366 }
20367
20368 vkQueueWaitIdle(m_device->m_queue);
20369
20370 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20371 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20372 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20373
20374 m_errorMonitor->VerifyNotFound();
20375}
20376
20377// This is a positive test. No errors should be generated.
20378TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020379 TEST_DESCRIPTION(
20380 "Two command buffers, each in a separate QueueSubmit call "
20381 "submitted on separate queues, the second having a fence"
20382 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020383
20384 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020385 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020386
20387 m_errorMonitor->ExpectSuccess();
20388
20389 VkFence fence;
20390 VkFenceCreateInfo fence_create_info{};
20391 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20392 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20393
20394 VkSemaphore semaphore;
20395 VkSemaphoreCreateInfo semaphore_create_info{};
20396 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20397 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20398
20399 VkCommandPool command_pool;
20400 VkCommandPoolCreateInfo pool_create_info{};
20401 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20402 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20403 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20404 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20405
20406 VkCommandBuffer command_buffer[2];
20407 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20408 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20409 command_buffer_allocate_info.commandPool = command_pool;
20410 command_buffer_allocate_info.commandBufferCount = 2;
20411 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20412 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20413
20414 VkQueue queue = VK_NULL_HANDLE;
20415 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20416
20417 {
20418 VkCommandBufferBeginInfo begin_info{};
20419 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20420 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20421
20422 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 -070020423 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020424
20425 VkViewport viewport{};
20426 viewport.maxDepth = 1.0f;
20427 viewport.minDepth = 0.0f;
20428 viewport.width = 512;
20429 viewport.height = 512;
20430 viewport.x = 0;
20431 viewport.y = 0;
20432 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20433 vkEndCommandBuffer(command_buffer[0]);
20434 }
20435 {
20436 VkCommandBufferBeginInfo begin_info{};
20437 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20438 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20439
20440 VkViewport viewport{};
20441 viewport.maxDepth = 1.0f;
20442 viewport.minDepth = 0.0f;
20443 viewport.width = 512;
20444 viewport.height = 512;
20445 viewport.x = 0;
20446 viewport.y = 0;
20447 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20448 vkEndCommandBuffer(command_buffer[1]);
20449 }
20450 {
20451 VkSubmitInfo submit_info{};
20452 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20453 submit_info.commandBufferCount = 1;
20454 submit_info.pCommandBuffers = &command_buffer[0];
20455 submit_info.signalSemaphoreCount = 1;
20456 submit_info.pSignalSemaphores = &semaphore;
20457 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20458 }
20459 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020460 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020461 VkSubmitInfo submit_info{};
20462 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20463 submit_info.commandBufferCount = 1;
20464 submit_info.pCommandBuffers = &command_buffer[1];
20465 submit_info.waitSemaphoreCount = 1;
20466 submit_info.pWaitSemaphores = &semaphore;
20467 submit_info.pWaitDstStageMask = flags;
20468 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20469 }
20470
20471 vkQueueWaitIdle(m_device->m_queue);
20472
20473 vkDestroyFence(m_device->device(), fence, nullptr);
20474 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20475 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20476 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20477
20478 m_errorMonitor->VerifyNotFound();
20479}
20480
20481// This is a positive test. No errors should be generated.
20482TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020483 TEST_DESCRIPTION(
20484 "Two command buffers, each in a separate QueueSubmit call "
20485 "submitted on separate queues, the second having a fence"
20486 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020487
20488 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020489 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020490
20491 m_errorMonitor->ExpectSuccess();
20492
20493 VkFence fence;
20494 VkFenceCreateInfo fence_create_info{};
20495 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20496 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20497
20498 VkSemaphore semaphore;
20499 VkSemaphoreCreateInfo semaphore_create_info{};
20500 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20501 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20502
20503 VkCommandPool command_pool;
20504 VkCommandPoolCreateInfo pool_create_info{};
20505 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20506 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20507 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20508 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20509
20510 VkCommandBuffer command_buffer[2];
20511 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20512 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20513 command_buffer_allocate_info.commandPool = command_pool;
20514 command_buffer_allocate_info.commandBufferCount = 2;
20515 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20516 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20517
20518 VkQueue queue = VK_NULL_HANDLE;
20519 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20520
20521 {
20522 VkCommandBufferBeginInfo begin_info{};
20523 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20524 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20525
20526 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 -070020527 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020528
20529 VkViewport viewport{};
20530 viewport.maxDepth = 1.0f;
20531 viewport.minDepth = 0.0f;
20532 viewport.width = 512;
20533 viewport.height = 512;
20534 viewport.x = 0;
20535 viewport.y = 0;
20536 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20537 vkEndCommandBuffer(command_buffer[0]);
20538 }
20539 {
20540 VkCommandBufferBeginInfo begin_info{};
20541 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20542 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20543
20544 VkViewport viewport{};
20545 viewport.maxDepth = 1.0f;
20546 viewport.minDepth = 0.0f;
20547 viewport.width = 512;
20548 viewport.height = 512;
20549 viewport.x = 0;
20550 viewport.y = 0;
20551 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20552 vkEndCommandBuffer(command_buffer[1]);
20553 }
20554 {
20555 VkSubmitInfo submit_info{};
20556 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20557 submit_info.commandBufferCount = 1;
20558 submit_info.pCommandBuffers = &command_buffer[0];
20559 submit_info.signalSemaphoreCount = 1;
20560 submit_info.pSignalSemaphores = &semaphore;
20561 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20562 }
20563 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020564 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020565 VkSubmitInfo submit_info{};
20566 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20567 submit_info.commandBufferCount = 1;
20568 submit_info.pCommandBuffers = &command_buffer[1];
20569 submit_info.waitSemaphoreCount = 1;
20570 submit_info.pWaitSemaphores = &semaphore;
20571 submit_info.pWaitDstStageMask = flags;
20572 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20573 }
20574
20575 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20576 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20577
20578 vkDestroyFence(m_device->device(), fence, nullptr);
20579 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20580 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20581 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20582
20583 m_errorMonitor->VerifyNotFound();
20584}
20585
20586TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020587 ASSERT_NO_FATAL_FAILURE(InitState());
20588 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020589 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020590 return;
20591 }
20592
20593 VkResult err;
20594
20595 m_errorMonitor->ExpectSuccess();
20596
20597 VkQueue q0 = m_device->m_queue;
20598 VkQueue q1 = nullptr;
20599 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20600 ASSERT_NE(q1, nullptr);
20601
20602 // An (empty) command buffer. We must have work in the first submission --
20603 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020604 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020605 VkCommandPool pool;
20606 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20607 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020608 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20609 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020610 VkCommandBuffer cb;
20611 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20612 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020613 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020614 err = vkBeginCommandBuffer(cb, &cbbi);
20615 ASSERT_VK_SUCCESS(err);
20616 err = vkEndCommandBuffer(cb);
20617 ASSERT_VK_SUCCESS(err);
20618
20619 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020620 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020621 VkSemaphore s;
20622 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20623 ASSERT_VK_SUCCESS(err);
20624
20625 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020626 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020627
20628 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20629 ASSERT_VK_SUCCESS(err);
20630
20631 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020632 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020633 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020634
20635 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20636 ASSERT_VK_SUCCESS(err);
20637
20638 // Wait for q0 idle
20639 err = vkQueueWaitIdle(q0);
20640 ASSERT_VK_SUCCESS(err);
20641
20642 // Command buffer should have been completed (it was on q0); reset the pool.
20643 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20644
20645 m_errorMonitor->VerifyNotFound();
20646
20647 // Force device completely idle and clean up resources
20648 vkDeviceWaitIdle(m_device->device());
20649 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20650 vkDestroySemaphore(m_device->device(), s, nullptr);
20651}
20652
20653// This is a positive test. No errors should be generated.
20654TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020655 TEST_DESCRIPTION(
20656 "Two command buffers, each in a separate QueueSubmit call "
20657 "submitted on separate queues, the second having a fence, "
20658 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020659
20660 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020661 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020662
20663 m_errorMonitor->ExpectSuccess();
20664
20665 ASSERT_NO_FATAL_FAILURE(InitState());
20666 VkFence fence;
20667 VkFenceCreateInfo fence_create_info{};
20668 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20669 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20670
20671 VkSemaphore semaphore;
20672 VkSemaphoreCreateInfo semaphore_create_info{};
20673 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20674 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20675
20676 VkCommandPool command_pool;
20677 VkCommandPoolCreateInfo pool_create_info{};
20678 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20679 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20680 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20681 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20682
20683 VkCommandBuffer command_buffer[2];
20684 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20685 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20686 command_buffer_allocate_info.commandPool = command_pool;
20687 command_buffer_allocate_info.commandBufferCount = 2;
20688 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20689 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20690
20691 VkQueue queue = VK_NULL_HANDLE;
20692 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20693
20694 {
20695 VkCommandBufferBeginInfo begin_info{};
20696 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20697 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20698
20699 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 -070020700 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020701
20702 VkViewport viewport{};
20703 viewport.maxDepth = 1.0f;
20704 viewport.minDepth = 0.0f;
20705 viewport.width = 512;
20706 viewport.height = 512;
20707 viewport.x = 0;
20708 viewport.y = 0;
20709 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20710 vkEndCommandBuffer(command_buffer[0]);
20711 }
20712 {
20713 VkCommandBufferBeginInfo begin_info{};
20714 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20715 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20716
20717 VkViewport viewport{};
20718 viewport.maxDepth = 1.0f;
20719 viewport.minDepth = 0.0f;
20720 viewport.width = 512;
20721 viewport.height = 512;
20722 viewport.x = 0;
20723 viewport.y = 0;
20724 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20725 vkEndCommandBuffer(command_buffer[1]);
20726 }
20727 {
20728 VkSubmitInfo submit_info{};
20729 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20730 submit_info.commandBufferCount = 1;
20731 submit_info.pCommandBuffers = &command_buffer[0];
20732 submit_info.signalSemaphoreCount = 1;
20733 submit_info.pSignalSemaphores = &semaphore;
20734 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20735 }
20736 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020737 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020738 VkSubmitInfo submit_info{};
20739 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20740 submit_info.commandBufferCount = 1;
20741 submit_info.pCommandBuffers = &command_buffer[1];
20742 submit_info.waitSemaphoreCount = 1;
20743 submit_info.pWaitSemaphores = &semaphore;
20744 submit_info.pWaitDstStageMask = flags;
20745 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20746 }
20747
20748 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20749
20750 vkDestroyFence(m_device->device(), fence, nullptr);
20751 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20752 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20753 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20754
20755 m_errorMonitor->VerifyNotFound();
20756}
20757
20758// This is a positive test. No errors should be generated.
20759TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020760 TEST_DESCRIPTION(
20761 "Two command buffers, each in a separate QueueSubmit call "
20762 "on the same queue, sharing a signal/wait semaphore, the "
20763 "second having a fence, "
20764 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020765
20766 m_errorMonitor->ExpectSuccess();
20767
20768 ASSERT_NO_FATAL_FAILURE(InitState());
20769 VkFence fence;
20770 VkFenceCreateInfo fence_create_info{};
20771 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20772 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20773
20774 VkSemaphore semaphore;
20775 VkSemaphoreCreateInfo semaphore_create_info{};
20776 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20777 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20778
20779 VkCommandPool command_pool;
20780 VkCommandPoolCreateInfo pool_create_info{};
20781 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20782 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20783 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20784 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20785
20786 VkCommandBuffer command_buffer[2];
20787 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20788 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20789 command_buffer_allocate_info.commandPool = command_pool;
20790 command_buffer_allocate_info.commandBufferCount = 2;
20791 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20792 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20793
20794 {
20795 VkCommandBufferBeginInfo begin_info{};
20796 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20797 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20798
20799 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 -070020800 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020801
20802 VkViewport viewport{};
20803 viewport.maxDepth = 1.0f;
20804 viewport.minDepth = 0.0f;
20805 viewport.width = 512;
20806 viewport.height = 512;
20807 viewport.x = 0;
20808 viewport.y = 0;
20809 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20810 vkEndCommandBuffer(command_buffer[0]);
20811 }
20812 {
20813 VkCommandBufferBeginInfo begin_info{};
20814 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20815 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20816
20817 VkViewport viewport{};
20818 viewport.maxDepth = 1.0f;
20819 viewport.minDepth = 0.0f;
20820 viewport.width = 512;
20821 viewport.height = 512;
20822 viewport.x = 0;
20823 viewport.y = 0;
20824 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20825 vkEndCommandBuffer(command_buffer[1]);
20826 }
20827 {
20828 VkSubmitInfo submit_info{};
20829 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20830 submit_info.commandBufferCount = 1;
20831 submit_info.pCommandBuffers = &command_buffer[0];
20832 submit_info.signalSemaphoreCount = 1;
20833 submit_info.pSignalSemaphores = &semaphore;
20834 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20835 }
20836 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020837 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020838 VkSubmitInfo submit_info{};
20839 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20840 submit_info.commandBufferCount = 1;
20841 submit_info.pCommandBuffers = &command_buffer[1];
20842 submit_info.waitSemaphoreCount = 1;
20843 submit_info.pWaitSemaphores = &semaphore;
20844 submit_info.pWaitDstStageMask = flags;
20845 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20846 }
20847
20848 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20849
20850 vkDestroyFence(m_device->device(), fence, nullptr);
20851 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20852 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20853 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20854
20855 m_errorMonitor->VerifyNotFound();
20856}
20857
20858// This is a positive test. No errors should be generated.
20859TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020860 TEST_DESCRIPTION(
20861 "Two command buffers, each in a separate QueueSubmit call "
20862 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20863 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020864
20865 m_errorMonitor->ExpectSuccess();
20866
20867 ASSERT_NO_FATAL_FAILURE(InitState());
20868 VkFence fence;
20869 VkFenceCreateInfo fence_create_info{};
20870 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20871 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20872
20873 VkCommandPool command_pool;
20874 VkCommandPoolCreateInfo pool_create_info{};
20875 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20876 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20877 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20878 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20879
20880 VkCommandBuffer command_buffer[2];
20881 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20882 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20883 command_buffer_allocate_info.commandPool = command_pool;
20884 command_buffer_allocate_info.commandBufferCount = 2;
20885 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20886 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20887
20888 {
20889 VkCommandBufferBeginInfo begin_info{};
20890 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20891 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20892
20893 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 -070020894 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020895
20896 VkViewport viewport{};
20897 viewport.maxDepth = 1.0f;
20898 viewport.minDepth = 0.0f;
20899 viewport.width = 512;
20900 viewport.height = 512;
20901 viewport.x = 0;
20902 viewport.y = 0;
20903 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20904 vkEndCommandBuffer(command_buffer[0]);
20905 }
20906 {
20907 VkCommandBufferBeginInfo begin_info{};
20908 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20909 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20910
20911 VkViewport viewport{};
20912 viewport.maxDepth = 1.0f;
20913 viewport.minDepth = 0.0f;
20914 viewport.width = 512;
20915 viewport.height = 512;
20916 viewport.x = 0;
20917 viewport.y = 0;
20918 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20919 vkEndCommandBuffer(command_buffer[1]);
20920 }
20921 {
20922 VkSubmitInfo submit_info{};
20923 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20924 submit_info.commandBufferCount = 1;
20925 submit_info.pCommandBuffers = &command_buffer[0];
20926 submit_info.signalSemaphoreCount = 0;
20927 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20928 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20929 }
20930 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020931 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020932 VkSubmitInfo submit_info{};
20933 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20934 submit_info.commandBufferCount = 1;
20935 submit_info.pCommandBuffers = &command_buffer[1];
20936 submit_info.waitSemaphoreCount = 0;
20937 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20938 submit_info.pWaitDstStageMask = flags;
20939 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20940 }
20941
20942 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20943
20944 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20945 ASSERT_VK_SUCCESS(err);
20946
20947 vkDestroyFence(m_device->device(), fence, nullptr);
20948 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20949 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20950
20951 m_errorMonitor->VerifyNotFound();
20952}
20953
20954// This is a positive test. No errors should be generated.
20955TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020956 TEST_DESCRIPTION(
20957 "Two command buffers, each in a separate QueueSubmit call "
20958 "on the same queue, the second having a fence, followed "
20959 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020960
20961 m_errorMonitor->ExpectSuccess();
20962
20963 ASSERT_NO_FATAL_FAILURE(InitState());
20964 VkFence fence;
20965 VkFenceCreateInfo fence_create_info{};
20966 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20967 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20968
20969 VkCommandPool command_pool;
20970 VkCommandPoolCreateInfo pool_create_info{};
20971 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20972 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20973 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20974 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20975
20976 VkCommandBuffer command_buffer[2];
20977 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20978 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20979 command_buffer_allocate_info.commandPool = command_pool;
20980 command_buffer_allocate_info.commandBufferCount = 2;
20981 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20982 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20983
20984 {
20985 VkCommandBufferBeginInfo begin_info{};
20986 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20987 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20988
20989 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 -070020990 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020991
20992 VkViewport viewport{};
20993 viewport.maxDepth = 1.0f;
20994 viewport.minDepth = 0.0f;
20995 viewport.width = 512;
20996 viewport.height = 512;
20997 viewport.x = 0;
20998 viewport.y = 0;
20999 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21000 vkEndCommandBuffer(command_buffer[0]);
21001 }
21002 {
21003 VkCommandBufferBeginInfo begin_info{};
21004 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21005 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21006
21007 VkViewport viewport{};
21008 viewport.maxDepth = 1.0f;
21009 viewport.minDepth = 0.0f;
21010 viewport.width = 512;
21011 viewport.height = 512;
21012 viewport.x = 0;
21013 viewport.y = 0;
21014 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21015 vkEndCommandBuffer(command_buffer[1]);
21016 }
21017 {
21018 VkSubmitInfo submit_info{};
21019 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21020 submit_info.commandBufferCount = 1;
21021 submit_info.pCommandBuffers = &command_buffer[0];
21022 submit_info.signalSemaphoreCount = 0;
21023 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21024 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21025 }
21026 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021027 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021028 VkSubmitInfo submit_info{};
21029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21030 submit_info.commandBufferCount = 1;
21031 submit_info.pCommandBuffers = &command_buffer[1];
21032 submit_info.waitSemaphoreCount = 0;
21033 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21034 submit_info.pWaitDstStageMask = flags;
21035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21036 }
21037
21038 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21039
21040 vkDestroyFence(m_device->device(), fence, nullptr);
21041 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21042 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21043
21044 m_errorMonitor->VerifyNotFound();
21045}
21046
21047// This is a positive test. No errors should be generated.
21048TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021049 TEST_DESCRIPTION(
21050 "Two command buffers each in a separate SubmitInfo sent in a single "
21051 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021052 ASSERT_NO_FATAL_FAILURE(InitState());
21053
21054 m_errorMonitor->ExpectSuccess();
21055
21056 VkFence fence;
21057 VkFenceCreateInfo fence_create_info{};
21058 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21059 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21060
21061 VkSemaphore semaphore;
21062 VkSemaphoreCreateInfo semaphore_create_info{};
21063 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21064 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21065
21066 VkCommandPool command_pool;
21067 VkCommandPoolCreateInfo pool_create_info{};
21068 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21069 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21070 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21071 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21072
21073 VkCommandBuffer command_buffer[2];
21074 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21075 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21076 command_buffer_allocate_info.commandPool = command_pool;
21077 command_buffer_allocate_info.commandBufferCount = 2;
21078 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21079 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21080
21081 {
21082 VkCommandBufferBeginInfo begin_info{};
21083 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21084 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21085
21086 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 -070021087 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021088
21089 VkViewport viewport{};
21090 viewport.maxDepth = 1.0f;
21091 viewport.minDepth = 0.0f;
21092 viewport.width = 512;
21093 viewport.height = 512;
21094 viewport.x = 0;
21095 viewport.y = 0;
21096 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21097 vkEndCommandBuffer(command_buffer[0]);
21098 }
21099 {
21100 VkCommandBufferBeginInfo begin_info{};
21101 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21102 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21103
21104 VkViewport viewport{};
21105 viewport.maxDepth = 1.0f;
21106 viewport.minDepth = 0.0f;
21107 viewport.width = 512;
21108 viewport.height = 512;
21109 viewport.x = 0;
21110 viewport.y = 0;
21111 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21112 vkEndCommandBuffer(command_buffer[1]);
21113 }
21114 {
21115 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021116 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021117
21118 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21119 submit_info[0].pNext = NULL;
21120 submit_info[0].commandBufferCount = 1;
21121 submit_info[0].pCommandBuffers = &command_buffer[0];
21122 submit_info[0].signalSemaphoreCount = 1;
21123 submit_info[0].pSignalSemaphores = &semaphore;
21124 submit_info[0].waitSemaphoreCount = 0;
21125 submit_info[0].pWaitSemaphores = NULL;
21126 submit_info[0].pWaitDstStageMask = 0;
21127
21128 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21129 submit_info[1].pNext = NULL;
21130 submit_info[1].commandBufferCount = 1;
21131 submit_info[1].pCommandBuffers = &command_buffer[1];
21132 submit_info[1].waitSemaphoreCount = 1;
21133 submit_info[1].pWaitSemaphores = &semaphore;
21134 submit_info[1].pWaitDstStageMask = flags;
21135 submit_info[1].signalSemaphoreCount = 0;
21136 submit_info[1].pSignalSemaphores = NULL;
21137 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21138 }
21139
21140 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21141
21142 vkDestroyFence(m_device->device(), fence, nullptr);
21143 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21144 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21145 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21146
21147 m_errorMonitor->VerifyNotFound();
21148}
21149
21150TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21151 m_errorMonitor->ExpectSuccess();
21152
21153 ASSERT_NO_FATAL_FAILURE(InitState());
21154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21155
Tony Barbour552f6c02016-12-21 14:34:07 -070021156 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021157
21158 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21159 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21160 m_errorMonitor->VerifyNotFound();
21161 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21162 m_errorMonitor->VerifyNotFound();
21163 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21164 m_errorMonitor->VerifyNotFound();
21165
21166 m_commandBuffer->EndCommandBuffer();
21167 m_errorMonitor->VerifyNotFound();
21168}
21169
21170TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021171 TEST_DESCRIPTION(
21172 "Positive test where we create a renderpass with an "
21173 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21174 "has a valid layout, and a second subpass then uses a "
21175 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021176 m_errorMonitor->ExpectSuccess();
21177 ASSERT_NO_FATAL_FAILURE(InitState());
21178
21179 VkAttachmentReference attach[2] = {};
21180 attach[0].attachment = 0;
21181 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21182 attach[1].attachment = 0;
21183 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21184 VkSubpassDescription subpasses[2] = {};
21185 // First subpass clears DS attach on load
21186 subpasses[0].pDepthStencilAttachment = &attach[0];
21187 // 2nd subpass reads in DS as input attachment
21188 subpasses[1].inputAttachmentCount = 1;
21189 subpasses[1].pInputAttachments = &attach[1];
21190 VkAttachmentDescription attach_desc = {};
21191 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
21192 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21193 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21194 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21195 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21196 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21197 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21198 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21199 VkRenderPassCreateInfo rpci = {};
21200 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21201 rpci.attachmentCount = 1;
21202 rpci.pAttachments = &attach_desc;
21203 rpci.subpassCount = 2;
21204 rpci.pSubpasses = subpasses;
21205
21206 // Now create RenderPass and verify no errors
21207 VkRenderPass rp;
21208 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21209 m_errorMonitor->VerifyNotFound();
21210
21211 vkDestroyRenderPass(m_device->device(), rp, NULL);
21212}
21213
Tobin Ehlis01103de2017-02-16 13:22:47 -070021214TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21215 TEST_DESCRIPTION(
21216 "Create a render pass with depth-stencil attachment where layout transition "
21217 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21218 "transition has correctly occurred at queue submit time with no validation errors.");
21219
21220 VkFormat ds_format = VK_FORMAT_D24_UNORM_S8_UINT;
21221 VkImageFormatProperties format_props;
21222 vkGetPhysicalDeviceImageFormatProperties(gpu(), ds_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
21223 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21224 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
21225 printf("DS format VK_FORMAT_D24_UNORM_S8_UINT not supported, RenderPassDepthStencilLayoutTransition skipped.\n");
21226 return;
21227 }
21228
21229 m_errorMonitor->ExpectSuccess();
21230 ASSERT_NO_FATAL_FAILURE(InitState());
21231 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21232
21233 // A renderpass with one depth/stencil attachment.
21234 VkAttachmentDescription attachment = {0,
21235 ds_format,
21236 VK_SAMPLE_COUNT_1_BIT,
21237 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21238 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21239 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21240 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21241 VK_IMAGE_LAYOUT_UNDEFINED,
21242 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21243
21244 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21245
21246 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21247
21248 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21249
21250 VkRenderPass rp;
21251 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21252 ASSERT_VK_SUCCESS(err);
21253 // A compatible ds image.
21254 VkImageObj image(m_device);
21255 image.init(32, 32, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
21256 ASSERT_TRUE(image.initialized());
21257
21258 VkImageViewCreateInfo ivci = {
21259 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21260 nullptr,
21261 0,
21262 image.handle(),
21263 VK_IMAGE_VIEW_TYPE_2D,
21264 ds_format,
21265 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21266 VK_COMPONENT_SWIZZLE_IDENTITY},
21267 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21268 };
21269 VkImageView view;
21270 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21271 ASSERT_VK_SUCCESS(err);
21272
21273 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21274 VkFramebuffer fb;
21275 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21276 ASSERT_VK_SUCCESS(err);
21277
21278 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21279 m_commandBuffer->BeginCommandBuffer();
21280 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21281 vkCmdEndRenderPass(m_commandBuffer->handle());
21282 m_commandBuffer->EndCommandBuffer();
21283 QueueCommandBuffer(false);
21284 m_errorMonitor->VerifyNotFound();
21285
21286 // Cleanup
21287 vkDestroyImageView(m_device->device(), view, NULL);
21288 vkDestroyRenderPass(m_device->device(), rp, NULL);
21289 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21290}
21291
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021292TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021293 TEST_DESCRIPTION(
21294 "Test that pipeline validation accepts matrices passed "
21295 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021296 m_errorMonitor->ExpectSuccess();
21297
21298 ASSERT_NO_FATAL_FAILURE(InitState());
21299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21300
21301 VkVertexInputBindingDescription input_binding;
21302 memset(&input_binding, 0, sizeof(input_binding));
21303
21304 VkVertexInputAttributeDescription input_attribs[2];
21305 memset(input_attribs, 0, sizeof(input_attribs));
21306
21307 for (int i = 0; i < 2; i++) {
21308 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21309 input_attribs[i].location = i;
21310 }
21311
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021312 char const *vsSource =
21313 "#version 450\n"
21314 "\n"
21315 "layout(location=0) in mat2x4 x;\n"
21316 "out gl_PerVertex {\n"
21317 " vec4 gl_Position;\n"
21318 "};\n"
21319 "void main(){\n"
21320 " gl_Position = x[0] + x[1];\n"
21321 "}\n";
21322 char const *fsSource =
21323 "#version 450\n"
21324 "\n"
21325 "layout(location=0) out vec4 color;\n"
21326 "void main(){\n"
21327 " color = vec4(1);\n"
21328 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021329
21330 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21331 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21332
21333 VkPipelineObj pipe(m_device);
21334 pipe.AddColorAttachment();
21335 pipe.AddShader(&vs);
21336 pipe.AddShader(&fs);
21337
21338 pipe.AddVertexInputBindings(&input_binding, 1);
21339 pipe.AddVertexInputAttribs(input_attribs, 2);
21340
21341 VkDescriptorSetObj descriptorSet(m_device);
21342 descriptorSet.AppendDummy();
21343 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21344
21345 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21346
21347 /* expect success */
21348 m_errorMonitor->VerifyNotFound();
21349}
21350
21351TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21352 m_errorMonitor->ExpectSuccess();
21353
21354 ASSERT_NO_FATAL_FAILURE(InitState());
21355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21356
21357 VkVertexInputBindingDescription input_binding;
21358 memset(&input_binding, 0, sizeof(input_binding));
21359
21360 VkVertexInputAttributeDescription input_attribs[2];
21361 memset(input_attribs, 0, sizeof(input_attribs));
21362
21363 for (int i = 0; i < 2; i++) {
21364 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21365 input_attribs[i].location = i;
21366 }
21367
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021368 char const *vsSource =
21369 "#version 450\n"
21370 "\n"
21371 "layout(location=0) in vec4 x[2];\n"
21372 "out gl_PerVertex {\n"
21373 " vec4 gl_Position;\n"
21374 "};\n"
21375 "void main(){\n"
21376 " gl_Position = x[0] + x[1];\n"
21377 "}\n";
21378 char const *fsSource =
21379 "#version 450\n"
21380 "\n"
21381 "layout(location=0) out vec4 color;\n"
21382 "void main(){\n"
21383 " color = vec4(1);\n"
21384 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021385
21386 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21387 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21388
21389 VkPipelineObj pipe(m_device);
21390 pipe.AddColorAttachment();
21391 pipe.AddShader(&vs);
21392 pipe.AddShader(&fs);
21393
21394 pipe.AddVertexInputBindings(&input_binding, 1);
21395 pipe.AddVertexInputAttribs(input_attribs, 2);
21396
21397 VkDescriptorSetObj descriptorSet(m_device);
21398 descriptorSet.AppendDummy();
21399 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21400
21401 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21402
21403 m_errorMonitor->VerifyNotFound();
21404}
21405
21406TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021407 TEST_DESCRIPTION(
21408 "Test that pipeline validation accepts consuming a vertex attribute "
21409 "through multiple vertex shader inputs, each consuming a different "
21410 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021411 m_errorMonitor->ExpectSuccess();
21412
21413 ASSERT_NO_FATAL_FAILURE(InitState());
21414 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21415
21416 VkVertexInputBindingDescription input_binding;
21417 memset(&input_binding, 0, sizeof(input_binding));
21418
21419 VkVertexInputAttributeDescription input_attribs[3];
21420 memset(input_attribs, 0, sizeof(input_attribs));
21421
21422 for (int i = 0; i < 3; i++) {
21423 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21424 input_attribs[i].location = i;
21425 }
21426
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021427 char const *vsSource =
21428 "#version 450\n"
21429 "\n"
21430 "layout(location=0) in vec4 x;\n"
21431 "layout(location=1) in vec3 y1;\n"
21432 "layout(location=1, component=3) in float y2;\n"
21433 "layout(location=2) in vec4 z;\n"
21434 "out gl_PerVertex {\n"
21435 " vec4 gl_Position;\n"
21436 "};\n"
21437 "void main(){\n"
21438 " gl_Position = x + vec4(y1, y2) + z;\n"
21439 "}\n";
21440 char const *fsSource =
21441 "#version 450\n"
21442 "\n"
21443 "layout(location=0) out vec4 color;\n"
21444 "void main(){\n"
21445 " color = vec4(1);\n"
21446 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021447
21448 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21449 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21450
21451 VkPipelineObj pipe(m_device);
21452 pipe.AddColorAttachment();
21453 pipe.AddShader(&vs);
21454 pipe.AddShader(&fs);
21455
21456 pipe.AddVertexInputBindings(&input_binding, 1);
21457 pipe.AddVertexInputAttribs(input_attribs, 3);
21458
21459 VkDescriptorSetObj descriptorSet(m_device);
21460 descriptorSet.AppendDummy();
21461 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21462
21463 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21464
21465 m_errorMonitor->VerifyNotFound();
21466}
21467
21468TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21469 m_errorMonitor->ExpectSuccess();
21470
21471 ASSERT_NO_FATAL_FAILURE(InitState());
21472 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21473
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021474 char const *vsSource =
21475 "#version 450\n"
21476 "out gl_PerVertex {\n"
21477 " vec4 gl_Position;\n"
21478 "};\n"
21479 "void main(){\n"
21480 " gl_Position = vec4(0);\n"
21481 "}\n";
21482 char const *fsSource =
21483 "#version 450\n"
21484 "\n"
21485 "layout(location=0) out vec4 color;\n"
21486 "void main(){\n"
21487 " color = vec4(1);\n"
21488 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021489
21490 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21491 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21492
21493 VkPipelineObj pipe(m_device);
21494 pipe.AddColorAttachment();
21495 pipe.AddShader(&vs);
21496 pipe.AddShader(&fs);
21497
21498 VkDescriptorSetObj descriptorSet(m_device);
21499 descriptorSet.AppendDummy();
21500 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21501
21502 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21503
21504 m_errorMonitor->VerifyNotFound();
21505}
21506
21507TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021508 TEST_DESCRIPTION(
21509 "Test that pipeline validation accepts the relaxed type matching rules "
21510 "set out in 14.1.3: fundamental type must match, and producer side must "
21511 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021512 m_errorMonitor->ExpectSuccess();
21513
21514 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21515
21516 ASSERT_NO_FATAL_FAILURE(InitState());
21517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21518
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021519 char const *vsSource =
21520 "#version 450\n"
21521 "out gl_PerVertex {\n"
21522 " vec4 gl_Position;\n"
21523 "};\n"
21524 "layout(location=0) out vec3 x;\n"
21525 "layout(location=1) out ivec3 y;\n"
21526 "layout(location=2) out vec3 z;\n"
21527 "void main(){\n"
21528 " gl_Position = vec4(0);\n"
21529 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21530 "}\n";
21531 char const *fsSource =
21532 "#version 450\n"
21533 "\n"
21534 "layout(location=0) out vec4 color;\n"
21535 "layout(location=0) in float x;\n"
21536 "layout(location=1) flat in int y;\n"
21537 "layout(location=2) in vec2 z;\n"
21538 "void main(){\n"
21539 " color = vec4(1 + x + y + z.x);\n"
21540 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021541
21542 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21543 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21544
21545 VkPipelineObj pipe(m_device);
21546 pipe.AddColorAttachment();
21547 pipe.AddShader(&vs);
21548 pipe.AddShader(&fs);
21549
21550 VkDescriptorSetObj descriptorSet(m_device);
21551 descriptorSet.AppendDummy();
21552 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21553
21554 VkResult err = VK_SUCCESS;
21555 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21556 ASSERT_VK_SUCCESS(err);
21557
21558 m_errorMonitor->VerifyNotFound();
21559}
21560
21561TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021562 TEST_DESCRIPTION(
21563 "Test that pipeline validation accepts per-vertex variables "
21564 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021565 m_errorMonitor->ExpectSuccess();
21566
21567 ASSERT_NO_FATAL_FAILURE(InitState());
21568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21569
21570 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021571 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021572 return;
21573 }
21574
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021575 char const *vsSource =
21576 "#version 450\n"
21577 "void main(){}\n";
21578 char const *tcsSource =
21579 "#version 450\n"
21580 "layout(location=0) out int x[];\n"
21581 "layout(vertices=3) out;\n"
21582 "void main(){\n"
21583 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21584 " gl_TessLevelInner[0] = 1;\n"
21585 " x[gl_InvocationID] = gl_InvocationID;\n"
21586 "}\n";
21587 char const *tesSource =
21588 "#version 450\n"
21589 "layout(triangles, equal_spacing, cw) in;\n"
21590 "layout(location=0) in int x[];\n"
21591 "out gl_PerVertex { vec4 gl_Position; };\n"
21592 "void main(){\n"
21593 " gl_Position.xyz = gl_TessCoord;\n"
21594 " gl_Position.w = x[0] + x[1] + x[2];\n"
21595 "}\n";
21596 char const *fsSource =
21597 "#version 450\n"
21598 "layout(location=0) out vec4 color;\n"
21599 "void main(){\n"
21600 " color = vec4(1);\n"
21601 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021602
21603 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21604 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21605 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21606 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21607
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021608 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21609 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021610
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021611 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021612
21613 VkPipelineObj pipe(m_device);
21614 pipe.SetInputAssembly(&iasci);
21615 pipe.SetTessellation(&tsci);
21616 pipe.AddColorAttachment();
21617 pipe.AddShader(&vs);
21618 pipe.AddShader(&tcs);
21619 pipe.AddShader(&tes);
21620 pipe.AddShader(&fs);
21621
21622 VkDescriptorSetObj descriptorSet(m_device);
21623 descriptorSet.AppendDummy();
21624 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21625
21626 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21627
21628 m_errorMonitor->VerifyNotFound();
21629}
21630
21631TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021632 TEST_DESCRIPTION(
21633 "Test that pipeline validation accepts a user-defined "
21634 "interface block passed into the geometry shader. This "
21635 "is interesting because the 'extra' array level is not "
21636 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021637 m_errorMonitor->ExpectSuccess();
21638
21639 ASSERT_NO_FATAL_FAILURE(InitState());
21640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21641
21642 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021643 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021644 return;
21645 }
21646
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021647 char const *vsSource =
21648 "#version 450\n"
21649 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21650 "void main(){\n"
21651 " vs_out.x = vec4(1);\n"
21652 "}\n";
21653 char const *gsSource =
21654 "#version 450\n"
21655 "layout(triangles) in;\n"
21656 "layout(triangle_strip, max_vertices=3) out;\n"
21657 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21658 "out gl_PerVertex { vec4 gl_Position; };\n"
21659 "void main() {\n"
21660 " gl_Position = gs_in[0].x;\n"
21661 " EmitVertex();\n"
21662 "}\n";
21663 char const *fsSource =
21664 "#version 450\n"
21665 "layout(location=0) out vec4 color;\n"
21666 "void main(){\n"
21667 " color = vec4(1);\n"
21668 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021669
21670 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21671 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21672 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21673
21674 VkPipelineObj pipe(m_device);
21675 pipe.AddColorAttachment();
21676 pipe.AddShader(&vs);
21677 pipe.AddShader(&gs);
21678 pipe.AddShader(&fs);
21679
21680 VkDescriptorSetObj descriptorSet(m_device);
21681 descriptorSet.AppendDummy();
21682 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21683
21684 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21685
21686 m_errorMonitor->VerifyNotFound();
21687}
21688
21689TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021690 TEST_DESCRIPTION(
21691 "Test that pipeline validation accepts basic use of 64bit vertex "
21692 "attributes. This is interesting because they consume multiple "
21693 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021694 m_errorMonitor->ExpectSuccess();
21695
21696 ASSERT_NO_FATAL_FAILURE(InitState());
21697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21698
21699 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021700 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021701 return;
21702 }
21703
21704 VkVertexInputBindingDescription input_bindings[1];
21705 memset(input_bindings, 0, sizeof(input_bindings));
21706
21707 VkVertexInputAttributeDescription input_attribs[4];
21708 memset(input_attribs, 0, sizeof(input_attribs));
21709 input_attribs[0].location = 0;
21710 input_attribs[0].offset = 0;
21711 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21712 input_attribs[1].location = 2;
21713 input_attribs[1].offset = 32;
21714 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21715 input_attribs[2].location = 4;
21716 input_attribs[2].offset = 64;
21717 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21718 input_attribs[3].location = 6;
21719 input_attribs[3].offset = 96;
21720 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21721
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021722 char const *vsSource =
21723 "#version 450\n"
21724 "\n"
21725 "layout(location=0) in dmat4 x;\n"
21726 "out gl_PerVertex {\n"
21727 " vec4 gl_Position;\n"
21728 "};\n"
21729 "void main(){\n"
21730 " gl_Position = vec4(x[0][0]);\n"
21731 "}\n";
21732 char const *fsSource =
21733 "#version 450\n"
21734 "\n"
21735 "layout(location=0) out vec4 color;\n"
21736 "void main(){\n"
21737 " color = vec4(1);\n"
21738 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021739
21740 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21741 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21742
21743 VkPipelineObj pipe(m_device);
21744 pipe.AddColorAttachment();
21745 pipe.AddShader(&vs);
21746 pipe.AddShader(&fs);
21747
21748 pipe.AddVertexInputBindings(input_bindings, 1);
21749 pipe.AddVertexInputAttribs(input_attribs, 4);
21750
21751 VkDescriptorSetObj descriptorSet(m_device);
21752 descriptorSet.AppendDummy();
21753 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21754
21755 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21756
21757 m_errorMonitor->VerifyNotFound();
21758}
21759
21760TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21761 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21762 m_errorMonitor->ExpectSuccess();
21763
21764 ASSERT_NO_FATAL_FAILURE(InitState());
21765
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021766 char const *vsSource =
21767 "#version 450\n"
21768 "\n"
21769 "out gl_PerVertex {\n"
21770 " vec4 gl_Position;\n"
21771 "};\n"
21772 "void main(){\n"
21773 " gl_Position = vec4(1);\n"
21774 "}\n";
21775 char const *fsSource =
21776 "#version 450\n"
21777 "\n"
21778 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21779 "layout(location=0) out vec4 color;\n"
21780 "void main() {\n"
21781 " color = subpassLoad(x);\n"
21782 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021783
21784 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21785 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21786
21787 VkPipelineObj pipe(m_device);
21788 pipe.AddShader(&vs);
21789 pipe.AddShader(&fs);
21790 pipe.AddColorAttachment();
21791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21792
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021793 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21794 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021795 VkDescriptorSetLayout dsl;
21796 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21797 ASSERT_VK_SUCCESS(err);
21798
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021799 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021800 VkPipelineLayout pl;
21801 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21802 ASSERT_VK_SUCCESS(err);
21803
21804 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021805 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21806 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21807 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21808 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21809 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 -060021810 };
21811 VkAttachmentReference color = {
21812 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21813 };
21814 VkAttachmentReference input = {
21815 1, VK_IMAGE_LAYOUT_GENERAL,
21816 };
21817
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021818 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021819
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021820 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021821 VkRenderPass rp;
21822 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21823 ASSERT_VK_SUCCESS(err);
21824
21825 // should be OK. would go wrong here if it's going to...
21826 pipe.CreateVKPipeline(pl, rp);
21827
21828 m_errorMonitor->VerifyNotFound();
21829
21830 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21831 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21832 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21833}
21834
21835TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021836 TEST_DESCRIPTION(
21837 "Test that pipeline validation accepts a compute pipeline which declares a "
21838 "descriptor-backed resource which is not provided, but the shader does not "
21839 "statically use it. This is interesting because it requires compute pipelines "
21840 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021841 m_errorMonitor->ExpectSuccess();
21842
21843 ASSERT_NO_FATAL_FAILURE(InitState());
21844
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021845 char const *csSource =
21846 "#version 450\n"
21847 "\n"
21848 "layout(local_size_x=1) in;\n"
21849 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21850 "void main(){\n"
21851 " // x is not used.\n"
21852 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021853
21854 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21855
21856 VkDescriptorSetObj descriptorSet(m_device);
21857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21858
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021859 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21860 nullptr,
21861 0,
21862 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21863 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21864 descriptorSet.GetPipelineLayout(),
21865 VK_NULL_HANDLE,
21866 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021867
21868 VkPipeline pipe;
21869 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21870
21871 m_errorMonitor->VerifyNotFound();
21872
21873 if (err == VK_SUCCESS) {
21874 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21875 }
21876}
21877
21878TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021879 TEST_DESCRIPTION(
21880 "Test that pipeline validation accepts a shader consuming only the "
21881 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021882 m_errorMonitor->ExpectSuccess();
21883
21884 ASSERT_NO_FATAL_FAILURE(InitState());
21885
21886 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021887 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21888 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21889 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021890 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021891 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021892 VkDescriptorSetLayout dsl;
21893 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21894 ASSERT_VK_SUCCESS(err);
21895
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021896 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021897 VkPipelineLayout pl;
21898 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21899 ASSERT_VK_SUCCESS(err);
21900
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021901 char const *csSource =
21902 "#version 450\n"
21903 "\n"
21904 "layout(local_size_x=1) in;\n"
21905 "layout(set=0, binding=0) uniform sampler s;\n"
21906 "layout(set=0, binding=1) uniform texture2D t;\n"
21907 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21908 "void main() {\n"
21909 " x = texture(sampler2D(t, s), vec2(0));\n"
21910 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021911 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21912
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021913 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21914 nullptr,
21915 0,
21916 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21917 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21918 pl,
21919 VK_NULL_HANDLE,
21920 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021921
21922 VkPipeline pipe;
21923 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21924
21925 m_errorMonitor->VerifyNotFound();
21926
21927 if (err == VK_SUCCESS) {
21928 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21929 }
21930
21931 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21932 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21933}
21934
21935TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021936 TEST_DESCRIPTION(
21937 "Test that pipeline validation accepts a shader consuming only the "
21938 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021939 m_errorMonitor->ExpectSuccess();
21940
21941 ASSERT_NO_FATAL_FAILURE(InitState());
21942
21943 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021944 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21945 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21946 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021947 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021948 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021949 VkDescriptorSetLayout dsl;
21950 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21951 ASSERT_VK_SUCCESS(err);
21952
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021953 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021954 VkPipelineLayout pl;
21955 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21956 ASSERT_VK_SUCCESS(err);
21957
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021958 char const *csSource =
21959 "#version 450\n"
21960 "\n"
21961 "layout(local_size_x=1) in;\n"
21962 "layout(set=0, binding=0) uniform texture2D t;\n"
21963 "layout(set=0, binding=1) uniform sampler s;\n"
21964 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21965 "void main() {\n"
21966 " x = texture(sampler2D(t, s), vec2(0));\n"
21967 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021968 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21969
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021970 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21971 nullptr,
21972 0,
21973 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21974 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21975 pl,
21976 VK_NULL_HANDLE,
21977 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021978
21979 VkPipeline pipe;
21980 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21981
21982 m_errorMonitor->VerifyNotFound();
21983
21984 if (err == VK_SUCCESS) {
21985 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21986 }
21987
21988 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21989 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21990}
21991
21992TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021993 TEST_DESCRIPTION(
21994 "Test that pipeline validation accepts a shader consuming "
21995 "both the sampler and the image of a combined image+sampler "
21996 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021997 m_errorMonitor->ExpectSuccess();
21998
21999 ASSERT_NO_FATAL_FAILURE(InitState());
22000
22001 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022002 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22003 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022004 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022005 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022006 VkDescriptorSetLayout dsl;
22007 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22008 ASSERT_VK_SUCCESS(err);
22009
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022010 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022011 VkPipelineLayout pl;
22012 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22013 ASSERT_VK_SUCCESS(err);
22014
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022015 char const *csSource =
22016 "#version 450\n"
22017 "\n"
22018 "layout(local_size_x=1) in;\n"
22019 "layout(set=0, binding=0) uniform texture2D t;\n"
22020 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22021 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22022 "void main() {\n"
22023 " x = texture(sampler2D(t, s), vec2(0));\n"
22024 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022025 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22026
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022027 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22028 nullptr,
22029 0,
22030 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22031 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22032 pl,
22033 VK_NULL_HANDLE,
22034 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022035
22036 VkPipeline pipe;
22037 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22038
22039 m_errorMonitor->VerifyNotFound();
22040
22041 if (err == VK_SUCCESS) {
22042 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22043 }
22044
22045 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22046 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22047}
22048
22049TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22050 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22051
22052 ASSERT_NO_FATAL_FAILURE(InitState());
22053
22054 // Positive test to check parameter_validation and unique_objects support
22055 // for NV_dedicated_allocation
22056 uint32_t extension_count = 0;
22057 bool supports_nv_dedicated_allocation = false;
22058 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22059 ASSERT_VK_SUCCESS(err);
22060
22061 if (extension_count > 0) {
22062 std::vector<VkExtensionProperties> available_extensions(extension_count);
22063
22064 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22065 ASSERT_VK_SUCCESS(err);
22066
22067 for (const auto &extension_props : available_extensions) {
22068 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22069 supports_nv_dedicated_allocation = true;
22070 }
22071 }
22072 }
22073
22074 if (supports_nv_dedicated_allocation) {
22075 m_errorMonitor->ExpectSuccess();
22076
22077 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22078 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22079 dedicated_buffer_create_info.pNext = nullptr;
22080 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22081
22082 uint32_t queue_family_index = 0;
22083 VkBufferCreateInfo buffer_create_info = {};
22084 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22085 buffer_create_info.pNext = &dedicated_buffer_create_info;
22086 buffer_create_info.size = 1024;
22087 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22088 buffer_create_info.queueFamilyIndexCount = 1;
22089 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22090
22091 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022092 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022093 ASSERT_VK_SUCCESS(err);
22094
22095 VkMemoryRequirements memory_reqs;
22096 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22097
22098 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22099 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22100 dedicated_memory_info.pNext = nullptr;
22101 dedicated_memory_info.buffer = buffer;
22102 dedicated_memory_info.image = VK_NULL_HANDLE;
22103
22104 VkMemoryAllocateInfo memory_info = {};
22105 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22106 memory_info.pNext = &dedicated_memory_info;
22107 memory_info.allocationSize = memory_reqs.size;
22108
22109 bool pass;
22110 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22111 ASSERT_TRUE(pass);
22112
22113 VkDeviceMemory buffer_memory;
22114 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22115 ASSERT_VK_SUCCESS(err);
22116
22117 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22118 ASSERT_VK_SUCCESS(err);
22119
22120 vkDestroyBuffer(m_device->device(), buffer, NULL);
22121 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22122
22123 m_errorMonitor->VerifyNotFound();
22124 }
22125}
22126
22127TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22128 VkResult err;
22129
22130 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22131
22132 ASSERT_NO_FATAL_FAILURE(InitState());
22133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22134
22135 std::vector<const char *> device_extension_names;
22136 auto features = m_device->phy().features();
22137 // Artificially disable support for non-solid fill modes
22138 features.fillModeNonSolid = false;
22139 // The sacrificial device object
22140 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22141
22142 VkRenderpassObj render_pass(&test_device);
22143
22144 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22145 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22146 pipeline_layout_ci.setLayoutCount = 0;
22147 pipeline_layout_ci.pSetLayouts = NULL;
22148
22149 VkPipelineLayout pipeline_layout;
22150 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22151 ASSERT_VK_SUCCESS(err);
22152
22153 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22154 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22155 rs_ci.pNext = nullptr;
22156 rs_ci.lineWidth = 1.0f;
22157 rs_ci.rasterizerDiscardEnable = true;
22158
22159 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22160 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22161
22162 // Set polygonMode=FILL. No error is expected
22163 m_errorMonitor->ExpectSuccess();
22164 {
22165 VkPipelineObj pipe(&test_device);
22166 pipe.AddShader(&vs);
22167 pipe.AddShader(&fs);
22168 pipe.AddColorAttachment();
22169 // Set polygonMode to a good value
22170 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22171 pipe.SetRasterization(&rs_ci);
22172 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22173 }
22174 m_errorMonitor->VerifyNotFound();
22175
22176 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22177}
22178
22179TEST_F(VkPositiveLayerTest, ValidPushConstants) {
22180 VkResult err;
22181 ASSERT_NO_FATAL_FAILURE(InitState());
22182 ASSERT_NO_FATAL_FAILURE(InitViewport());
22183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22184
22185 VkPipelineLayout pipeline_layout;
22186 VkPushConstantRange pc_range = {};
22187 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22188 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22189 pipeline_layout_ci.pushConstantRangeCount = 1;
22190 pipeline_layout_ci.pPushConstantRanges = &pc_range;
22191
22192 //
22193 // Check for invalid push constant ranges in pipeline layouts.
22194 //
22195 struct PipelineLayoutTestCase {
22196 VkPushConstantRange const range;
22197 char const *msg;
22198 };
22199
22200 // Check for overlapping ranges
22201 const uint32_t ranges_per_test = 5;
22202 struct OverlappingRangeTestCase {
22203 VkPushConstantRange const ranges[ranges_per_test];
22204 char const *msg;
22205 };
22206
22207 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022208 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
22209 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
22210 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
22211 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
22212 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
22213 ""},
22214 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
22215 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
22216 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
22217 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
22218 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
22219 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022220 for (const auto &iter : overlapping_range_tests_pos) {
22221 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
22222 m_errorMonitor->ExpectSuccess();
22223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22224 m_errorMonitor->VerifyNotFound();
22225 if (VK_SUCCESS == err) {
22226 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22227 }
22228 }
22229
22230 //
22231 // CmdPushConstants tests
22232 //
22233 const uint8_t dummy_values[100] = {};
22234
Tony Barbour552f6c02016-12-21 14:34:07 -070022235 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022236
22237 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022238 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
22239 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
22240 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
22241 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
22242 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
22243 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022244
22245 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
22246 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022247 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
22248 {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 -060022249 };
22250
22251 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
22252 pipeline_layout_ci.pPushConstantRanges = pc_range4;
22253 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22254 ASSERT_VK_SUCCESS(err);
22255 for (const auto &iter : cmd_overlap_tests_pos) {
22256 m_errorMonitor->ExpectSuccess();
22257 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022258 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022259 m_errorMonitor->VerifyNotFound();
22260 }
22261 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22262
Tony Barbour552f6c02016-12-21 14:34:07 -070022263 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022264}
22265
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022266#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022267TEST_F(VkPositiveLayerTest, LongFenceChain)
22268{
22269 m_errorMonitor->ExpectSuccess();
22270
22271 ASSERT_NO_FATAL_FAILURE(InitState());
22272 VkResult err;
22273
22274 std::vector<VkFence> fences;
22275
22276 const int chainLength = 32768;
22277
22278 for (int i = 0; i < chainLength; i++) {
22279 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22280 VkFence fence;
22281 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22282 ASSERT_VK_SUCCESS(err);
22283
22284 fences.push_back(fence);
22285
22286 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22287 0, nullptr, 0, nullptr };
22288 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22289 ASSERT_VK_SUCCESS(err);
22290
22291 }
22292
22293 // BOOM, stack overflow.
22294 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22295
22296 for (auto fence : fences)
22297 vkDestroyFence(m_device->device(), fence, nullptr);
22298
22299 m_errorMonitor->VerifyNotFound();
22300}
22301#endif
22302
Cody Northrop1242dfd2016-07-13 17:24:59 -060022303#if defined(ANDROID) && defined(VALIDATION_APK)
22304static bool initialized = false;
22305static bool active = false;
22306
22307// Convert Intents to argv
22308// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022309std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022310 std::vector<std::string> args;
22311 JavaVM &vm = *app.activity->vm;
22312 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022313 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022314
22315 JNIEnv &env = *p_env;
22316 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022317 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022318 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022319 jmethodID get_string_extra_method =
22320 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022321 jvalue get_string_extra_args;
22322 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022323 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022324
22325 std::string args_str;
22326 if (extra_str) {
22327 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22328 args_str = extra_utf;
22329 env.ReleaseStringUTFChars(extra_str, extra_utf);
22330 env.DeleteLocalRef(extra_str);
22331 }
22332
22333 env.DeleteLocalRef(get_string_extra_args.l);
22334 env.DeleteLocalRef(intent);
22335 vm.DetachCurrentThread();
22336
22337 // split args_str
22338 std::stringstream ss(args_str);
22339 std::string arg;
22340 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022341 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022342 }
22343
22344 return args;
22345}
22346
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022347static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022349static void processCommand(struct android_app *app, int32_t cmd) {
22350 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022351 case APP_CMD_INIT_WINDOW: {
22352 if (app->window) {
22353 initialized = true;
22354 }
22355 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022356 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022357 case APP_CMD_GAINED_FOCUS: {
22358 active = true;
22359 break;
22360 }
22361 case APP_CMD_LOST_FOCUS: {
22362 active = false;
22363 break;
22364 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022365 }
22366}
22367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022368void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022369 app_dummy();
22370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022371 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022372
22373 int vulkanSupport = InitVulkan();
22374 if (vulkanSupport == 0) {
22375 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22376 return;
22377 }
22378
22379 app->onAppCmd = processCommand;
22380 app->onInputEvent = processInput;
22381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022382 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022383 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022384 struct android_poll_source *source;
22385 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022386 if (source) {
22387 source->process(app, source);
22388 }
22389
22390 if (app->destroyRequested != 0) {
22391 VkTestFramework::Finish();
22392 return;
22393 }
22394 }
22395
22396 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022397 // Use the following key to send arguments to gtest, i.e.
22398 // --es args "--gtest_filter=-VkLayerTest.foo"
22399 const char key[] = "args";
22400 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022401
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022402 std::string filter = "";
22403 if (args.size() > 0) {
22404 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22405 filter += args[0];
22406 } else {
22407 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22408 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022410 int argc = 2;
22411 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22412 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022414 // Route output to files until we can override the gtest output
22415 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22416 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022418 ::testing::InitGoogleTest(&argc, argv);
22419 VkTestFramework::InitArgs(&argc, argv);
22420 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022421
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022422 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022424 if (result != 0) {
22425 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22426 } else {
22427 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22428 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022430 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022432 fclose(stdout);
22433 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022435 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022436 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022437 }
22438 }
22439}
22440#endif
22441
Tony Barbour300a6082015-04-07 13:44:53 -060022442int main(int argc, char **argv) {
22443 int result;
22444
Cody Northrop8e54a402016-03-08 22:25:52 -070022445#ifdef ANDROID
22446 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022447 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022448#endif
22449
Tony Barbour300a6082015-04-07 13:44:53 -060022450 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022451 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022452
22453 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22454
22455 result = RUN_ALL_TESTS();
22456
Tony Barbour6918cd52015-04-09 12:58:51 -060022457 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022458 return result;
22459}