blob: adb25fda403a51024ab9801944fdf70d6d82cf4c [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;
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600358 bool m_enable_maintenance1_ext;
Tony Barbour300a6082015-04-07 13:44:53 -0600359
360 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600361 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600362 std::vector<const char *> instance_extension_names;
363 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600364
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700365 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600366 /*
367 * Since CreateDbgMsgCallback is an instance level extension call
368 * any extension / layer that utilizes that feature also needs
369 * to be enabled at create instance time.
370 */
Karl Schultz6addd812016-02-02 17:17:23 -0700371 // Use Threading layer first to protect others from
372 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700373 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600374 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800375 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700376 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600377 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700378 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600379
Ian Elliott2c1daf52016-05-12 09:41:46 -0600380 if (m_enableWSI) {
381 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
382 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
383#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
384#if defined(VK_USE_PLATFORM_ANDROID_KHR)
385 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700386#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600387#if defined(VK_USE_PLATFORM_MIR_KHR)
388 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700389#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600390#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
391 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700392#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600393#if defined(VK_USE_PLATFORM_WIN32_KHR)
394 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700395#endif // VK_USE_PLATFORM_WIN32_KHR
396#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600397#if defined(VK_USE_PLATFORM_XCB_KHR)
398 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
399#elif defined(VK_USE_PLATFORM_XLIB_KHR)
400 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700401#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600402 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600403 if (m_enable_maintenance1_ext) {
404 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
405 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600406
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600407 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600408 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 this->app_info.pApplicationName = "layer_tests";
410 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600411 this->app_info.pEngineName = "unittest";
412 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600413 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600414
Tony Barbour15524c32015-04-29 17:34:29 -0600415 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600416 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600417 }
418
419 virtual void TearDown() {
420 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600421 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600422 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600423 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600424
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600425 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600426};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500427
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600428void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500429 // Create identity matrix
430 int i;
431 struct vktriangle_vs_uniform data;
432
433 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 glm::mat4 View = glm::mat4(1.0f);
435 glm::mat4 Model = glm::mat4(1.0f);
436 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500437 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700438 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500439
440 memcpy(&data.mvp, &MVP[0][0], matrixSize);
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 {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 -0500444 };
445
Karl Schultz6addd812016-02-02 17:17:23 -0700446 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447 data.position[i][0] = tri_data[i].posX;
448 data.position[i][1] = tri_data[i].posY;
449 data.position[i][2] = tri_data[i].posZ;
450 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700451 data.color[i][0] = tri_data[i].r;
452 data.color[i][1] = tri_data[i].g;
453 data.color[i][2] = tri_data[i].b;
454 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500455 }
456
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457 ASSERT_NO_FATAL_FAILURE(InitViewport());
458
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200459 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
460 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500461
Karl Schultz6addd812016-02-02 17:17:23 -0700462 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464
465 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800466 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 pipelineobj.AddShader(&vs);
468 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 if (failMask & BsoFailLineWidth) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600472 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600473 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
474 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 }
476 if (failMask & BsoFailDepthBias) {
477 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600479 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600481 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600482 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600483 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700484 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700485 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600486 if (failMask & BsoFailViewport) {
487 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
488 }
489 if (failMask & BsoFailScissor) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
491 }
492 if (failMask & BsoFailBlend) {
493 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600494 VkPipelineColorBlendAttachmentState att_state = {};
495 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
496 att_state.blendEnable = VK_TRUE;
497 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600498 }
499 if (failMask & BsoFailDepthBounds) {
500 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
501 }
502 if (failMask & BsoFailStencilReadMask) {
503 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
504 }
505 if (failMask & BsoFailStencilWriteMask) {
506 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
507 }
508 if (failMask & BsoFailStencilReference) {
509 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
510 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511
512 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600513 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700516 m_commandBuffer->BeginCommandBuffer();
517 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500518
Tony Barbourfe3351b2015-07-28 10:17:20 -0600519 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500520
521 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600522 if (failMask & BsoFailIndexBuffer) {
523 // Use DrawIndexed w/o an index buffer bound
524 DrawIndexed(3, 1, 0, 0, 0);
525 } else {
526 Draw(3, 1, 0, 0);
527 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Mark Muellerd4914412016-06-13 17:52:06 -0600529 if (failMask & BsoFailCmdClearAttachments) {
530 VkClearAttachment color_attachment = {};
531 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700532 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600533 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
534
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600536 }
537
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700539 m_commandBuffer->EndRenderPass();
540 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600541 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542}
543
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600544void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
545 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600547 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500548 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500550 }
551
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800552 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700553 // Make sure depthWriteEnable is set so that Depth fail test will work
554 // correctly
555 // Make sure stencilTestEnable is set so that Stencil fail test will work
556 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600557 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800558 stencil.failOp = VK_STENCIL_OP_KEEP;
559 stencil.passOp = VK_STENCIL_OP_KEEP;
560 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
561 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600562
563 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
564 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600565 ds_ci.pNext = NULL;
566 ds_ci.depthTestEnable = VK_FALSE;
567 ds_ci.depthWriteEnable = VK_TRUE;
568 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
569 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 if (failMask & BsoFailDepthBounds) {
571 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600572 ds_ci.maxDepthBounds = 0.0f;
573 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600574 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600575 ds_ci.stencilTestEnable = VK_TRUE;
576 ds_ci.front = stencil;
577 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600578
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600579 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600580 pipelineobj.SetViewport(m_viewports);
581 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800582 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600583 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600584 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800585 commandBuffer->BindPipeline(pipelineobj);
586 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500587}
588
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600589class VkMaintenance1LayerTest : public VkLayerTest {
590 public:
591 protected:
592 VkMaintenance1LayerTest(){ m_enable_maintenance1_ext = true; }
593};
594
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600595class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700596 public:
597 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600598};
599
Ian Elliott2c1daf52016-05-12 09:41:46 -0600600class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700601 public:
602 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600604};
605
Mark Muellerdfe37552016-07-07 14:47:42 -0600606class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700607 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600608 enum eTestEnFlags {
609 eDoubleDelete,
610 eInvalidDeviceOffset,
611 eInvalidMemoryOffset,
612 eBindNullBuffer,
613 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600614 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600615 };
616
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600617 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600618
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
620 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 return true;
622 }
623 VkDeviceSize offset_limit = 0;
624 if (eInvalidMemoryOffset == aTestFlag) {
625 VkBuffer vulkanBuffer;
626 VkBufferCreateInfo buffer_create_info = {};
627 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
628 buffer_create_info.size = 32;
629 buffer_create_info.usage = aBufferUsage;
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600632 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600633
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600634 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
636 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600637 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
638 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600639 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600640 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600641 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 }
644 if (eOffsetAlignment < offset_limit) {
645 return true;
646 }
647 return false;
648 }
649
650 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
652 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 if (eBindNullBuffer == aTestFlag) {
654 VulkanMemory = 0;
655 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
656 } else {
657 VkBufferCreateInfo buffer_create_info = {};
658 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
659 buffer_create_info.size = 32;
660 buffer_create_info.usage = aBufferUsage;
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663
664 CreateCurrent = true;
665
666 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600667 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600668
669 VkMemoryAllocateInfo memory_allocate_info = {};
670 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800671 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
673 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 if (!pass) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 return;
677 }
678
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600679 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600680 AllocateCurrent = true;
681 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600682 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
683 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600684 BoundCurrent = true;
685
686 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
687 }
688 }
689
690 ~VkBufferTest() {
691 if (CreateCurrent) {
692 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
693 }
694 if (AllocateCurrent) {
695 if (InvalidDeleteEn) {
696 union {
697 VkDeviceMemory device_memory;
698 unsigned long long index_access;
699 } bad_index;
700
701 bad_index.device_memory = VulkanMemory;
702 bad_index.index_access++;
703
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600704 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600705 }
706 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
707 }
708 }
709
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600710 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600711
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600713
714 void TestDoubleDestroy() {
715 // Destroy the buffer but leave the flag set, which will cause
716 // the buffer to be destroyed again in the destructor.
717 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
718 }
719
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700720 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600721 bool AllocateCurrent;
722 bool BoundCurrent;
723 bool CreateCurrent;
724 bool InvalidDeleteEn;
725
726 VkBuffer VulkanBuffer;
727 VkDevice VulkanDevice;
728 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729};
730
731class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600733 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600734 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700735 : BoundCurrent(false),
736 AttributeCount(aAttributeCount),
737 BindingCount(aBindingCount),
738 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600740 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
741 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700742 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600743
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600744 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
745 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600746
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
748 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
749 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
750 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
751 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600752
753 unsigned i = 0;
754 do {
755 VertexInputAttributeDescription[i].binding = BindId;
756 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600757 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
758 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600759 i++;
760 } while (AttributeCount < i);
761
762 i = 0;
763 do {
764 VertexInputBindingDescription[i].binding = BindId;
765 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 i++;
768 } while (BindingCount < i);
769 }
770
771 ~VkVerticesObj() {
772 if (VertexInputAttributeDescription) {
773 delete[] VertexInputAttributeDescription;
774 }
775 if (VertexInputBindingDescription) {
776 delete[] VertexInputBindingDescription;
777 }
778 }
779
780 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600781 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
782 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 return true;
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 VkDeviceSize *offsetList;
788 unsigned offsetCount;
789
790 if (aOffsetCount) {
791 offsetList = aOffsetList;
792 offsetCount = aOffsetCount;
793 } else {
794 offsetList = new VkDeviceSize[1]();
795 offsetCount = 1;
796 }
797
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600798 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600799 BoundCurrent = true;
800
801 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600802 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600803 }
804 }
805
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700806 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600807 static uint32_t BindIdGenerator;
808
809 bool BoundCurrent;
810 unsigned AttributeCount;
811 unsigned BindingCount;
812 uint32_t BindId;
813
814 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
815 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
816 VkVertexInputBindingDescription *VertexInputBindingDescription;
817 VkConstantBufferObj VulkanMemoryBuffer;
818};
819
820uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500821// ********************************************************************************************************************
822// ********************************************************************************************************************
823// ********************************************************************************************************************
824// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600825TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700826 TEST_DESCRIPTION(
827 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
828 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600829
830 ASSERT_NO_FATAL_FAILURE(InitState());
831
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600833 // Specify NULL for a pointer to a handle
834 // Expected to trigger an error with
835 // parameter_validation::validate_required_pointer
836 vkGetPhysicalDeviceFeatures(gpu(), NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
840 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600841 // Specify NULL for pointer to array count
842 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600843 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify 0 for a required array count
848 // Expected to trigger an error with parameter_validation::validate_array
849 VkViewport view_port = {};
850 m_commandBuffer->SetViewport(0, 0, &view_port);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600854 // Specify NULL for a required array
855 // Expected to trigger an error with parameter_validation::validate_array
856 m_commandBuffer->SetViewport(0, 1, NULL);
857 m_errorMonitor->VerifyFound();
858
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600860 // Specify VK_NULL_HANDLE for a required handle
861 // Expected to trigger an error with
862 // parameter_validation::validate_required_handle
863 vkUnmapMemory(device(), VK_NULL_HANDLE);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
867 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600868 // Specify VK_NULL_HANDLE for a required handle array entry
869 // Expected to trigger an error with
870 // parameter_validation::validate_required_handle_array
871 VkFence fence = VK_NULL_HANDLE;
872 vkResetFences(device(), 1, &fence);
873 m_errorMonitor->VerifyFound();
874
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600876 // Specify NULL for a required struct pointer
877 // Expected to trigger an error with
878 // parameter_validation::validate_struct_type
879 VkDeviceMemory memory = VK_NULL_HANDLE;
880 vkAllocateMemory(device(), NULL, NULL, &memory);
881 m_errorMonitor->VerifyFound();
882
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600884 // Specify 0 for a required VkFlags parameter
885 // Expected to trigger an error with parameter_validation::validate_flags
886 m_commandBuffer->SetStencilReference(0, 0);
887 m_errorMonitor->VerifyFound();
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 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 -0600890 // Specify 0 for a required VkFlags array entry
891 // Expected to trigger an error with
892 // parameter_validation::validate_flags_array
893 VkSemaphore semaphore = VK_NULL_HANDLE;
894 VkPipelineStageFlags stageFlags = 0;
895 VkSubmitInfo submitInfo = {};
896 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
897 submitInfo.waitSemaphoreCount = 1;
898 submitInfo.pWaitSemaphores = &semaphore;
899 submitInfo.pWaitDstStageMask = &stageFlags;
900 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
901 m_errorMonitor->VerifyFound();
902}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600903
Dustin Gravesfce74c02016-05-10 11:42:58 -0600904TEST_F(VkLayerTest, ReservedParameter) {
905 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
906
907 ASSERT_NO_FATAL_FAILURE(InitState());
908
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600910 // Specify 0 for a reserved VkFlags parameter
911 // Expected to trigger an error with
912 // parameter_validation::validate_reserved_flags
913 VkEvent event_handle = VK_NULL_HANDLE;
914 VkEventCreateInfo event_info = {};
915 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
916 event_info.flags = 1;
917 vkCreateEvent(device(), &event_info, NULL, &event_handle);
918 m_errorMonitor->VerifyFound();
919}
920
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600921TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700922 TEST_DESCRIPTION(
923 "Specify an invalid VkStructureType for a Vulkan "
924 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600925
926 ASSERT_NO_FATAL_FAILURE(InitState());
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->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
933 VkMemoryAllocateInfo alloc_info = {};
934 VkDeviceMemory memory = VK_NULL_HANDLE;
935 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
936 m_errorMonitor->VerifyFound();
937
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939 // Zero struct memory, effectively setting sType to
940 // VK_STRUCTURE_TYPE_APPLICATION_INFO
941 // Expected to trigger an error with
942 // parameter_validation::validate_struct_type_array
943 VkSubmitInfo submit_info = {};
944 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
945 m_errorMonitor->VerifyFound();
946}
947
948TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600949 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600950
951 ASSERT_NO_FATAL_FAILURE(InitState());
952
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600954 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600955 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600956 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600957 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600958 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600959 // Zero-initialization will provide the correct sType
960 VkApplicationInfo app_info = {};
961 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
962 event_alloc_info.pNext = &app_info;
963 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
964 m_errorMonitor->VerifyFound();
965
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
967 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600968 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
969 // a function that has allowed pNext structure types and specify
970 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600971 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600972 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600973 VkMemoryAllocateInfo memory_alloc_info = {};
974 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
975 memory_alloc_info.pNext = &app_info;
976 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600977 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600978}
Dustin Graves5d33d532016-05-09 16:21:12 -0600979
980TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600981 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600982
983 ASSERT_NO_FATAL_FAILURE(InitState());
984
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
986 "does not fall within the begin..end "
987 "range of the core VkFormat "
988 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600989 // Specify an invalid VkFormat value
990 // Expected to trigger an error with
991 // parameter_validation::validate_ranged_enum
992 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 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 -0600997 // Specify an invalid VkFlags bitmask value
998 // Expected to trigger an error with parameter_validation::validate_flags
999 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001000 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1001 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001002 m_errorMonitor->VerifyFound();
1003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001004 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 -06001005 // Specify an invalid VkFlags array entry
1006 // Expected to trigger an error with
1007 // parameter_validation::validate_flags_array
1008 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001009 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001010 VkSubmitInfo submit_info = {};
1011 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1012 submit_info.waitSemaphoreCount = 1;
1013 submit_info.pWaitSemaphores = &semaphore;
1014 submit_info.pWaitDstStageMask = &stage_flags;
1015 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1016 m_errorMonitor->VerifyFound();
1017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001019 // Specify an invalid VkBool32 value
1020 // Expected to trigger a warning with
1021 // parameter_validation::validate_bool32
1022 VkSampler sampler = VK_NULL_HANDLE;
1023 VkSamplerCreateInfo sampler_info = {};
1024 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1025 sampler_info.pNext = NULL;
1026 sampler_info.magFilter = VK_FILTER_NEAREST;
1027 sampler_info.minFilter = VK_FILTER_NEAREST;
1028 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1029 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1030 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1031 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1032 sampler_info.mipLodBias = 1.0;
1033 sampler_info.maxAnisotropy = 1;
1034 sampler_info.compareEnable = VK_FALSE;
1035 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1036 sampler_info.minLod = 1.0;
1037 sampler_info.maxLod = 1.0;
1038 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1039 sampler_info.unnormalizedCoordinates = VK_FALSE;
1040 // Not VK_TRUE or VK_FALSE
1041 sampler_info.anisotropyEnable = 3;
1042 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1043 m_errorMonitor->VerifyFound();
1044}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001045
1046TEST_F(VkLayerTest, FailedReturnValue) {
1047 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1048
1049 ASSERT_NO_FATAL_FAILURE(InitState());
1050
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001051 // Find an unsupported image format
1052 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1053 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1054 VkFormat format = static_cast<VkFormat>(f);
1055 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001056 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001057 unsupported = format;
1058 break;
1059 }
1060 }
1061
1062 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1064 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001065 // Specify an unsupported VkFormat value to generate a
1066 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1067 // Expected to trigger a warning from
1068 // parameter_validation::validate_result
1069 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001070 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1071 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001072 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1073 m_errorMonitor->VerifyFound();
1074 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001075}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076
1077TEST_F(VkLayerTest, UpdateBufferAlignment) {
1078 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080
1081 ASSERT_NO_FATAL_FAILURE(InitState());
1082
1083 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1084 vk_testing::Buffer buffer;
1085 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1086
Tony Barbour552f6c02016-12-21 14:34:07 -07001087 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001088 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1091 m_errorMonitor->VerifyFound();
1092
1093 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001095 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1096 m_errorMonitor->VerifyFound();
1097
1098 // Introduce failure by using dataSize that is < 0
1099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using dataSize that is > 65536
1105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001106 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001107 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1108 m_errorMonitor->VerifyFound();
1109
Tony Barbour552f6c02016-12-21 14:34:07 -07001110 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111}
1112
1113TEST_F(VkLayerTest, FillBufferAlignment) {
1114 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1115
1116 ASSERT_NO_FATAL_FAILURE(InitState());
1117
1118 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1119 vk_testing::Buffer buffer;
1120 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1121
Tony Barbour552f6c02016-12-21 14:34:07 -07001122 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001123
1124 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
1129 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001131 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1132 m_errorMonitor->VerifyFound();
1133
1134 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001136 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1137 m_errorMonitor->VerifyFound();
1138
Tony Barbour552f6c02016-12-21 14:34:07 -07001139 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001140}
Dustin Graves40f35822016-06-23 11:12:53 -06001141
Cortd889ff92016-07-27 09:51:27 -07001142TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1143 VkResult err;
1144
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001145 TEST_DESCRIPTION(
1146 "Attempt to use a non-solid polygon fill mode in a "
1147 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001148
1149 ASSERT_NO_FATAL_FAILURE(InitState());
1150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1151
1152 std::vector<const char *> device_extension_names;
1153 auto features = m_device->phy().features();
1154 // Artificially disable support for non-solid fill modes
1155 features.fillModeNonSolid = false;
1156 // The sacrificial device object
1157 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1158
1159 VkRenderpassObj render_pass(&test_device);
1160
1161 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1162 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1163 pipeline_layout_ci.setLayoutCount = 0;
1164 pipeline_layout_ci.pSetLayouts = NULL;
1165
1166 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001167 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001168 ASSERT_VK_SUCCESS(err);
1169
1170 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1171 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1172 rs_ci.pNext = nullptr;
1173 rs_ci.lineWidth = 1.0f;
1174 rs_ci.rasterizerDiscardEnable = true;
1175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001176 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1177 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001178
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001179 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1181 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001182 {
1183 VkPipelineObj pipe(&test_device);
1184 pipe.AddShader(&vs);
1185 pipe.AddShader(&fs);
1186 pipe.AddColorAttachment();
1187 // Introduce failure by setting unsupported polygon mode
1188 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1189 pipe.SetRasterization(&rs_ci);
1190 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1191 }
1192 m_errorMonitor->VerifyFound();
1193
1194 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1196 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001197 {
1198 VkPipelineObj pipe(&test_device);
1199 pipe.AddShader(&vs);
1200 pipe.AddShader(&fs);
1201 pipe.AddColorAttachment();
1202 // Introduce failure by setting unsupported polygon mode
1203 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1204 pipe.SetRasterization(&rs_ci);
1205 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1206 }
1207 m_errorMonitor->VerifyFound();
1208
Cortd889ff92016-07-27 09:51:27 -07001209 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1210}
1211
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001212#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001213TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001214{
1215 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001216 VkFenceCreateInfo fenceInfo = {};
1217 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1218 fenceInfo.pNext = NULL;
1219 fenceInfo.flags = 0;
1220
Mike Weiblencce7ec72016-10-17 19:33:05 -06001221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001222
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001223 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001224
1225 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1226 vk_testing::Buffer buffer;
1227 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228
Tony Barbourfe3351b2015-07-28 10:17:20 -06001229 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001230 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001231 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232
1233 testFence.init(*m_device, fenceInfo);
1234
1235 // Bypass framework since it does the waits automatically
1236 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001237 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001238 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1239 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001240 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001241 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001242 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001243 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001244 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001245 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001246 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001247
1248 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001249 ASSERT_VK_SUCCESS( err );
1250
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001253
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001254 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001255}
1256
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001257TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001258{
1259 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001260 VkFenceCreateInfo fenceInfo = {};
1261 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1262 fenceInfo.pNext = NULL;
1263 fenceInfo.flags = 0;
1264
Mike Weiblencce7ec72016-10-17 19:33:05 -06001265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001266
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001267 ASSERT_NO_FATAL_FAILURE(InitState());
1268 ASSERT_NO_FATAL_FAILURE(InitViewport());
1269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1270
Tony Barbourfe3351b2015-07-28 10:17:20 -06001271 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001272 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001273 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001274
1275 testFence.init(*m_device, fenceInfo);
1276
1277 // Bypass framework since it does the waits automatically
1278 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001279 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1281 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001282 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001283 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001284 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001285 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001286 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001287 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001288 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001289
1290 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001291 ASSERT_VK_SUCCESS( err );
1292
Jon Ashburnf19916e2016-01-11 13:12:43 -07001293 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001294 VkCommandBufferBeginInfo info = {};
1295 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1296 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001297 info.renderPass = VK_NULL_HANDLE;
1298 info.subpass = 0;
1299 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001300 info.occlusionQueryEnable = VK_FALSE;
1301 info.queryFlags = 0;
1302 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001303
1304 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001305 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001306
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001307 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001308}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001309#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001310
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001311TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1312 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1313
1314 ASSERT_NO_FATAL_FAILURE(InitState());
1315
1316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1317 VkBuffer buffer;
1318 VkBufferCreateInfo buf_info = {};
1319 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1320 buf_info.pNext = NULL;
1321 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1322 buf_info.size = 2048;
1323 buf_info.queueFamilyIndexCount = 0;
1324 buf_info.pQueueFamilyIndices = NULL;
1325 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1326 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1327 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1328 m_errorMonitor->VerifyFound();
1329
1330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1331 VkImage image;
1332 VkImageCreateInfo image_create_info = {};
1333 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1334 image_create_info.pNext = NULL;
1335 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1336 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1337 image_create_info.extent.width = 512;
1338 image_create_info.extent.height = 64;
1339 image_create_info.extent.depth = 1;
1340 image_create_info.mipLevels = 1;
1341 image_create_info.arrayLayers = 1;
1342 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1343 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1344 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1346 image_create_info.queueFamilyIndexCount = 0;
1347 image_create_info.pQueueFamilyIndices = NULL;
1348 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1349 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1350 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1351 m_errorMonitor->VerifyFound();
1352}
1353
Dave Houlton829c0d82017-01-24 15:09:17 -07001354TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1355 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1356
1357 // Determine which device feature are available
1358 VkPhysicalDeviceFeatures available_features;
1359 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1360
1361 // Mask out device features we don't want
1362 VkPhysicalDeviceFeatures desired_features = available_features;
1363 desired_features.sparseResidencyImage2D = VK_FALSE;
1364 desired_features.sparseResidencyImage3D = VK_FALSE;
1365 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1366
1367 VkImage image = VK_NULL_HANDLE;
1368 VkResult result = VK_RESULT_MAX_ENUM;
1369 VkImageCreateInfo image_create_info = {};
1370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1371 image_create_info.pNext = NULL;
1372 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1373 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1374 image_create_info.extent.width = 512;
1375 image_create_info.extent.height = 1;
1376 image_create_info.extent.depth = 1;
1377 image_create_info.mipLevels = 1;
1378 image_create_info.arrayLayers = 1;
1379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1380 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1381 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1382 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1383 image_create_info.queueFamilyIndexCount = 0;
1384 image_create_info.pQueueFamilyIndices = NULL;
1385 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1386 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1387
1388 // 1D image w/ sparse residency is an error
1389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1390 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1391 m_errorMonitor->VerifyFound();
1392 if (VK_SUCCESS == result) {
1393 vkDestroyImage(m_device->device(), image, NULL);
1394 image = VK_NULL_HANDLE;
1395 }
1396
1397 // 2D image w/ sparse residency when feature isn't available
1398 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1399 image_create_info.extent.height = 64;
1400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1401 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1402 m_errorMonitor->VerifyFound();
1403 if (VK_SUCCESS == result) {
1404 vkDestroyImage(m_device->device(), image, NULL);
1405 image = VK_NULL_HANDLE;
1406 }
1407
1408 // 3D image w/ sparse residency when feature isn't available
1409 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1410 image_create_info.extent.depth = 8;
1411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1412 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1413 m_errorMonitor->VerifyFound();
1414 if (VK_SUCCESS == result) {
1415 vkDestroyImage(m_device->device(), image, NULL);
1416 image = VK_NULL_HANDLE;
1417 }
1418}
1419
1420TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1421 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1422
1423 // Determine which device feature are available
1424 VkPhysicalDeviceFeatures available_features;
1425 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1426
1427 // These tests all require that the device support sparse residency for 2D images
1428 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1429 return;
1430 }
1431
1432 // Mask out device features we don't want
1433 VkPhysicalDeviceFeatures desired_features = available_features;
1434 desired_features.sparseResidency2Samples = VK_FALSE;
1435 desired_features.sparseResidency4Samples = VK_FALSE;
1436 desired_features.sparseResidency8Samples = VK_FALSE;
1437 desired_features.sparseResidency16Samples = VK_FALSE;
1438 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1439
1440 VkImage image = VK_NULL_HANDLE;
1441 VkResult result = VK_RESULT_MAX_ENUM;
1442 VkImageCreateInfo image_create_info = {};
1443 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1444 image_create_info.pNext = NULL;
1445 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1446 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1447 image_create_info.extent.width = 64;
1448 image_create_info.extent.height = 64;
1449 image_create_info.extent.depth = 1;
1450 image_create_info.mipLevels = 1;
1451 image_create_info.arrayLayers = 1;
1452 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1453 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1454 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1455 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1456 image_create_info.queueFamilyIndexCount = 0;
1457 image_create_info.pQueueFamilyIndices = NULL;
1458 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1459 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1460
1461 // 2D image w/ sparse residency and linear tiling is an error
1462 m_errorMonitor->SetDesiredFailureMsg(
1463 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1464 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1465 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1466 m_errorMonitor->VerifyFound();
1467 if (VK_SUCCESS == result) {
1468 vkDestroyImage(m_device->device(), image, NULL);
1469 image = VK_NULL_HANDLE;
1470 }
1471 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1472
1473 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1474 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1476 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1477 m_errorMonitor->VerifyFound();
1478 if (VK_SUCCESS == result) {
1479 vkDestroyImage(m_device->device(), image, NULL);
1480 image = VK_NULL_HANDLE;
1481 }
1482
1483 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1485 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1486 m_errorMonitor->VerifyFound();
1487 if (VK_SUCCESS == result) {
1488 vkDestroyImage(m_device->device(), image, NULL);
1489 image = VK_NULL_HANDLE;
1490 }
1491
1492 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1494 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1495 m_errorMonitor->VerifyFound();
1496 if (VK_SUCCESS == result) {
1497 vkDestroyImage(m_device->device(), image, NULL);
1498 image = VK_NULL_HANDLE;
1499 }
1500
1501 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1503 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1504 m_errorMonitor->VerifyFound();
1505 if (VK_SUCCESS == result) {
1506 vkDestroyImage(m_device->device(), image, NULL);
1507 image = VK_NULL_HANDLE;
1508 }
1509}
1510
Tobin Ehlisf11be982016-05-11 13:52:53 -06001511TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 TEST_DESCRIPTION(
1513 "Create a buffer and image, allocate memory, and bind the "
1514 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001515 VkResult err;
1516 bool pass;
1517 ASSERT_NO_FATAL_FAILURE(InitState());
1518
Tobin Ehlis077ded32016-05-12 17:39:13 -06001519 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001520 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001521 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001522 VkDeviceMemory mem; // buffer will be bound first
1523 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001524 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001525 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001526
1527 VkBufferCreateInfo buf_info = {};
1528 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1529 buf_info.pNext = NULL;
1530 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1531 buf_info.size = 256;
1532 buf_info.queueFamilyIndexCount = 0;
1533 buf_info.pQueueFamilyIndices = NULL;
1534 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1535 buf_info.flags = 0;
1536 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1537 ASSERT_VK_SUCCESS(err);
1538
Tobin Ehlis077ded32016-05-12 17:39:13 -06001539 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001540
1541 VkImageCreateInfo image_create_info = {};
1542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1543 image_create_info.pNext = NULL;
1544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1545 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1546 image_create_info.extent.width = 64;
1547 image_create_info.extent.height = 64;
1548 image_create_info.extent.depth = 1;
1549 image_create_info.mipLevels = 1;
1550 image_create_info.arrayLayers = 1;
1551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001552 // Image tiling must be optimal to trigger error when aliasing linear buffer
1553 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001554 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1555 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1556 image_create_info.queueFamilyIndexCount = 0;
1557 image_create_info.pQueueFamilyIndices = NULL;
1558 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1559 image_create_info.flags = 0;
1560
Tobin Ehlisf11be982016-05-11 13:52:53 -06001561 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1562 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001563 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1564 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001565
Tobin Ehlis077ded32016-05-12 17:39:13 -06001566 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1567
1568 VkMemoryAllocateInfo alloc_info = {};
1569 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1570 alloc_info.pNext = NULL;
1571 alloc_info.memoryTypeIndex = 0;
1572 // Ensure memory is big enough for both bindings
1573 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001574 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1575 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001576 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001577 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001578 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001579 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001580 return;
1581 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001582 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1583 ASSERT_VK_SUCCESS(err);
1584 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1585 ASSERT_VK_SUCCESS(err);
1586
Rene Lindsayd14f5572016-12-16 14:57:18 -07001587 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1588
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001590 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1592 m_errorMonitor->VerifyFound();
1593
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001594 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001595 // aliasing buffer2
1596 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1597 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001598 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1599 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001603 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001604 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001605 m_errorMonitor->VerifyFound();
1606
1607 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001608 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001609 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001610 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001611 vkFreeMemory(m_device->device(), mem, NULL);
1612 vkFreeMemory(m_device->device(), mem_img, NULL);
1613}
1614
Tobin Ehlis35372522016-05-12 08:32:31 -06001615TEST_F(VkLayerTest, InvalidMemoryMapping) {
1616 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1617 VkResult err;
1618 bool pass;
1619 ASSERT_NO_FATAL_FAILURE(InitState());
1620
1621 VkBuffer buffer;
1622 VkDeviceMemory mem;
1623 VkMemoryRequirements mem_reqs;
1624
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001625 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1626
Tobin Ehlis35372522016-05-12 08:32:31 -06001627 VkBufferCreateInfo buf_info = {};
1628 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1629 buf_info.pNext = NULL;
1630 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1631 buf_info.size = 256;
1632 buf_info.queueFamilyIndexCount = 0;
1633 buf_info.pQueueFamilyIndices = NULL;
1634 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1635 buf_info.flags = 0;
1636 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1637 ASSERT_VK_SUCCESS(err);
1638
1639 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1640 VkMemoryAllocateInfo alloc_info = {};
1641 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1642 alloc_info.pNext = NULL;
1643 alloc_info.memoryTypeIndex = 0;
1644
1645 // Ensure memory is big enough for both bindings
1646 static const VkDeviceSize allocation_size = 0x10000;
1647 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 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 -06001649 if (!pass) {
1650 vkDestroyBuffer(m_device->device(), buffer, NULL);
1651 return;
1652 }
1653 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1654 ASSERT_VK_SUCCESS(err);
1655
1656 uint8_t *pData;
1657 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 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 -06001659 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1660 m_errorMonitor->VerifyFound();
1661 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001663 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1665 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1666 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001667 m_errorMonitor->VerifyFound();
1668
1669 // Unmap the memory to avoid re-map error
1670 vkUnmapMemory(m_device->device(), mem);
1671 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1673 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1674 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 m_errorMonitor->VerifyFound();
1676 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1678 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001679 m_errorMonitor->VerifyFound();
1680 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001682 vkUnmapMemory(m_device->device(), mem);
1683 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001684
Tobin Ehlis35372522016-05-12 08:32:31 -06001685 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001686 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001687 ASSERT_VK_SUCCESS(err);
1688 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001689 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001690 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001695
Tobin Ehlis35372522016-05-12 08:32:31 -06001696 // Now flush range that oversteps mapped range
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001701 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1707 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001708 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001709 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001710 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001711 mmr.size = VK_WHOLE_SIZE;
1712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001713 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1714 m_errorMonitor->VerifyFound();
1715
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001716#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001717 // Some platforms have an atomsize of 1 which makes the test meaningless
1718 if (atom_size > 3) {
1719 // Now with an offset 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 = 3; // Not a multiple of atom_size
1724 mmr.size = VK_WHOLE_SIZE;
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728
1729 // Now with a size NOT a multiple of the device limit
1730 vkUnmapMemory(m_device->device(), mem);
1731 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1732 ASSERT_VK_SUCCESS(err);
1733 mmr.offset = atom_size;
1734 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1736 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1737 m_errorMonitor->VerifyFound();
1738 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001739#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001740 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1741 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001742 if (!pass) {
1743 vkFreeMemory(m_device->device(), mem, NULL);
1744 vkDestroyBuffer(m_device->device(), buffer, NULL);
1745 return;
1746 }
1747 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1748 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1749
1750 vkDestroyBuffer(m_device->device(), buffer, NULL);
1751 vkFreeMemory(m_device->device(), mem, NULL);
1752}
1753
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001754#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001755TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1756 VkResult err;
1757 bool pass;
1758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1760 // following declaration (which is temporarily being moved below):
1761 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001762 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001763 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001764 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001765 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001766 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001767 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001768
1769 ASSERT_NO_FATAL_FAILURE(InitState());
1770
Ian Elliott3f06ce52016-04-29 14:46:21 -06001771#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1772#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1773 // Use the functions from the VK_KHR_android_surface extension without
1774 // enabling that extension:
1775
1776 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001777 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1779 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001780 pass = (err != VK_SUCCESS);
1781 ASSERT_TRUE(pass);
1782 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001783#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001784
Ian Elliott3f06ce52016-04-29 14:46:21 -06001785#if defined(VK_USE_PLATFORM_MIR_KHR)
1786 // Use the functions from the VK_KHR_mir_surface extension without enabling
1787 // that extension:
1788
1789 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001790 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001792 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1793 pass = (err != VK_SUCCESS);
1794 ASSERT_TRUE(pass);
1795 m_errorMonitor->VerifyFound();
1796
1797 // Tell whether an mir_connection supports presentation:
1798 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1800 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001801 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001802#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001803
Ian Elliott3f06ce52016-04-29 14:46:21 -06001804#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1805 // Use the functions from the VK_KHR_wayland_surface extension without
1806 // enabling that extension:
1807
1808 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001809 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1811 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001812 pass = (err != VK_SUCCESS);
1813 ASSERT_TRUE(pass);
1814 m_errorMonitor->VerifyFound();
1815
1816 // Tell whether an wayland_display supports presentation:
1817 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1819 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001820 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001821#endif // VK_USE_PLATFORM_WAYLAND_KHR
1822#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001823
Ian Elliott3f06ce52016-04-29 14:46:21 -06001824#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001825 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1826 // TO NON-LINUX PLATFORMS:
1827 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828 // Use the functions from the VK_KHR_win32_surface extension without
1829 // enabling that extension:
1830
1831 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001832 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1834 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001835 pass = (err != VK_SUCCESS);
1836 ASSERT_TRUE(pass);
1837 m_errorMonitor->VerifyFound();
1838
1839 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001841 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001842 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001843// Set this (for now, until all platforms are supported and tested):
1844#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001845#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001846#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1848 // TO NON-LINUX PLATFORMS:
1849 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001850#endif
1851#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001852 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1853 // that extension:
1854
1855 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001856 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1859 pass = (err != VK_SUCCESS);
1860 ASSERT_TRUE(pass);
1861 m_errorMonitor->VerifyFound();
1862
1863 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001864 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001865 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1867 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001868 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001869// Set this (for now, until all platforms are supported and tested):
1870#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001871#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001872
Ian Elliott12630812016-04-29 14:35:43 -06001873#if defined(VK_USE_PLATFORM_XLIB_KHR)
1874 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1875 // that extension:
1876
1877 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001878 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001880 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1881 pass = (err != VK_SUCCESS);
1882 ASSERT_TRUE(pass);
1883 m_errorMonitor->VerifyFound();
1884
1885 // Tell whether an Xlib VisualID supports presentation:
1886 Display *dpy = NULL;
1887 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001889 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1890 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001891// Set this (for now, until all platforms are supported and tested):
1892#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001893#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001895// Use the functions from the VK_KHR_surface extension without enabling
1896// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001897
Ian Elliott489eec02016-05-05 14:12:44 -06001898#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001899 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001901 vkDestroySurfaceKHR(instance(), surface, NULL);
1902 m_errorMonitor->VerifyFound();
1903
1904 // Check if surface supports presentation:
1905 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001907 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1908 pass = (err != VK_SUCCESS);
1909 ASSERT_TRUE(pass);
1910 m_errorMonitor->VerifyFound();
1911
1912 // Check surface capabilities:
1913 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1915 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001916 pass = (err != VK_SUCCESS);
1917 ASSERT_TRUE(pass);
1918 m_errorMonitor->VerifyFound();
1919
1920 // Check surface formats:
1921 uint32_t format_count = 0;
1922 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1924 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001925 pass = (err != VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927 m_errorMonitor->VerifyFound();
1928
1929 // Check surface present modes:
1930 uint32_t present_mode_count = 0;
1931 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1933 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 pass = (err != VK_SUCCESS);
1935 ASSERT_TRUE(pass);
1936 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001937#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001938
Ian Elliott1c32c772016-04-28 14:47:13 -06001939 // Use the functions from the VK_KHR_swapchain extension without enabling
1940 // that extension:
1941
1942 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1945 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001946 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001947 pass = (err != VK_SUCCESS);
1948 ASSERT_TRUE(pass);
1949 m_errorMonitor->VerifyFound();
1950
1951 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1953 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001954 pass = (err != VK_SUCCESS);
1955 ASSERT_TRUE(pass);
1956 m_errorMonitor->VerifyFound();
1957
Chris Forbeseb7d5502016-09-13 18:19:21 +12001958 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1959 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1960 VkFence fence;
1961 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1962
Ian Elliott1c32c772016-04-28 14:47:13 -06001963 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001965 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001966 pass = (err != VK_SUCCESS);
1967 ASSERT_TRUE(pass);
1968 m_errorMonitor->VerifyFound();
1969
Chris Forbeseb7d5502016-09-13 18:19:21 +12001970 vkDestroyFence(m_device->device(), fence, nullptr);
1971
Ian Elliott1c32c772016-04-28 14:47:13 -06001972 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001973 //
1974 // NOTE: Currently can't test this because a real swapchain is needed (as
1975 // opposed to the fake one we created) in order for the layer to lookup the
1976 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001977
1978 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001980 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1981 m_errorMonitor->VerifyFound();
1982}
Chris Forbes09368e42016-10-13 11:59:22 +13001983#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001984
Karl Schultz6addd812016-02-02 17:17:23 -07001985TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1986 VkResult err;
1987 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1990 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001991
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001993
1994 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001995 VkImage image;
1996 VkDeviceMemory mem;
1997 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001998
Karl Schultz6addd812016-02-02 17:17:23 -07001999 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2000 const int32_t tex_width = 32;
2001 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002002
Tony Barboureb254902015-07-15 12:50:33 -06002003 VkImageCreateInfo image_create_info = {};
2004 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002005 image_create_info.pNext = NULL;
2006 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2007 image_create_info.format = tex_format;
2008 image_create_info.extent.width = tex_width;
2009 image_create_info.extent.height = tex_height;
2010 image_create_info.extent.depth = 1;
2011 image_create_info.mipLevels = 1;
2012 image_create_info.arrayLayers = 1;
2013 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2014 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2015 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2016 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002017 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002018
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002019 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002020 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002021 mem_alloc.pNext = NULL;
2022 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002023
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002025 ASSERT_VK_SUCCESS(err);
2026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028
Mark Lobodzinski23065352015-05-29 09:32:35 -05002029 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002031 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 -07002032 if (!pass) { // If we can't find any unmappable memory this test doesn't
2033 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002034 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002035 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002036 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002037
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002038 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002039 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002040 ASSERT_VK_SUCCESS(err);
2041
2042 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002043 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044 ASSERT_VK_SUCCESS(err);
2045
2046 // Map memory as if to initialize the image
2047 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002049
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002050 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002051
Chia-I Wuf7458c52015-10-26 21:10:41 +08002052 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002053 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002054}
2055
Karl Schultz6addd812016-02-02 17:17:23 -07002056TEST_F(VkLayerTest, RebindMemory) {
2057 VkResult err;
2058 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002061
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002062 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
2064 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002065 VkImage image;
2066 VkDeviceMemory mem1;
2067 VkDeviceMemory mem2;
2068 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002069
Karl Schultz6addd812016-02-02 17:17:23 -07002070 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2071 const int32_t tex_width = 32;
2072 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002073
Tony Barboureb254902015-07-15 12:50:33 -06002074 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002075 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2076 image_create_info.pNext = NULL;
2077 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2078 image_create_info.format = tex_format;
2079 image_create_info.extent.width = tex_width;
2080 image_create_info.extent.height = tex_height;
2081 image_create_info.extent.depth = 1;
2082 image_create_info.mipLevels = 1;
2083 image_create_info.arrayLayers = 1;
2084 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2085 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2086 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2087 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002088
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002089 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002090 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2091 mem_alloc.pNext = NULL;
2092 mem_alloc.allocationSize = 0;
2093 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002094
Karl Schultz6addd812016-02-02 17:17:23 -07002095 // Introduce failure, do NOT set memProps to
2096 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002097 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002098 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
2100
Karl Schultz6addd812016-02-02 17:17:23 -07002101 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
2103 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002104 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002105 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002106
2107 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002108 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002109 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002110 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002111 ASSERT_VK_SUCCESS(err);
2112
2113 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002114 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002115 ASSERT_VK_SUCCESS(err);
2116
Karl Schultz6addd812016-02-02 17:17:23 -07002117 // Introduce validation failure, try to bind a different memory object to
2118 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002119 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002120
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002121 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002122
Chia-I Wuf7458c52015-10-26 21:10:41 +08002123 vkDestroyImage(m_device->device(), image, NULL);
2124 vkFreeMemory(m_device->device(), mem1, NULL);
2125 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002126}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002127
Karl Schultz6addd812016-02-02 17:17:23 -07002128TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002129 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002130
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2132 "submitted in SIGNALED state. Fences "
2133 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002134
2135 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002136 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2137 fenceInfo.pNext = NULL;
2138 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002139
Tony Barbour300a6082015-04-07 13:44:53 -06002140 ASSERT_NO_FATAL_FAILURE(InitState());
2141 ASSERT_NO_FATAL_FAILURE(InitViewport());
2142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2143
Tony Barbour552f6c02016-12-21 14:34:07 -07002144 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002145 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002146 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002147
2148 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002149
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002150 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2152 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002153 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002154 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002155 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002156 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002157 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002158 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002159 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002160
2161 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002162 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002164 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002165}
Chris Forbes4e44c912016-06-16 10:20:00 +12002166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002167TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002168 TEST_DESCRIPTION(
2169 "Specify wrong usage for image then create conflicting view of image "
2170 "Initialize buffer with wrong usage then perform copy expecting errors "
2171 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002173
2174 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002175
Tony Barbourf887b162017-03-09 10:06:46 -07002176 auto format = find_depth_stencil_format(m_device);
2177 if (!format) {
2178 printf(" No Depth + Stencil format found. Skipped.\n");
2179 return;
2180 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002181
Tony Barbourf92621a2016-05-02 14:28:12 -06002182 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002183 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002184 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002185 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002186
Tony Barbourf92621a2016-05-02 14:28:12 -06002187 VkImageView dsv;
2188 VkImageViewCreateInfo dsvci = {};
2189 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2190 dsvci.image = image.handle();
2191 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002192 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002193 dsvci.subresourceRange.layerCount = 1;
2194 dsvci.subresourceRange.baseMipLevel = 0;
2195 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002196 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002197
Tony Barbourf92621a2016-05-02 14:28:12 -06002198 // Create a view with depth / stencil aspect for image with different usage
2199 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002200
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002201 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002202
2203 // Initialize buffer with TRANSFER_DST usage
2204 vk_testing::Buffer buffer;
2205 VkMemoryPropertyFlags reqs = 0;
2206 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2207 VkBufferImageCopy region = {};
2208 region.bufferRowLength = 128;
2209 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002210 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 region.imageSubresource.layerCount = 1;
2212 region.imageExtent.height = 16;
2213 region.imageExtent.width = 16;
2214 region.imageExtent.depth = 1;
2215
Mark Lobodzinski80871462017-02-16 10:37:27 -07002216 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002217 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002218
Chris Forbesda581202016-10-06 18:25:26 +13002219 // two separate errors from this call:
2220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2224 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002225 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002226}
Tony Barbour75d79f02016-08-30 09:39:07 -06002227
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228TEST_F(VkLayerTest, LeakAnObject) {
2229 VkResult err;
2230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002232
2233 // Note that we have to create a new device since destroying the
2234 // framework's device causes Teardown() to fail and just calling Teardown
2235 // will destroy the errorMonitor.
2236
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002238
2239 ASSERT_NO_FATAL_FAILURE(InitState());
2240
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002241 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<VkDeviceQueueCreateInfo> queue_info;
2243 queue_info.reserve(queue_props.size());
2244 std::vector<std::vector<float>> queue_priorities;
2245 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2246 VkDeviceQueueCreateInfo qi = {};
2247 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2248 qi.pNext = NULL;
2249 qi.queueFamilyIndex = i;
2250 qi.queueCount = queue_props[i].queueCount;
2251 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2252 qi.pQueuePriorities = queue_priorities[i].data();
2253 queue_info.push_back(qi);
2254 }
2255
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002256 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002257
2258 // The sacrificial device object
2259 VkDevice testDevice;
2260 VkDeviceCreateInfo device_create_info = {};
2261 auto features = m_device->phy().features();
2262 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2263 device_create_info.pNext = NULL;
2264 device_create_info.queueCreateInfoCount = queue_info.size();
2265 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002266 device_create_info.enabledLayerCount = 0;
2267 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002268 device_create_info.pEnabledFeatures = &features;
2269 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2270 ASSERT_VK_SUCCESS(err);
2271
2272 VkFence fence;
2273 VkFenceCreateInfo fence_create_info = {};
2274 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2275 fence_create_info.pNext = NULL;
2276 fence_create_info.flags = 0;
2277 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2278 ASSERT_VK_SUCCESS(err);
2279
2280 // Induce failure by not calling vkDestroyFence
2281 vkDestroyDevice(testDevice, NULL);
2282 m_errorMonitor->VerifyFound();
2283}
2284
2285TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002286 TEST_DESCRIPTION(
2287 "Allocate command buffers from one command pool and "
2288 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002291
Cody Northropc31a84f2016-08-22 10:41:47 -06002292 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002293 VkCommandPool command_pool_one;
2294 VkCommandPool command_pool_two;
2295
2296 VkCommandPoolCreateInfo pool_create_info{};
2297 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2298 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2299 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002301 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002303 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002304
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002305 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002306 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002307 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002308 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002309 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002310 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002311 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002312
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002313 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002314
2315 m_errorMonitor->VerifyFound();
2316
2317 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2318 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2319}
2320
2321TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2322 VkResult err;
2323
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002324 TEST_DESCRIPTION(
2325 "Allocate descriptor sets from one DS pool and "
2326 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002329
2330 ASSERT_NO_FATAL_FAILURE(InitState());
2331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2332
2333 VkDescriptorPoolSize ds_type_count = {};
2334 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2335 ds_type_count.descriptorCount = 1;
2336
2337 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2338 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2339 ds_pool_ci.pNext = NULL;
2340 ds_pool_ci.flags = 0;
2341 ds_pool_ci.maxSets = 1;
2342 ds_pool_ci.poolSizeCount = 1;
2343 ds_pool_ci.pPoolSizes = &ds_type_count;
2344
2345 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002346 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002347 ASSERT_VK_SUCCESS(err);
2348
2349 // Create a second descriptor pool
2350 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002351 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002352 ASSERT_VK_SUCCESS(err);
2353
2354 VkDescriptorSetLayoutBinding dsl_binding = {};
2355 dsl_binding.binding = 0;
2356 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2357 dsl_binding.descriptorCount = 1;
2358 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2359 dsl_binding.pImmutableSamplers = NULL;
2360
2361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2363 ds_layout_ci.pNext = NULL;
2364 ds_layout_ci.bindingCount = 1;
2365 ds_layout_ci.pBindings = &dsl_binding;
2366
2367 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002368 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002369 ASSERT_VK_SUCCESS(err);
2370
2371 VkDescriptorSet descriptorSet;
2372 VkDescriptorSetAllocateInfo alloc_info = {};
2373 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2374 alloc_info.descriptorSetCount = 1;
2375 alloc_info.descriptorPool = ds_pool_one;
2376 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002377 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002378 ASSERT_VK_SUCCESS(err);
2379
2380 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2381
2382 m_errorMonitor->VerifyFound();
2383
2384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2385 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2386 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2387}
2388
2389TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002392 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002393
2394 ASSERT_NO_FATAL_FAILURE(InitState());
2395
2396 // Pass bogus handle into GetImageMemoryRequirements
2397 VkMemoryRequirements mem_reqs;
2398 uint64_t fakeImageHandle = 0xCADECADE;
2399 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2400
2401 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2402
2403 m_errorMonitor->VerifyFound();
2404}
2405
Mike Schuchardt17838902017-02-21 09:48:06 -07002406TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2407 TEST_DESCRIPTION(
2408 "Try to destroy a render pass object using a device other than the one it was created on. "
2409 "This should generate a distinct error from the invalid handle error.");
2410 // Create first device and renderpass
2411 ASSERT_NO_FATAL_FAILURE(InitState());
2412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2413
2414 // Create second device
2415 float priorities[] = {1.0f};
2416 VkDeviceQueueCreateInfo queue_info{};
2417 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2418 queue_info.pNext = NULL;
2419 queue_info.flags = 0;
2420 queue_info.queueFamilyIndex = 0;
2421 queue_info.queueCount = 1;
2422 queue_info.pQueuePriorities = &priorities[0];
2423
2424 VkDeviceCreateInfo device_create_info = {};
2425 auto features = m_device->phy().features();
2426 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2427 device_create_info.pNext = NULL;
2428 device_create_info.queueCreateInfoCount = 1;
2429 device_create_info.pQueueCreateInfos = &queue_info;
2430 device_create_info.enabledLayerCount = 0;
2431 device_create_info.ppEnabledLayerNames = NULL;
2432 device_create_info.pEnabledFeatures = &features;
2433
2434 VkDevice second_device;
2435 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2436
2437 // Try to destroy the renderpass from the first device using the second device
2438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2439 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2440 m_errorMonitor->VerifyFound();
2441
2442 vkDestroyDevice(second_device, NULL);
2443}
2444
Karl Schultz6addd812016-02-02 17:17:23 -07002445TEST_F(VkLayerTest, PipelineNotBound) {
2446 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002447
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002448 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002449
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002451
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002452 ASSERT_NO_FATAL_FAILURE(InitState());
2453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002455 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002456 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2457 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002458
2459 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002460 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2461 ds_pool_ci.pNext = NULL;
2462 ds_pool_ci.maxSets = 1;
2463 ds_pool_ci.poolSizeCount = 1;
2464 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002465
2466 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002467 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468 ASSERT_VK_SUCCESS(err);
2469
2470 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002471 dsl_binding.binding = 0;
2472 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2473 dsl_binding.descriptorCount = 1;
2474 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2475 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002476
2477 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002478 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2479 ds_layout_ci.pNext = NULL;
2480 ds_layout_ci.bindingCount = 1;
2481 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002482
2483 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002484 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002485 ASSERT_VK_SUCCESS(err);
2486
2487 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002488 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002489 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002490 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002491 alloc_info.descriptorPool = ds_pool;
2492 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002493 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002494 ASSERT_VK_SUCCESS(err);
2495
2496 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002497 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2498 pipeline_layout_ci.pNext = NULL;
2499 pipeline_layout_ci.setLayoutCount = 1;
2500 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501
2502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002504 ASSERT_VK_SUCCESS(err);
2505
Mark Youngad779052016-01-06 14:26:04 -07002506 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002507
Tony Barbour552f6c02016-12-21 14:34:07 -07002508 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002509 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002511 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002512
Chia-I Wuf7458c52015-10-26 21:10:41 +08002513 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2514 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2515 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002516}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002517
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002518TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2519 VkResult err;
2520
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002521 TEST_DESCRIPTION(
2522 "Test validation check for an invalid memory type index "
2523 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002524
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002525 ASSERT_NO_FATAL_FAILURE(InitState());
2526
2527 // Create an image, allocate memory, set a bad typeIndex and then try to
2528 // bind it
2529 VkImage image;
2530 VkDeviceMemory mem;
2531 VkMemoryRequirements mem_reqs;
2532 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2533 const int32_t tex_width = 32;
2534 const int32_t tex_height = 32;
2535
2536 VkImageCreateInfo image_create_info = {};
2537 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2538 image_create_info.pNext = NULL;
2539 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2540 image_create_info.format = tex_format;
2541 image_create_info.extent.width = tex_width;
2542 image_create_info.extent.height = tex_height;
2543 image_create_info.extent.depth = 1;
2544 image_create_info.mipLevels = 1;
2545 image_create_info.arrayLayers = 1;
2546 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2547 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2548 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2549 image_create_info.flags = 0;
2550
2551 VkMemoryAllocateInfo mem_alloc = {};
2552 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2553 mem_alloc.pNext = NULL;
2554 mem_alloc.allocationSize = 0;
2555 mem_alloc.memoryTypeIndex = 0;
2556
2557 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2558 ASSERT_VK_SUCCESS(err);
2559
2560 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2561 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562
2563 // Introduce Failure, select invalid TypeIndex
2564 VkPhysicalDeviceMemoryProperties memory_info;
2565
2566 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2567 unsigned int i;
2568 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2569 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2570 mem_alloc.memoryTypeIndex = i;
2571 break;
2572 }
2573 }
2574 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002575 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002576 vkDestroyImage(m_device->device(), image, NULL);
2577 return;
2578 }
2579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002580 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 -06002581
2582 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2583 ASSERT_VK_SUCCESS(err);
2584
2585 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2586 (void)err;
2587
2588 m_errorMonitor->VerifyFound();
2589
2590 vkDestroyImage(m_device->device(), image, NULL);
2591 vkFreeMemory(m_device->device(), mem, NULL);
2592}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002593
Karl Schultz6addd812016-02-02 17:17:23 -07002594TEST_F(VkLayerTest, BindInvalidMemory) {
2595 VkResult err;
2596 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002597
2598 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002599
Cortf801b982017-01-17 18:10:21 -08002600 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002601 const int32_t tex_width = 256;
2602 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002603
2604 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002605 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2606 image_create_info.pNext = NULL;
2607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2608 image_create_info.format = tex_format;
2609 image_create_info.extent.width = tex_width;
2610 image_create_info.extent.height = tex_height;
2611 image_create_info.extent.depth = 1;
2612 image_create_info.mipLevels = 1;
2613 image_create_info.arrayLayers = 1;
2614 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002615 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002616 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2617 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002618
Cortf801b982017-01-17 18:10:21 -08002619 VkBufferCreateInfo buffer_create_info = {};
2620 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2621 buffer_create_info.pNext = NULL;
2622 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002623 buffer_create_info.size = 4 * 1024 * 1024;
2624 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002625 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002626
Cortf801b982017-01-17 18:10:21 -08002627 // Create an image/buffer, allocate memory, free it, and then try to bind it
2628 {
2629 VkImage image = VK_NULL_HANDLE;
2630 VkBuffer buffer = VK_NULL_HANDLE;
2631 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2632 ASSERT_VK_SUCCESS(err);
2633 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2634 ASSERT_VK_SUCCESS(err);
2635 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2636 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2637 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002638
Cortf801b982017-01-17 18:10:21 -08002639 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2640 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2641 image_mem_alloc.allocationSize = image_mem_reqs.size;
2642 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2643 ASSERT_TRUE(pass);
2644 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2645 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2646 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2647 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2650 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2651 ASSERT_VK_SUCCESS(err);
2652 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2653 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Cortf801b982017-01-17 18:10:21 -08002655 vkFreeMemory(device(), image_mem, NULL);
2656 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002657
Cortf801b982017-01-17 18:10:21 -08002658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2659 err = vkBindImageMemory(device(), image, image_mem, 0);
2660 (void)err; // This may very well return an error.
2661 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002662
Cortf801b982017-01-17 18:10:21 -08002663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2664 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2665 (void)err; // This may very well return an error.
2666 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002667
Cortf801b982017-01-17 18:10:21 -08002668 vkDestroyImage(m_device->device(), image, NULL);
2669 vkDestroyBuffer(m_device->device(), buffer, NULL);
2670 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002671
2672 // Try to bind memory to an object that already has a memory binding
2673 {
2674 VkImage image = VK_NULL_HANDLE;
2675 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2676 ASSERT_VK_SUCCESS(err);
2677 VkBuffer buffer = VK_NULL_HANDLE;
2678 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2679 ASSERT_VK_SUCCESS(err);
2680 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2681 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2682 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2683 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2684 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2685 image_alloc_info.allocationSize = image_mem_reqs.size;
2686 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2687 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2688 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2689 ASSERT_TRUE(pass);
2690 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2691 ASSERT_TRUE(pass);
2692 VkDeviceMemory image_mem, buffer_mem;
2693 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2694 ASSERT_VK_SUCCESS(err);
2695 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2696 ASSERT_VK_SUCCESS(err);
2697
2698 err = vkBindImageMemory(device(), image, image_mem, 0);
2699 ASSERT_VK_SUCCESS(err);
2700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2701 err = vkBindImageMemory(device(), image, image_mem, 0);
2702 (void)err; // This may very well return an error.
2703 m_errorMonitor->VerifyFound();
2704
2705 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2706 ASSERT_VK_SUCCESS(err);
2707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2708 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2709 (void)err; // This may very well return an error.
2710 m_errorMonitor->VerifyFound();
2711
2712 vkFreeMemory(device(), image_mem, NULL);
2713 vkFreeMemory(device(), buffer_mem, NULL);
2714 vkDestroyImage(device(), image, NULL);
2715 vkDestroyBuffer(device(), buffer, NULL);
2716 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002717
Cort Strattonde748202017-02-17 12:50:01 -08002718 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002719 {
2720 VkImage image = VK_NULL_HANDLE;
2721 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2722 ASSERT_VK_SUCCESS(err);
2723 VkBuffer buffer = VK_NULL_HANDLE;
2724 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2725 ASSERT_VK_SUCCESS(err);
2726 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2727 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2728 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2729 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2730 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002731 // Leave some extra space for alignment wiggle room
2732 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002733 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002734 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002735 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2736 ASSERT_TRUE(pass);
2737 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2738 ASSERT_TRUE(pass);
2739 VkDeviceMemory image_mem, buffer_mem;
2740 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2741 ASSERT_VK_SUCCESS(err);
2742 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2743 ASSERT_VK_SUCCESS(err);
2744
Cort Strattonde748202017-02-17 12:50:01 -08002745 // Test unaligned memory offset
2746 {
2747 if (image_mem_reqs.alignment > 1) {
2748 VkDeviceSize image_offset = 1;
2749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2750 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2751 (void)err; // This may very well return an error.
2752 m_errorMonitor->VerifyFound();
2753 }
Cort6c7dff72017-01-27 18:34:50 -08002754
Cort Strattonde748202017-02-17 12:50:01 -08002755 if (buffer_mem_reqs.alignment > 1) {
2756 VkDeviceSize buffer_offset = 1;
2757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2758 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2759 (void)err; // This may very well return an error.
2760 m_errorMonitor->VerifyFound();
2761 }
2762 }
2763
2764 // Test memory offsets outside the memory allocation
2765 {
2766 VkDeviceSize image_offset =
2767 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2769 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2770 (void)err; // This may very well return an error.
2771 m_errorMonitor->VerifyFound();
2772
2773 VkDeviceSize buffer_offset =
2774 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2776 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2777 (void)err; // This may very well return an error.
2778 m_errorMonitor->VerifyFound();
2779 }
2780
2781 // Test memory offsets within the memory allocation, but which leave too little memory for
2782 // the resource.
2783 {
2784 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2785 if (image_offset > 0) {
2786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2787 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2788 (void)err; // This may very well return an error.
2789 m_errorMonitor->VerifyFound();
2790 }
2791
2792 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2793 if (buffer_offset > 0) {
2794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2795 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2796 (void)err; // This may very well return an error.
2797 m_errorMonitor->VerifyFound();
2798 }
2799 }
Cort6c7dff72017-01-27 18:34:50 -08002800
2801 vkFreeMemory(device(), image_mem, NULL);
2802 vkFreeMemory(device(), buffer_mem, NULL);
2803 vkDestroyImage(device(), image, NULL);
2804 vkDestroyBuffer(device(), buffer, NULL);
2805 }
2806
Cort Stratton4c38bb52017-01-28 13:33:10 -08002807 // Try to bind memory to an object with an invalid memory type
2808 {
2809 VkImage image = VK_NULL_HANDLE;
2810 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2811 ASSERT_VK_SUCCESS(err);
2812 VkBuffer buffer = VK_NULL_HANDLE;
2813 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2814 ASSERT_VK_SUCCESS(err);
2815 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2816 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2817 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2818 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2819 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2820 image_alloc_info.allocationSize = image_mem_reqs.size;
2821 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2822 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002823 // Create a mask of available memory types *not* supported by these resources,
2824 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002825 VkPhysicalDeviceMemoryProperties memory_properties = {};
2826 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002827 VkDeviceMemory image_mem, buffer_mem;
2828
Cort Stratton4c38bb52017-01-28 13:33:10 -08002829 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002830 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002831 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2832 ASSERT_TRUE(pass);
2833 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2834 ASSERT_VK_SUCCESS(err);
2835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2836 err = vkBindImageMemory(device(), image, image_mem, 0);
2837 (void)err; // This may very well return an error.
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002840 }
2841
Cort Stratton4c38bb52017-01-28 13:33:10 -08002842 uint32_t buffer_unsupported_mem_type_bits =
2843 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002844 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002845 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2846 ASSERT_TRUE(pass);
2847 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2848 ASSERT_VK_SUCCESS(err);
2849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2850 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2851 (void)err; // This may very well return an error.
2852 m_errorMonitor->VerifyFound();
2853 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002854 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002855
Cort Stratton4c38bb52017-01-28 13:33:10 -08002856 vkDestroyImage(device(), image, NULL);
2857 vkDestroyBuffer(device(), buffer, NULL);
2858 }
2859
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002860 // Try to bind memory to an image created with sparse memory flags
2861 {
2862 VkImageCreateInfo sparse_image_create_info = image_create_info;
2863 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2864 VkImageFormatProperties image_format_properties = {};
2865 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2866 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2867 sparse_image_create_info.usage, sparse_image_create_info.flags,
2868 &image_format_properties);
2869 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2870 // most likely means sparse formats aren't supported here; skip this test.
2871 } else {
2872 ASSERT_VK_SUCCESS(err);
2873 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002874 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002875 return;
2876 } else {
2877 VkImage sparse_image = VK_NULL_HANDLE;
2878 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2879 ASSERT_VK_SUCCESS(err);
2880 VkMemoryRequirements sparse_mem_reqs = {};
2881 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2882 if (sparse_mem_reqs.memoryTypeBits != 0) {
2883 VkMemoryAllocateInfo sparse_mem_alloc = {};
2884 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2885 sparse_mem_alloc.pNext = NULL;
2886 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2887 sparse_mem_alloc.memoryTypeIndex = 0;
2888 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2889 ASSERT_TRUE(pass);
2890 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2891 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2892 ASSERT_VK_SUCCESS(err);
2893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2894 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2895 // This may very well return an error.
2896 (void)err;
2897 m_errorMonitor->VerifyFound();
2898 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2899 }
2900 vkDestroyImage(m_device->device(), sparse_image, NULL);
2901 }
2902 }
2903 }
2904
2905 // Try to bind memory to a buffer created with sparse memory flags
2906 {
2907 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2908 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2909 if (!m_device->phy().features().sparseResidencyBuffer) {
2910 // most likely means sparse formats aren't supported here; skip this test.
2911 } else {
2912 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2913 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2914 ASSERT_VK_SUCCESS(err);
2915 VkMemoryRequirements sparse_mem_reqs = {};
2916 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2917 if (sparse_mem_reqs.memoryTypeBits != 0) {
2918 VkMemoryAllocateInfo sparse_mem_alloc = {};
2919 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2920 sparse_mem_alloc.pNext = NULL;
2921 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2922 sparse_mem_alloc.memoryTypeIndex = 0;
2923 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2924 ASSERT_TRUE(pass);
2925 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2926 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2927 ASSERT_VK_SUCCESS(err);
2928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2929 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2930 // This may very well return an error.
2931 (void)err;
2932 m_errorMonitor->VerifyFound();
2933 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2934 }
2935 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2936 }
2937 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002938}
2939
Karl Schultz6addd812016-02-02 17:17:23 -07002940TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2941 VkResult err;
2942 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002943
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002945
Tobin Ehlisec598302015-09-15 15:02:17 -06002946 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002947
Karl Schultz6addd812016-02-02 17:17:23 -07002948 // Create an image object, allocate memory, destroy the object and then try
2949 // to bind it
2950 VkImage image;
2951 VkDeviceMemory mem;
2952 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002953
Karl Schultz6addd812016-02-02 17:17:23 -07002954 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2955 const int32_t tex_width = 32;
2956 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002957
2958 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002959 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2960 image_create_info.pNext = NULL;
2961 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2962 image_create_info.format = tex_format;
2963 image_create_info.extent.width = tex_width;
2964 image_create_info.extent.height = tex_height;
2965 image_create_info.extent.depth = 1;
2966 image_create_info.mipLevels = 1;
2967 image_create_info.arrayLayers = 1;
2968 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2969 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2970 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2971 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002972
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002973 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002974 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2975 mem_alloc.pNext = NULL;
2976 mem_alloc.allocationSize = 0;
2977 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002978
Chia-I Wuf7458c52015-10-26 21:10:41 +08002979 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002980 ASSERT_VK_SUCCESS(err);
2981
Karl Schultz6addd812016-02-02 17:17:23 -07002982 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002983
2984 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002985 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002986 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002987
2988 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002989 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002990 ASSERT_VK_SUCCESS(err);
2991
2992 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002993 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002994 ASSERT_VK_SUCCESS(err);
2995
2996 // Now Try to bind memory to this destroyed object
2997 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2998 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002999 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003000
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003001 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003002
Chia-I Wuf7458c52015-10-26 21:10:41 +08003003 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003004}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003005
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003006TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3007 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3008
3009 ASSERT_NO_FATAL_FAILURE(InitState());
3010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3011
3012 VkVertexInputBindingDescription input_binding;
3013 memset(&input_binding, 0, sizeof(input_binding));
3014
3015 VkVertexInputAttributeDescription input_attribs;
3016 memset(&input_attribs, 0, sizeof(input_attribs));
3017
3018 // Pick a really bad format for this purpose and make sure it should fail
3019 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3020 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3021 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003022 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003023 return;
3024 }
3025
3026 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003027 char const *vsSource =
3028 "#version 450\n"
3029 "\n"
3030 "out gl_PerVertex {\n"
3031 " vec4 gl_Position;\n"
3032 "};\n"
3033 "void main(){\n"
3034 " gl_Position = vec4(1);\n"
3035 "}\n";
3036 char const *fsSource =
3037 "#version 450\n"
3038 "\n"
3039 "layout(location=0) out vec4 color;\n"
3040 "void main(){\n"
3041 " color = vec4(1);\n"
3042 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003043
3044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3045 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3046 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3047
3048 VkPipelineObj pipe(m_device);
3049 pipe.AddColorAttachment();
3050 pipe.AddShader(&vs);
3051 pipe.AddShader(&fs);
3052
3053 pipe.AddVertexInputBindings(&input_binding, 1);
3054 pipe.AddVertexInputAttribs(&input_attribs, 1);
3055
3056 VkDescriptorSetObj descriptorSet(m_device);
3057 descriptorSet.AppendDummy();
3058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3059
3060 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3061
3062 m_errorMonitor->VerifyFound();
3063}
3064
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003065TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003066 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3067 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003068
3069 VkMemoryPropertyFlags reqs = 0;
3070 VkImageCreateInfo image_create_info = {};
3071 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3072 image_create_info.pNext = NULL;
3073 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3074 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3075 image_create_info.extent.width = 256;
3076 image_create_info.extent.height = 256;
3077 image_create_info.extent.depth = 1;
3078 image_create_info.mipLevels = 1;
3079 image_create_info.arrayLayers = 1;
3080 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3081 image_create_info.flags = 0;
3082
3083 VkImageBlit blit_region = {};
3084 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3085 blit_region.srcSubresource.baseArrayLayer = 0;
3086 blit_region.srcSubresource.layerCount = 1;
3087 blit_region.srcSubresource.mipLevel = 0;
3088 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3089 blit_region.dstSubresource.baseArrayLayer = 0;
3090 blit_region.dstSubresource.layerCount = 1;
3091 blit_region.dstSubresource.mipLevel = 0;
3092
3093 // Create two images, the source with sampleCount = 2, and attempt to blit
3094 // between them
3095 {
3096 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003097 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003098 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003099 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003100 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003101 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003102 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003103 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003104 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003105 m_errorMonitor->SetDesiredFailureMsg(
3106 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3109 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003110 m_errorMonitor->VerifyFound();
3111 m_commandBuffer->EndCommandBuffer();
3112 }
3113
3114 // Create two images, the dest with sampleCount = 4, and attempt to blit
3115 // between them
3116 {
3117 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003118 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003119 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003121 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003123 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003124 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003125 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003126 m_errorMonitor->SetDesiredFailureMsg(
3127 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3128 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003129 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3130 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003131 m_errorMonitor->VerifyFound();
3132 m_commandBuffer->EndCommandBuffer();
3133 }
3134
3135 VkBufferImageCopy copy_region = {};
3136 copy_region.bufferRowLength = 128;
3137 copy_region.bufferImageHeight = 128;
3138 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3139 copy_region.imageSubresource.layerCount = 1;
3140 copy_region.imageExtent.height = 64;
3141 copy_region.imageExtent.width = 64;
3142 copy_region.imageExtent.depth = 1;
3143
3144 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3145 // buffer to image
3146 {
3147 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003148 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3149 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003150 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003151 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003152 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003153 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003154 m_errorMonitor->SetDesiredFailureMsg(
3155 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3156 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003157 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3158 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003159 m_errorMonitor->VerifyFound();
3160 m_commandBuffer->EndCommandBuffer();
3161 }
3162
3163 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3164 // image to buffer
3165 {
3166 vk_testing::Buffer dst_buffer;
3167 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3168 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003170 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003172 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003173 m_errorMonitor->SetDesiredFailureMsg(
3174 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3175 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003176 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003177 dst_buffer.handle(), 1, &copy_region);
3178 m_errorMonitor->VerifyFound();
3179 m_commandBuffer->EndCommandBuffer();
3180 }
3181}
3182
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003183TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003184 ASSERT_NO_FATAL_FAILURE(InitState());
3185
3186 VkImageObj src_image(m_device);
3187 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3188 VkImageObj dst_image(m_device);
3189 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3190 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003191 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 -06003192
3193 VkImageBlit blitRegion = {};
3194 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3195 blitRegion.srcSubresource.baseArrayLayer = 0;
3196 blitRegion.srcSubresource.layerCount = 1;
3197 blitRegion.srcSubresource.mipLevel = 0;
3198 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3199 blitRegion.dstSubresource.baseArrayLayer = 0;
3200 blitRegion.dstSubresource.layerCount = 1;
3201 blitRegion.dstSubresource.mipLevel = 0;
3202
Dave Houlton34df4cb2016-12-01 16:43:06 -07003203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3204
3205 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3206 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003207
3208 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003209 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003210 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3211 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003212
3213 m_errorMonitor->VerifyFound();
3214
Dave Houlton34df4cb2016-12-01 16:43:06 -07003215 // Test should generate 2 VU failures
3216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003218
3219 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003220 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3221 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003222
Dave Houlton34df4cb2016-12-01 16:43:06 -07003223 // TODO: Note that this only verifies that at least one of the VU enums was found
3224 // 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 -06003225 m_errorMonitor->VerifyFound();
3226
Tony Barbour552f6c02016-12-21 14:34:07 -07003227 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003228}
3229
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003230TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3231 VkResult err;
3232 bool pass;
3233
3234 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3235 ASSERT_NO_FATAL_FAILURE(InitState());
3236
3237 // If w/d/h granularity is 1, test is not meaningful
3238 // TODO: When virtual device limits are available, create a set of limits for this test that
3239 // will always have a granularity of > 1 for w, h, and d
3240 auto index = m_device->graphics_queue_node_index_;
3241 auto queue_family_properties = m_device->phy().queue_properties();
3242
3243 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3244 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3245 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3246 return;
3247 }
3248
3249 // Create two images of different types and try to copy between them
3250 VkImage srcImage;
3251 VkImage dstImage;
3252 VkDeviceMemory srcMem;
3253 VkDeviceMemory destMem;
3254 VkMemoryRequirements memReqs;
3255
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003256 VkImageCreateInfo image_create_info = {};
3257 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3258 image_create_info.pNext = NULL;
3259 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3260 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3261 image_create_info.extent.width = 32;
3262 image_create_info.extent.height = 32;
3263 image_create_info.extent.depth = 1;
3264 image_create_info.mipLevels = 1;
3265 image_create_info.arrayLayers = 4;
3266 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3267 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3268 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3269 image_create_info.flags = 0;
3270
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003271 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 ASSERT_VK_SUCCESS(err);
3273
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003274 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003275 ASSERT_VK_SUCCESS(err);
3276
3277 // Allocate memory
3278 VkMemoryAllocateInfo memAlloc = {};
3279 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3280 memAlloc.pNext = NULL;
3281 memAlloc.allocationSize = 0;
3282 memAlloc.memoryTypeIndex = 0;
3283
3284 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3285 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003286 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003287 ASSERT_TRUE(pass);
3288 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3289 ASSERT_VK_SUCCESS(err);
3290
3291 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3292 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003293 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003294 ASSERT_VK_SUCCESS(err);
3295 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3296 ASSERT_VK_SUCCESS(err);
3297
3298 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3299 ASSERT_VK_SUCCESS(err);
3300 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3301 ASSERT_VK_SUCCESS(err);
3302
Tony Barbour552f6c02016-12-21 14:34:07 -07003303 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003304 VkImageCopy copyRegion;
3305 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3306 copyRegion.srcSubresource.mipLevel = 0;
3307 copyRegion.srcSubresource.baseArrayLayer = 0;
3308 copyRegion.srcSubresource.layerCount = 1;
3309 copyRegion.srcOffset.x = 0;
3310 copyRegion.srcOffset.y = 0;
3311 copyRegion.srcOffset.z = 0;
3312 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3313 copyRegion.dstSubresource.mipLevel = 0;
3314 copyRegion.dstSubresource.baseArrayLayer = 0;
3315 copyRegion.dstSubresource.layerCount = 1;
3316 copyRegion.dstOffset.x = 0;
3317 copyRegion.dstOffset.y = 0;
3318 copyRegion.dstOffset.z = 0;
3319 copyRegion.extent.width = 1;
3320 copyRegion.extent.height = 1;
3321 copyRegion.extent.depth = 1;
3322
3323 // Introduce failure by setting srcOffset to a bad granularity value
3324 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3326 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003327 m_errorMonitor->VerifyFound();
3328
3329 // Introduce failure by setting extent to a bad granularity value
3330 copyRegion.srcOffset.y = 0;
3331 copyRegion.extent.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 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003334 m_errorMonitor->VerifyFound();
3335
3336 // Now do some buffer/image copies
3337 vk_testing::Buffer buffer;
3338 VkMemoryPropertyFlags reqs = 0;
3339 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3340 VkBufferImageCopy region = {};
3341 region.bufferOffset = 0;
3342 region.bufferRowLength = 3;
3343 region.bufferImageHeight = 128;
3344 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3345 region.imageSubresource.layerCount = 1;
3346 region.imageExtent.height = 16;
3347 region.imageExtent.width = 16;
3348 region.imageExtent.depth = 1;
3349 region.imageOffset.x = 0;
3350 region.imageOffset.y = 0;
3351 region.imageOffset.z = 0;
3352
3353 // Introduce failure by setting bufferRowLength to a bad granularity value
3354 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3356 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3357 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003358 m_errorMonitor->VerifyFound();
3359 region.bufferRowLength = 128;
3360
3361 // Introduce failure by setting bufferOffset to a bad granularity value
3362 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3364 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3365 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003366 m_errorMonitor->VerifyFound();
3367 region.bufferOffset = 0;
3368
3369 // Introduce failure by setting bufferImageHeight to a bad granularity value
3370 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3372 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3373 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003374 m_errorMonitor->VerifyFound();
3375 region.bufferImageHeight = 128;
3376
3377 // Introduce failure by setting imageExtent to a bad granularity value
3378 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3380 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3381 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003382 m_errorMonitor->VerifyFound();
3383 region.imageExtent.width = 16;
3384
3385 // Introduce failure by setting imageOffset to a bad granularity value
3386 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3388 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3389 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003390 m_errorMonitor->VerifyFound();
3391
Tony Barbour552f6c02016-12-21 14:34:07 -07003392 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003393
3394 vkDestroyImage(m_device->device(), srcImage, NULL);
3395 vkDestroyImage(m_device->device(), dstImage, NULL);
3396 vkFreeMemory(m_device->device(), srcMem, NULL);
3397 vkFreeMemory(m_device->device(), destMem, NULL);
3398}
3399
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003400TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003401 TEST_DESCRIPTION(
3402 "Submit command buffer created using one queue family and "
3403 "attempt to submit them on a queue created in a different "
3404 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003405
Cody Northropc31a84f2016-08-22 10:41:47 -06003406 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003407
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003408 // This test is meaningless unless we have multiple queue families
3409 auto queue_family_properties = m_device->phy().queue_properties();
3410 if (queue_family_properties.size() < 2) {
3411 return;
3412 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003414 // Get safe index of another queue family
3415 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3416 ASSERT_NO_FATAL_FAILURE(InitState());
3417 // Create a second queue using a different queue family
3418 VkQueue other_queue;
3419 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3420
3421 // Record an empty cmd buffer
3422 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3423 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3424 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3425 vkEndCommandBuffer(m_commandBuffer->handle());
3426
3427 // And submit on the wrong queue
3428 VkSubmitInfo submit_info = {};
3429 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3430 submit_info.commandBufferCount = 1;
3431 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003432 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003433
3434 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003435}
3436
Chris Forbes4c24a922016-11-16 08:59:10 +13003437TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3438 ASSERT_NO_FATAL_FAILURE(InitState());
3439
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003440 // There are no attachments, but refer to attachment 0.
3441 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003442 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003443 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003444 };
3445
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003446 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003447 VkRenderPass rp;
3448
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003449 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003451 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3452 m_errorMonitor->VerifyFound();
3453}
3454
Chris Forbesa58c4522016-09-28 15:19:39 +13003455TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3456 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3457 ASSERT_NO_FATAL_FAILURE(InitState());
3458
3459 // A renderpass with two subpasses, both writing the same attachment.
3460 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003461 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3462 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3463 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003464 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003465 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003466 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003467 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3468 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003469 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003470 VkSubpassDependency dep = {0,
3471 1,
3472 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3473 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3474 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3475 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3476 VK_DEPENDENCY_BY_REGION_BIT};
3477 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003478 VkRenderPass rp;
3479 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3480 ASSERT_VK_SUCCESS(err);
3481
3482 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003483 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 +13003484 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3485
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003486 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003487 VkFramebuffer fb;
3488 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3489 ASSERT_VK_SUCCESS(err);
3490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003491 char const *vsSource =
3492 "#version 450\n"
3493 "void main() { gl_Position = vec4(1); }\n";
3494 char const *fsSource =
3495 "#version 450\n"
3496 "layout(location=0) out vec4 color;\n"
3497 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003498
3499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3501 VkPipelineObj pipe(m_device);
3502 pipe.AddColorAttachment();
3503 pipe.AddShader(&vs);
3504 pipe.AddShader(&fs);
3505 VkViewport view_port = {};
3506 m_viewports.push_back(view_port);
3507 pipe.SetViewport(m_viewports);
3508 VkRect2D rect = {};
3509 m_scissors.push_back(rect);
3510 pipe.SetScissor(m_scissors);
3511
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003512 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003513 VkPipelineLayout pl;
3514 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3515 ASSERT_VK_SUCCESS(err);
3516 pipe.CreateVKPipeline(pl, rp);
3517
Tony Barbour552f6c02016-12-21 14:34:07 -07003518 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003519
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003520 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3521 nullptr,
3522 rp,
3523 fb,
3524 {{
3525 0, 0,
3526 },
3527 {32, 32}},
3528 0,
3529 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003530
3531 // subtest 1: bind in the wrong subpass
3532 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3533 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003534 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 +13003535 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3536 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3537 m_errorMonitor->VerifyFound();
3538
3539 vkCmdEndRenderPass(m_commandBuffer->handle());
3540
3541 // subtest 2: bind in correct subpass, then transition to next subpass
3542 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3543 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3544 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003545 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 +13003546 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3547 m_errorMonitor->VerifyFound();
3548
3549 vkCmdEndRenderPass(m_commandBuffer->handle());
3550
Tony Barbour552f6c02016-12-21 14:34:07 -07003551 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003552
3553 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3554 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3555 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3556}
3557
Tony Barbour4e919972016-08-09 13:27:40 -06003558TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003559 TEST_DESCRIPTION(
3560 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3561 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003562 ASSERT_NO_FATAL_FAILURE(InitState());
3563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3564
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3566 "Cannot execute a render pass with renderArea "
3567 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003568
3569 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3570 m_renderPassBeginInfo.renderArea.extent.width = 257;
3571 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003572 m_commandBuffer->BeginCommandBuffer();
3573 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003574 m_errorMonitor->VerifyFound();
3575}
3576
3577TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003578 TEST_DESCRIPTION(
3579 "Generate INDEPENDENT_BLEND by disabling independent "
3580 "blend and then specifying different blend states for two "
3581 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003582 VkPhysicalDeviceFeatures features = {};
3583 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003584 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3587 "Invalid Pipeline CreateInfo: If independent blend feature not "
3588 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003589
Cody Northropc31a84f2016-08-22 10:41:47 -06003590 VkDescriptorSetObj descriptorSet(m_device);
3591 descriptorSet.AppendDummy();
3592 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003593
Cody Northropc31a84f2016-08-22 10:41:47 -06003594 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003595 // Create a renderPass with two color attachments
3596 VkAttachmentReference attachments[2] = {};
3597 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003598 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003599 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3600
3601 VkSubpassDescription subpass = {};
3602 subpass.pColorAttachments = attachments;
3603 subpass.colorAttachmentCount = 2;
3604
3605 VkRenderPassCreateInfo rpci = {};
3606 rpci.subpassCount = 1;
3607 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003608 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003609
Tony Barbourffd60bd2017-03-09 12:04:55 -07003610 VkAttachmentDescription attach_desc[2] = {};
3611 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3612 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3613 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3614 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3615 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3616 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3617 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3618 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003619
Tony Barbourffd60bd2017-03-09 12:04:55 -07003620 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003621 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3622
3623 VkRenderPass renderpass;
3624 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003625 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003626 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003627
Cody Northropc31a84f2016-08-22 10:41:47 -06003628 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3629 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3630 att_state1.blendEnable = VK_TRUE;
3631 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3632 att_state2.blendEnable = VK_FALSE;
3633 pipeline.AddColorAttachment(0, &att_state1);
3634 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003635 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003636 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003637 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003638}
3639
Mike Weiblen40b160e2017-02-06 19:21:52 -07003640// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3641TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3642 TEST_DESCRIPTION(
3643 "Create a graphics pipeline that is incompatible with the requirements "
3644 "of its contained Renderpass/subpasses.");
3645 ASSERT_NO_FATAL_FAILURE(InitState());
3646
3647 VkDescriptorSetObj ds_obj(m_device);
3648 ds_obj.AppendDummy();
3649 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3650
3651 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3652
3653 VkPipelineColorBlendAttachmentState att_state1 = {};
3654 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3655 att_state1.blendEnable = VK_TRUE;
3656
3657 VkRenderpassObj rp_obj(m_device);
3658
3659 {
3660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3661 VkPipelineObj pipeline(m_device);
3662 pipeline.AddShader(&vs_obj);
3663 pipeline.AddColorAttachment(0, &att_state1);
3664
3665 VkGraphicsPipelineCreateInfo info = {};
3666 pipeline.InitGraphicsPipelineCreateInfo(&info);
3667 info.pColorBlendState = nullptr;
3668
3669 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3670 m_errorMonitor->VerifyFound();
3671 }
3672}
3673
Chris Forbes26ec2122016-11-29 08:58:33 +13003674#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003675TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3676 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3677 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003678 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3681 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003682
3683 // Create a renderPass with a single color attachment
3684 VkAttachmentReference attach = {};
3685 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3686 VkSubpassDescription subpass = {};
3687 VkRenderPassCreateInfo rpci = {};
3688 rpci.subpassCount = 1;
3689 rpci.pSubpasses = &subpass;
3690 rpci.attachmentCount = 1;
3691 VkAttachmentDescription attach_desc = {};
3692 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3693 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3694 rpci.pAttachments = &attach_desc;
3695 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3696 VkRenderPass rp;
3697 subpass.pDepthStencilAttachment = &attach;
3698 subpass.pColorAttachments = NULL;
3699 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3700 m_errorMonitor->VerifyFound();
3701}
Chris Forbes26ec2122016-11-29 08:58:33 +13003702#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003703
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003704TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003705 TEST_DESCRIPTION(
3706 "Create a framebuffer where a subpass has a preserve "
3707 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003708
3709 ASSERT_NO_FATAL_FAILURE(InitState());
3710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003713
3714 VkAttachmentReference color_attach = {};
3715 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3716 color_attach.attachment = 0;
3717 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3718 VkSubpassDescription subpass = {};
3719 subpass.colorAttachmentCount = 1;
3720 subpass.pColorAttachments = &color_attach;
3721 subpass.preserveAttachmentCount = 1;
3722 subpass.pPreserveAttachments = &preserve_attachment;
3723
3724 VkRenderPassCreateInfo rpci = {};
3725 rpci.subpassCount = 1;
3726 rpci.pSubpasses = &subpass;
3727 rpci.attachmentCount = 1;
3728 VkAttachmentDescription attach_desc = {};
3729 attach_desc.format = VK_FORMAT_UNDEFINED;
3730 rpci.pAttachments = &attach_desc;
3731 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3732 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003733 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003734
3735 m_errorMonitor->VerifyFound();
3736
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003737 if (result == VK_SUCCESS) {
3738 vkDestroyRenderPass(m_device->device(), rp, NULL);
3739 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003740}
3741
Chris Forbesc5389742016-06-29 11:49:23 +12003742TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003743 TEST_DESCRIPTION(
3744 "Ensure that CreateRenderPass produces a validation error "
3745 "when the source of a subpass multisample resolve "
3746 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003747
Chris Forbesc5389742016-06-29 11:49:23 +12003748 ASSERT_NO_FATAL_FAILURE(InitState());
3749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3751 "Subpass 0 requests multisample resolve from attachment 0 which has "
3752 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003753
3754 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003755 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3756 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3757 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3758 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3759 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3760 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003761 };
3762
3763 VkAttachmentReference color = {
3764 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3765 };
3766
3767 VkAttachmentReference resolve = {
3768 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3769 };
3770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003771 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003774
3775 VkRenderPass rp;
3776 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3777
3778 m_errorMonitor->VerifyFound();
3779
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003780 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003781}
3782
3783TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003784 TEST_DESCRIPTION(
3785 "Ensure CreateRenderPass produces a validation error "
3786 "when a subpass multisample resolve operation is "
3787 "requested, and the destination of that resolve has "
3788 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003789
Chris Forbesc5389742016-06-29 11:49:23 +12003790 ASSERT_NO_FATAL_FAILURE(InitState());
3791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3793 "Subpass 0 requests multisample resolve into attachment 1, which "
3794 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003795
3796 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003797 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3798 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3799 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3800 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3801 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3802 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003803 };
3804
3805 VkAttachmentReference color = {
3806 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3807 };
3808
3809 VkAttachmentReference resolve = {
3810 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3811 };
3812
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003813 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003815 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003816
3817 VkRenderPass rp;
3818 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3819
3820 m_errorMonitor->VerifyFound();
3821
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003822 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003823}
3824
Chris Forbes3f128ef2016-06-29 14:58:53 +12003825TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003826 TEST_DESCRIPTION(
3827 "Ensure CreateRenderPass produces a validation error "
3828 "when the color and depth attachments used by a subpass "
3829 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003830
Chris Forbes3f128ef2016-06-29 14:58:53 +12003831 ASSERT_NO_FATAL_FAILURE(InitState());
3832
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3834 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003835
3836 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003837 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3838 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3839 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3840 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3841 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3842 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003843 };
3844
3845 VkAttachmentReference color[] = {
3846 {
3847 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3848 },
3849 {
3850 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3851 },
3852 };
3853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003854 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003856 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003857
3858 VkRenderPass rp;
3859 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3860
3861 m_errorMonitor->VerifyFound();
3862
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003863 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003864}
3865
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003866TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003867 TEST_DESCRIPTION(
3868 "Hit errors when attempting to create a framebuffer :\n"
3869 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3870 " 2. Use a color image as depthStencil attachment\n"
3871 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3872 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3873 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3874 " 6. Framebuffer attachment where dimensions don't match\n"
3875 " 7. Framebuffer attachment w/o identity swizzle\n"
3876 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003877
3878 ASSERT_NO_FATAL_FAILURE(InitState());
3879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3880
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003881 m_errorMonitor->SetDesiredFailureMsg(
3882 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3883 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003884
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003885 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003886 VkAttachmentReference attach = {};
3887 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3888 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003889 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003890 VkRenderPassCreateInfo rpci = {};
3891 rpci.subpassCount = 1;
3892 rpci.pSubpasses = &subpass;
3893 rpci.attachmentCount = 1;
3894 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003895 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003896 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003897 rpci.pAttachments = &attach_desc;
3898 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3899 VkRenderPass rp;
3900 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3901 ASSERT_VK_SUCCESS(err);
3902
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003903 VkImageView ivs[2];
3904 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3905 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003906 VkFramebufferCreateInfo fb_info = {};
3907 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3908 fb_info.pNext = NULL;
3909 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003910 // Set mis-matching attachmentCount
3911 fb_info.attachmentCount = 2;
3912 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003913 fb_info.width = 100;
3914 fb_info.height = 100;
3915 fb_info.layers = 1;
3916
3917 VkFramebuffer fb;
3918 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3919
3920 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003921 if (err == VK_SUCCESS) {
3922 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3923 }
3924 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003925
3926 // Create a renderPass with a depth-stencil attachment created with
3927 // IMAGE_USAGE_COLOR_ATTACHMENT
3928 // Add our color attachment to pDepthStencilAttachment
3929 subpass.pDepthStencilAttachment = &attach;
3930 subpass.pColorAttachments = NULL;
3931 VkRenderPass rp_ds;
3932 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3933 ASSERT_VK_SUCCESS(err);
3934 // Set correct attachment count, but attachment has COLOR usage bit set
3935 fb_info.attachmentCount = 1;
3936 fb_info.renderPass = rp_ds;
3937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003939 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3940
3941 m_errorMonitor->VerifyFound();
3942 if (err == VK_SUCCESS) {
3943 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3944 }
3945 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003946
3947 // Create new renderpass with alternate attachment format from fb
3948 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3949 subpass.pDepthStencilAttachment = NULL;
3950 subpass.pColorAttachments = &attach;
3951 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3952 ASSERT_VK_SUCCESS(err);
3953
3954 // Cause error due to mis-matched formats between rp & fb
3955 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3956 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3958 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003959 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3960
3961 m_errorMonitor->VerifyFound();
3962 if (err == VK_SUCCESS) {
3963 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3964 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003965 vkDestroyRenderPass(m_device->device(), rp, NULL);
3966
3967 // Create new renderpass with alternate sample count from fb
3968 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3969 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3970 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3971 ASSERT_VK_SUCCESS(err);
3972
3973 // Cause error due to mis-matched sample count between rp & fb
3974 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003976 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -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 Ehlisd3bb23a2016-06-22 13:34:46 -06003983
3984 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003985
3986 // Create a custom imageView with non-1 mip levels
3987 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003988 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 -06003989 ASSERT_TRUE(image.initialized());
3990
3991 VkImageView view;
3992 VkImageViewCreateInfo ivci = {};
3993 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3994 ivci.image = image.handle();
3995 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3996 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3997 ivci.subresourceRange.layerCount = 1;
3998 ivci.subresourceRange.baseMipLevel = 0;
3999 // Set level count 2 (only 1 is allowed for FB attachment)
4000 ivci.subresourceRange.levelCount = 2;
4001 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4002 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4003 ASSERT_VK_SUCCESS(err);
4004 // Re-create renderpass to have matching sample count
4005 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4006 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4007 ASSERT_VK_SUCCESS(err);
4008
4009 fb_info.renderPass = rp;
4010 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004012 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4013
4014 m_errorMonitor->VerifyFound();
4015 if (err == VK_SUCCESS) {
4016 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4017 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004018 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004019 // Update view to original color buffer and grow FB dimensions too big
4020 fb_info.pAttachments = ivs;
4021 fb_info.height = 1024;
4022 fb_info.width = 1024;
4023 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004025 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4026
4027 m_errorMonitor->VerifyFound();
4028 if (err == VK_SUCCESS) {
4029 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4030 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004031 // Create view attachment with non-identity swizzle
4032 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4033 ivci.image = image.handle();
4034 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4035 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4036 ivci.subresourceRange.layerCount = 1;
4037 ivci.subresourceRange.baseMipLevel = 0;
4038 ivci.subresourceRange.levelCount = 1;
4039 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4040 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4041 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4042 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4043 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4044 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4045 ASSERT_VK_SUCCESS(err);
4046
4047 fb_info.pAttachments = &view;
4048 fb_info.height = 100;
4049 fb_info.width = 100;
4050 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004051 m_errorMonitor->SetDesiredFailureMsg(
4052 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4053 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004054 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4055
4056 m_errorMonitor->VerifyFound();
4057 if (err == VK_SUCCESS) {
4058 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4059 }
4060 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004061 // reset attachment to color attachment
4062 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004063
4064 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004065 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004066 fb_info.height = 100;
4067 fb_info.layers = 1;
4068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004069 m_errorMonitor->SetDesiredFailureMsg(
4070 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004071 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4072 "Here are the respective dimensions for attachment");
4073
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004074 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4075
4076 m_errorMonitor->VerifyFound();
4077 if (err == VK_SUCCESS) {
4078 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4079 }
4080
4081 // Request fb that exceeds max height
4082 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004083 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004084 fb_info.layers = 1;
4085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004086 m_errorMonitor->SetDesiredFailureMsg(
4087 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004088 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4089 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004090 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4091
4092 m_errorMonitor->VerifyFound();
4093 if (err == VK_SUCCESS) {
4094 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4095 }
4096
4097 // Request fb that exceeds max layers
4098 fb_info.width = 100;
4099 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004100 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004102 m_errorMonitor->SetDesiredFailureMsg(
4103 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004104 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4105 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004106 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4107
4108 m_errorMonitor->VerifyFound();
4109 if (err == VK_SUCCESS) {
4110 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4111 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004112
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004113 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004114}
4115
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004116TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004117 TEST_DESCRIPTION(
4118 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4119 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004120
Cody Northropc31a84f2016-08-22 10:41:47 -06004121 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004122 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4124 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004125 m_errorMonitor->VerifyFound();
4126}
4127
4128TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004129 TEST_DESCRIPTION(
4130 "Run a simple draw calls to validate failure when Line Width dynamic "
4131 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004132
Cody Northropc31a84f2016-08-22 10:41:47 -06004133 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004134 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4136 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004137 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004138}
4139
4140TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004141 TEST_DESCRIPTION(
4142 "Run a simple draw calls to validate failure when Viewport dynamic "
4143 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004144
Cody Northropc31a84f2016-08-22 10:41:47 -06004145 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004146 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4148 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004149 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004150 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004151}
4152
4153TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004154 TEST_DESCRIPTION(
4155 "Run a simple draw calls to validate failure when Scissor dynamic "
4156 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004157
Cody Northropc31a84f2016-08-22 10:41:47 -06004158 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004159 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4161 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004162 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004163 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004164}
4165
Cortd713fe82016-07-27 09:51:27 -07004166TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004167 TEST_DESCRIPTION(
4168 "Run a simple draw calls to validate failure when Blend Constants "
4169 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004170
4171 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004172 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4174 "Dynamic blend constants state not set for this command buffer");
4175 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004176 m_errorMonitor->VerifyFound();
4177}
4178
4179TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004180 TEST_DESCRIPTION(
4181 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4182 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004183
4184 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004185 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004186 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004187 return;
4188 }
4189 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4191 "Dynamic depth bounds state not set for this command buffer");
4192 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004193 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004194}
4195
4196TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004197 TEST_DESCRIPTION(
4198 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4199 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004200
4201 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004202 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4204 "Dynamic stencil read mask state not set for this command buffer");
4205 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004206 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004207}
4208
4209TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004210 TEST_DESCRIPTION(
4211 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4212 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004213
4214 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004215 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4217 "Dynamic stencil write mask state not set for this command buffer");
4218 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004219 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004220}
4221
4222TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004223 TEST_DESCRIPTION(
4224 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4225 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004226
4227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004228 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4230 "Dynamic stencil reference state not set for this command buffer");
4231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004232 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004233}
4234
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004235TEST_F(VkLayerTest, IndexBufferNotBound) {
4236 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004237
4238 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4240 "Index buffer object not bound to this command buffer when Indexed ");
4241 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004242 m_errorMonitor->VerifyFound();
4243}
4244
Karl Schultz6addd812016-02-02 17:17:23 -07004245TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4247 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4248 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004249
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004250 ASSERT_NO_FATAL_FAILURE(InitState());
4251 ASSERT_NO_FATAL_FAILURE(InitViewport());
4252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4253
Karl Schultz6addd812016-02-02 17:17:23 -07004254 // We luck out b/c by default the framework creates CB w/ the
4255 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004256 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004257 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004258 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004259
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004260 // Bypass framework since it does the waits automatically
4261 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004262 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4264 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004265 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004266 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004267 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004268 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004269 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004270 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004271 submit_info.pSignalSemaphores = NULL;
4272
Chris Forbes40028e22016-06-13 09:59:34 +12004273 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004274 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004275 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004276
Karl Schultz6addd812016-02-02 17:17:23 -07004277 // Cause validation error by re-submitting cmd buffer that should only be
4278 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004279 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004280 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004282 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004283}
4284
Karl Schultz6addd812016-02-02 17:17:23 -07004285TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004286 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004287 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004288
4289 ASSERT_NO_FATAL_FAILURE(InitState());
4290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004291
Karl Schultz6addd812016-02-02 17:17:23 -07004292 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4293 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004294 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004295 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004296 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004297
4298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4300 ds_pool_ci.pNext = NULL;
4301 ds_pool_ci.flags = 0;
4302 ds_pool_ci.maxSets = 1;
4303 ds_pool_ci.poolSizeCount = 1;
4304 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004305
4306 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004307 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004308 ASSERT_VK_SUCCESS(err);
4309
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004310 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4311 dsl_binding_samp.binding = 0;
4312 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4313 dsl_binding_samp.descriptorCount = 1;
4314 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4315 dsl_binding_samp.pImmutableSamplers = NULL;
4316
4317 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4318 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4319 ds_layout_ci.pNext = NULL;
4320 ds_layout_ci.bindingCount = 1;
4321 ds_layout_ci.pBindings = &dsl_binding_samp;
4322
4323 VkDescriptorSetLayout ds_layout_samp;
4324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4325 ASSERT_VK_SUCCESS(err);
4326
4327 // Try to allocate 2 sets when pool only has 1 set
4328 VkDescriptorSet descriptor_sets[2];
4329 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4330 VkDescriptorSetAllocateInfo alloc_info = {};
4331 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4332 alloc_info.descriptorSetCount = 2;
4333 alloc_info.descriptorPool = ds_pool;
4334 alloc_info.pSetLayouts = set_layouts;
4335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4337 m_errorMonitor->VerifyFound();
4338
4339 alloc_info.descriptorSetCount = 1;
4340 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004341 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004342 dsl_binding.binding = 0;
4343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4344 dsl_binding.descriptorCount = 1;
4345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4346 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004347
Karl Schultz6addd812016-02-02 17:17:23 -07004348 ds_layout_ci.bindingCount = 1;
4349 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004350
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004351 VkDescriptorSetLayout ds_layout_ub;
4352 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004353 ASSERT_VK_SUCCESS(err);
4354
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004355 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004356 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004357 alloc_info.pSetLayouts = &ds_layout_ub;
4358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4359 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004361 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004362
Karl Schultz2825ab92016-12-02 08:23:14 -07004363 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004364 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004365 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004366}
4367
Karl Schultz6addd812016-02-02 17:17:23 -07004368TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4369 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004370
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004372
Tobin Ehlise735c692015-10-08 13:13:50 -06004373 ASSERT_NO_FATAL_FAILURE(InitState());
4374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004375
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004376 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004377 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4378 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004379
4380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4382 ds_pool_ci.pNext = NULL;
4383 ds_pool_ci.maxSets = 1;
4384 ds_pool_ci.poolSizeCount = 1;
4385 ds_pool_ci.flags = 0;
4386 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4387 // app can only call vkResetDescriptorPool on this pool.;
4388 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004389
4390 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004391 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004392 ASSERT_VK_SUCCESS(err);
4393
4394 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004395 dsl_binding.binding = 0;
4396 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4397 dsl_binding.descriptorCount = 1;
4398 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4399 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004400
4401 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004402 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4403 ds_layout_ci.pNext = NULL;
4404 ds_layout_ci.bindingCount = 1;
4405 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004406
4407 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004409 ASSERT_VK_SUCCESS(err);
4410
4411 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004412 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004413 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004414 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004415 alloc_info.descriptorPool = ds_pool;
4416 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004417 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004418 ASSERT_VK_SUCCESS(err);
4419
4420 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004421 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004422
Chia-I Wuf7458c52015-10-26 21:10:41 +08004423 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4424 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004425}
4426
Karl Schultz6addd812016-02-02 17:17:23 -07004427TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004428 // Attempt to clear Descriptor Pool with bad object.
4429 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004430
4431 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004433 uint64_t fake_pool_handle = 0xbaad6001;
4434 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4435 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004436 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004437}
4438
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004439TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004440 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4441 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004442 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004443 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004444
4445 uint64_t fake_set_handle = 0xbaad6001;
4446 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004447 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004449
4450 ASSERT_NO_FATAL_FAILURE(InitState());
4451
4452 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4453 layout_bindings[0].binding = 0;
4454 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4455 layout_bindings[0].descriptorCount = 1;
4456 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4457 layout_bindings[0].pImmutableSamplers = NULL;
4458
4459 VkDescriptorSetLayout descriptor_set_layout;
4460 VkDescriptorSetLayoutCreateInfo dslci = {};
4461 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4462 dslci.pNext = NULL;
4463 dslci.bindingCount = 1;
4464 dslci.pBindings = layout_bindings;
4465 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004466 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004467
4468 VkPipelineLayout pipeline_layout;
4469 VkPipelineLayoutCreateInfo plci = {};
4470 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4471 plci.pNext = NULL;
4472 plci.setLayoutCount = 1;
4473 plci.pSetLayouts = &descriptor_set_layout;
4474 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004475 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004476
Tony Barbour552f6c02016-12-21 14:34:07 -07004477 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004478 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4479 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004480 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004481 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004482 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4483 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004484}
4485
Karl Schultz6addd812016-02-02 17:17:23 -07004486TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004487 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4488 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004489 uint64_t fake_layout_handle = 0xbaad6001;
4490 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004492 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004493 VkPipelineLayout pipeline_layout;
4494 VkPipelineLayoutCreateInfo plci = {};
4495 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4496 plci.pNext = NULL;
4497 plci.setLayoutCount = 1;
4498 plci.pSetLayouts = &bad_layout;
4499 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4500
4501 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004502}
4503
Mark Muellerd4914412016-06-13 17:52:06 -06004504TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004505 TEST_DESCRIPTION(
4506 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4507 "1) A uniform buffer update must have a valid buffer index."
4508 "2) When using an array of descriptors in a single WriteDescriptor,"
4509 " the descriptor types and stageflags must all be the same."
4510 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004511
Mike Weiblena6666382017-01-05 15:16:11 -07004512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004513
4514 ASSERT_NO_FATAL_FAILURE(InitState());
4515 VkDescriptorPoolSize ds_type_count[4] = {};
4516 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4517 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004518 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004519 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004520 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004521 ds_type_count[2].descriptorCount = 1;
4522 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4523 ds_type_count[3].descriptorCount = 1;
4524
4525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4527 ds_pool_ci.maxSets = 1;
4528 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4529 ds_pool_ci.pPoolSizes = ds_type_count;
4530
4531 VkDescriptorPool ds_pool;
4532 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4533 ASSERT_VK_SUCCESS(err);
4534
Mark Muellerb9896722016-06-16 09:54:29 -06004535 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004536 layout_binding[0].binding = 0;
4537 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4538 layout_binding[0].descriptorCount = 1;
4539 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4540 layout_binding[0].pImmutableSamplers = NULL;
4541
4542 layout_binding[1].binding = 1;
4543 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4544 layout_binding[1].descriptorCount = 1;
4545 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4546 layout_binding[1].pImmutableSamplers = NULL;
4547
4548 VkSamplerCreateInfo sampler_ci = {};
4549 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4550 sampler_ci.pNext = NULL;
4551 sampler_ci.magFilter = VK_FILTER_NEAREST;
4552 sampler_ci.minFilter = VK_FILTER_NEAREST;
4553 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4554 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4555 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4556 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4557 sampler_ci.mipLodBias = 1.0;
4558 sampler_ci.anisotropyEnable = VK_FALSE;
4559 sampler_ci.maxAnisotropy = 1;
4560 sampler_ci.compareEnable = VK_FALSE;
4561 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4562 sampler_ci.minLod = 1.0;
4563 sampler_ci.maxLod = 1.0;
4564 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4565 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4566 VkSampler sampler;
4567
4568 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4569 ASSERT_VK_SUCCESS(err);
4570
4571 layout_binding[2].binding = 2;
4572 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4573 layout_binding[2].descriptorCount = 1;
4574 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4575 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4576
Mark Muellerd4914412016-06-13 17:52:06 -06004577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4579 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4580 ds_layout_ci.pBindings = layout_binding;
4581 VkDescriptorSetLayout ds_layout;
4582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4583 ASSERT_VK_SUCCESS(err);
4584
4585 VkDescriptorSetAllocateInfo alloc_info = {};
4586 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4587 alloc_info.descriptorSetCount = 1;
4588 alloc_info.descriptorPool = ds_pool;
4589 alloc_info.pSetLayouts = &ds_layout;
4590 VkDescriptorSet descriptorSet;
4591 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4592 ASSERT_VK_SUCCESS(err);
4593
4594 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4595 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4596 pipeline_layout_ci.pNext = NULL;
4597 pipeline_layout_ci.setLayoutCount = 1;
4598 pipeline_layout_ci.pSetLayouts = &ds_layout;
4599
4600 VkPipelineLayout pipeline_layout;
4601 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4602 ASSERT_VK_SUCCESS(err);
4603
Mark Mueller5c838ce2016-06-16 09:54:29 -06004604 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004605 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4606 descriptor_write.dstSet = descriptorSet;
4607 descriptor_write.dstBinding = 0;
4608 descriptor_write.descriptorCount = 1;
4609 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4610
Mark Mueller5c838ce2016-06-16 09:54:29 -06004611 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004612 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4613 m_errorMonitor->VerifyFound();
4614
4615 // Create a buffer to update the descriptor with
4616 uint32_t qfi = 0;
4617 VkBufferCreateInfo buffCI = {};
4618 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4619 buffCI.size = 1024;
4620 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4621 buffCI.queueFamilyIndexCount = 1;
4622 buffCI.pQueueFamilyIndices = &qfi;
4623
4624 VkBuffer dyub;
4625 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4626 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004627
Tony Barboure132c5f2016-12-12 11:50:20 -07004628 VkDeviceMemory mem;
4629 VkMemoryRequirements mem_reqs;
4630 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4631
4632 VkMemoryAllocateInfo mem_alloc_info = {};
4633 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4634 mem_alloc_info.allocationSize = mem_reqs.size;
4635 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4636 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4637 ASSERT_VK_SUCCESS(err);
4638
4639 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4640 ASSERT_VK_SUCCESS(err);
4641
4642 VkDescriptorBufferInfo buffInfo[2] = {};
4643 buffInfo[0].buffer = dyub;
4644 buffInfo[0].offset = 0;
4645 buffInfo[0].range = 1024;
4646 buffInfo[1].buffer = dyub;
4647 buffInfo[1].offset = 0;
4648 buffInfo[1].range = 1024;
4649 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004650 descriptor_write.descriptorCount = 2;
4651
Mark Mueller5c838ce2016-06-16 09:54:29 -06004652 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004654 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4655 m_errorMonitor->VerifyFound();
4656
Mark Mueller5c838ce2016-06-16 09:54:29 -06004657 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4658 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004659 descriptor_write.dstBinding = 1;
4660 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004661
Mark Mueller5c838ce2016-06-16 09:54:29 -06004662 // Make pImageInfo index non-null to avoid complaints of it missing
4663 VkDescriptorImageInfo imageInfo = {};
4664 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4665 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004667 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4668 m_errorMonitor->VerifyFound();
4669
Mark Muellerd4914412016-06-13 17:52:06 -06004670 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004671 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004672 vkDestroySampler(m_device->device(), sampler, NULL);
4673 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4676}
4677
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004678TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004679 TEST_DESCRIPTION(
4680 "Attempt to draw with a command buffer that is invalid "
4681 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004682 ASSERT_NO_FATAL_FAILURE(InitState());
4683
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004684 VkBuffer buffer;
4685 VkDeviceMemory mem;
4686 VkMemoryRequirements mem_reqs;
4687
4688 VkBufferCreateInfo buf_info = {};
4689 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004690 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004691 buf_info.size = 256;
4692 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4693 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4694 ASSERT_VK_SUCCESS(err);
4695
4696 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4697
4698 VkMemoryAllocateInfo alloc_info = {};
4699 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4700 alloc_info.allocationSize = 256;
4701 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004702 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 -06004703 if (!pass) {
4704 vkDestroyBuffer(m_device->device(), buffer, NULL);
4705 return;
4706 }
4707 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4708 ASSERT_VK_SUCCESS(err);
4709
4710 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4711 ASSERT_VK_SUCCESS(err);
4712
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004713 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004714 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004715 m_commandBuffer->EndCommandBuffer();
4716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004718 // Destroy buffer dependency prior to submit to cause ERROR
4719 vkDestroyBuffer(m_device->device(), buffer, NULL);
4720
4721 VkSubmitInfo submit_info = {};
4722 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4723 submit_info.commandBufferCount = 1;
4724 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4725 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4726
4727 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004728 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004729 vkFreeMemory(m_device->handle(), mem, NULL);
4730}
4731
Tobin Ehlisea413442016-09-28 10:23:59 -06004732TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4733 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4734
4735 ASSERT_NO_FATAL_FAILURE(InitState());
4736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4737
4738 VkDescriptorPoolSize ds_type_count;
4739 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4740 ds_type_count.descriptorCount = 1;
4741
4742 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4743 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4744 ds_pool_ci.maxSets = 1;
4745 ds_pool_ci.poolSizeCount = 1;
4746 ds_pool_ci.pPoolSizes = &ds_type_count;
4747
4748 VkDescriptorPool ds_pool;
4749 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4750 ASSERT_VK_SUCCESS(err);
4751
4752 VkDescriptorSetLayoutBinding layout_binding;
4753 layout_binding.binding = 0;
4754 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4755 layout_binding.descriptorCount = 1;
4756 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4757 layout_binding.pImmutableSamplers = NULL;
4758
4759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4761 ds_layout_ci.bindingCount = 1;
4762 ds_layout_ci.pBindings = &layout_binding;
4763 VkDescriptorSetLayout ds_layout;
4764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4765 ASSERT_VK_SUCCESS(err);
4766
4767 VkDescriptorSetAllocateInfo alloc_info = {};
4768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4769 alloc_info.descriptorSetCount = 1;
4770 alloc_info.descriptorPool = ds_pool;
4771 alloc_info.pSetLayouts = &ds_layout;
4772 VkDescriptorSet descriptor_set;
4773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4774 ASSERT_VK_SUCCESS(err);
4775
4776 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4777 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4778 pipeline_layout_ci.pNext = NULL;
4779 pipeline_layout_ci.setLayoutCount = 1;
4780 pipeline_layout_ci.pSetLayouts = &ds_layout;
4781
4782 VkPipelineLayout pipeline_layout;
4783 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4784 ASSERT_VK_SUCCESS(err);
4785
4786 VkBuffer buffer;
4787 uint32_t queue_family_index = 0;
4788 VkBufferCreateInfo buffer_create_info = {};
4789 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4790 buffer_create_info.size = 1024;
4791 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4792 buffer_create_info.queueFamilyIndexCount = 1;
4793 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4794
4795 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4796 ASSERT_VK_SUCCESS(err);
4797
4798 VkMemoryRequirements memory_reqs;
4799 VkDeviceMemory buffer_memory;
4800
4801 VkMemoryAllocateInfo memory_info = {};
4802 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4803 memory_info.allocationSize = 0;
4804 memory_info.memoryTypeIndex = 0;
4805
4806 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4807 memory_info.allocationSize = memory_reqs.size;
4808 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4809 ASSERT_TRUE(pass);
4810
4811 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4812 ASSERT_VK_SUCCESS(err);
4813 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4814 ASSERT_VK_SUCCESS(err);
4815
4816 VkBufferView view;
4817 VkBufferViewCreateInfo bvci = {};
4818 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4819 bvci.buffer = buffer;
4820 bvci.format = VK_FORMAT_R8_UNORM;
4821 bvci.range = VK_WHOLE_SIZE;
4822
4823 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4824 ASSERT_VK_SUCCESS(err);
4825
4826 VkWriteDescriptorSet descriptor_write = {};
4827 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4828 descriptor_write.dstSet = descriptor_set;
4829 descriptor_write.dstBinding = 0;
4830 descriptor_write.descriptorCount = 1;
4831 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4832 descriptor_write.pTexelBufferView = &view;
4833
4834 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004836 char const *vsSource =
4837 "#version 450\n"
4838 "\n"
4839 "out gl_PerVertex { \n"
4840 " vec4 gl_Position;\n"
4841 "};\n"
4842 "void main(){\n"
4843 " gl_Position = vec4(1);\n"
4844 "}\n";
4845 char const *fsSource =
4846 "#version 450\n"
4847 "\n"
4848 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4849 "layout(location=0) out vec4 x;\n"
4850 "void main(){\n"
4851 " x = imageLoad(s, 0);\n"
4852 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4855 VkPipelineObj pipe(m_device);
4856 pipe.AddShader(&vs);
4857 pipe.AddShader(&fs);
4858 pipe.AddColorAttachment();
4859 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4860
Tobin Ehlisea413442016-09-28 10:23:59 -06004861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4862
Tony Barbour552f6c02016-12-21 14:34:07 -07004863 m_commandBuffer->BeginCommandBuffer();
4864 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4865
Tobin Ehlisea413442016-09-28 10:23:59 -06004866 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4867 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4868 VkRect2D scissor = {{0, 0}, {16, 16}};
4869 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4870 // Bind pipeline to cmd buffer
4871 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4872 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4873 &descriptor_set, 0, nullptr);
4874 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004875 m_commandBuffer->EndRenderPass();
4876 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004877
4878 // Delete BufferView in order to invalidate cmd buffer
4879 vkDestroyBufferView(m_device->device(), view, NULL);
4880 // Now attempt submit of cmd buffer
4881 VkSubmitInfo submit_info = {};
4882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4883 submit_info.commandBufferCount = 1;
4884 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4885 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4886 m_errorMonitor->VerifyFound();
4887
4888 // Clean-up
4889 vkDestroyBuffer(m_device->device(), buffer, NULL);
4890 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4892 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4893 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4894}
4895
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004896TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004897 TEST_DESCRIPTION(
4898 "Attempt to draw with a command buffer that is invalid "
4899 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004900 ASSERT_NO_FATAL_FAILURE(InitState());
4901
4902 VkImage image;
4903 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4904 VkImageCreateInfo image_create_info = {};
4905 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4906 image_create_info.pNext = NULL;
4907 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4908 image_create_info.format = tex_format;
4909 image_create_info.extent.width = 32;
4910 image_create_info.extent.height = 32;
4911 image_create_info.extent.depth = 1;
4912 image_create_info.mipLevels = 1;
4913 image_create_info.arrayLayers = 1;
4914 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4915 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004916 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004917 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004918 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004919 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004920 // Have to bind memory to image before recording cmd in cmd buffer using it
4921 VkMemoryRequirements mem_reqs;
4922 VkDeviceMemory image_mem;
4923 bool pass;
4924 VkMemoryAllocateInfo mem_alloc = {};
4925 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4926 mem_alloc.pNext = NULL;
4927 mem_alloc.memoryTypeIndex = 0;
4928 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4929 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004930 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004931 ASSERT_TRUE(pass);
4932 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4933 ASSERT_VK_SUCCESS(err);
4934 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4935 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004936
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004937 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004938 VkClearColorValue ccv;
4939 ccv.float32[0] = 1.0f;
4940 ccv.float32[1] = 1.0f;
4941 ccv.float32[2] = 1.0f;
4942 ccv.float32[3] = 1.0f;
4943 VkImageSubresourceRange isr = {};
4944 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004945 isr.baseArrayLayer = 0;
4946 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004947 isr.layerCount = 1;
4948 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004950 m_commandBuffer->EndCommandBuffer();
4951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004953 // Destroy image dependency prior to submit to cause ERROR
4954 vkDestroyImage(m_device->device(), image, NULL);
4955
4956 VkSubmitInfo submit_info = {};
4957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4958 submit_info.commandBufferCount = 1;
4959 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4960 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4961
4962 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004963 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004964}
4965
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004966TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004967 TEST_DESCRIPTION(
4968 "Attempt to draw with a command buffer that is invalid "
4969 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004970 VkFormatProperties format_properties;
4971 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004972 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4973 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004974 return;
4975 }
4976
4977 ASSERT_NO_FATAL_FAILURE(InitState());
4978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4979
4980 VkImageCreateInfo image_ci = {};
4981 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4982 image_ci.pNext = NULL;
4983 image_ci.imageType = VK_IMAGE_TYPE_2D;
4984 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4985 image_ci.extent.width = 32;
4986 image_ci.extent.height = 32;
4987 image_ci.extent.depth = 1;
4988 image_ci.mipLevels = 1;
4989 image_ci.arrayLayers = 1;
4990 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4991 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004992 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004993 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4994 image_ci.flags = 0;
4995 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004996 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004997
4998 VkMemoryRequirements memory_reqs;
4999 VkDeviceMemory image_memory;
5000 bool pass;
5001 VkMemoryAllocateInfo memory_info = {};
5002 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5003 memory_info.pNext = NULL;
5004 memory_info.allocationSize = 0;
5005 memory_info.memoryTypeIndex = 0;
5006 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5007 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005008 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005009 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005011 ASSERT_VK_SUCCESS(err);
5012 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5013 ASSERT_VK_SUCCESS(err);
5014
5015 VkImageViewCreateInfo ivci = {
5016 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5017 nullptr,
5018 0,
5019 image,
5020 VK_IMAGE_VIEW_TYPE_2D,
5021 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005022 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5024 };
5025 VkImageView view;
5026 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5027 ASSERT_VK_SUCCESS(err);
5028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005029 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005030 VkFramebuffer fb;
5031 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5032 ASSERT_VK_SUCCESS(err);
5033
5034 // Just use default renderpass with our framebuffer
5035 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005036 m_renderPassBeginInfo.renderArea.extent.width = 32;
5037 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005038 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005039 m_commandBuffer->BeginCommandBuffer();
5040 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5041 m_commandBuffer->EndRenderPass();
5042 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005043 // Destroy image attached to framebuffer to invalidate cmd buffer
5044 vkDestroyImage(m_device->device(), image, NULL);
5045 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005047 QueueCommandBuffer(false);
5048 m_errorMonitor->VerifyFound();
5049
5050 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5051 vkDestroyImageView(m_device->device(), view, nullptr);
5052 vkFreeMemory(m_device->device(), image_memory, nullptr);
5053}
5054
Tobin Ehlisb329f992016-10-12 13:20:29 -06005055TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5056 TEST_DESCRIPTION("Delete in-use framebuffer.");
5057 VkFormatProperties format_properties;
5058 VkResult err = VK_SUCCESS;
5059 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5060
5061 ASSERT_NO_FATAL_FAILURE(InitState());
5062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5063
5064 VkImageObj image(m_device);
5065 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5066 ASSERT_TRUE(image.initialized());
5067 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5068
5069 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5070 VkFramebuffer fb;
5071 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5072 ASSERT_VK_SUCCESS(err);
5073
5074 // Just use default renderpass with our framebuffer
5075 m_renderPassBeginInfo.framebuffer = fb;
5076 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005077 m_commandBuffer->BeginCommandBuffer();
5078 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5079 m_commandBuffer->EndRenderPass();
5080 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005081 // Submit cmd buffer to put it in-flight
5082 VkSubmitInfo submit_info = {};
5083 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5084 submit_info.commandBufferCount = 1;
5085 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5086 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5087 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005089 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5090 m_errorMonitor->VerifyFound();
5091 // Wait for queue to complete so we can safely destroy everything
5092 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005093 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5094 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005095 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5096}
5097
Tobin Ehlis88becd72016-09-21 14:33:41 -06005098TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5099 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5100 VkFormatProperties format_properties;
5101 VkResult err = VK_SUCCESS;
5102 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005103
5104 ASSERT_NO_FATAL_FAILURE(InitState());
5105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5106
5107 VkImageCreateInfo image_ci = {};
5108 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5109 image_ci.pNext = NULL;
5110 image_ci.imageType = VK_IMAGE_TYPE_2D;
5111 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5112 image_ci.extent.width = 256;
5113 image_ci.extent.height = 256;
5114 image_ci.extent.depth = 1;
5115 image_ci.mipLevels = 1;
5116 image_ci.arrayLayers = 1;
5117 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5118 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005119 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005120 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5121 image_ci.flags = 0;
5122 VkImage image;
5123 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5124
5125 VkMemoryRequirements memory_reqs;
5126 VkDeviceMemory image_memory;
5127 bool pass;
5128 VkMemoryAllocateInfo memory_info = {};
5129 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5130 memory_info.pNext = NULL;
5131 memory_info.allocationSize = 0;
5132 memory_info.memoryTypeIndex = 0;
5133 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5134 memory_info.allocationSize = memory_reqs.size;
5135 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5136 ASSERT_TRUE(pass);
5137 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5138 ASSERT_VK_SUCCESS(err);
5139 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5140 ASSERT_VK_SUCCESS(err);
5141
5142 VkImageViewCreateInfo ivci = {
5143 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5144 nullptr,
5145 0,
5146 image,
5147 VK_IMAGE_VIEW_TYPE_2D,
5148 VK_FORMAT_B8G8R8A8_UNORM,
5149 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5150 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5151 };
5152 VkImageView view;
5153 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5154 ASSERT_VK_SUCCESS(err);
5155
5156 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5157 VkFramebuffer fb;
5158 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5159 ASSERT_VK_SUCCESS(err);
5160
5161 // Just use default renderpass with our framebuffer
5162 m_renderPassBeginInfo.framebuffer = fb;
5163 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005164 m_commandBuffer->BeginCommandBuffer();
5165 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5166 m_commandBuffer->EndRenderPass();
5167 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005168 // Submit cmd buffer to put it (and attached imageView) in-flight
5169 VkSubmitInfo submit_info = {};
5170 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5171 submit_info.commandBufferCount = 1;
5172 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5173 // Submit cmd buffer to put framebuffer and children in-flight
5174 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5175 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005177 vkDestroyImage(m_device->device(), image, NULL);
5178 m_errorMonitor->VerifyFound();
5179 // Wait for queue to complete so we can safely destroy image and other objects
5180 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005181 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5182 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005183 vkDestroyImage(m_device->device(), image, NULL);
5184 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5185 vkDestroyImageView(m_device->device(), view, nullptr);
5186 vkFreeMemory(m_device->device(), image_memory, nullptr);
5187}
5188
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005189TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5190 TEST_DESCRIPTION("Delete in-use renderPass.");
5191
5192 ASSERT_NO_FATAL_FAILURE(InitState());
5193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5194
5195 // Create simple renderpass
5196 VkAttachmentReference attach = {};
5197 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5198 VkSubpassDescription subpass = {};
5199 subpass.pColorAttachments = &attach;
5200 VkRenderPassCreateInfo rpci = {};
5201 rpci.subpassCount = 1;
5202 rpci.pSubpasses = &subpass;
5203 rpci.attachmentCount = 1;
5204 VkAttachmentDescription attach_desc = {};
5205 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5206 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5207 rpci.pAttachments = &attach_desc;
5208 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5209 VkRenderPass rp;
5210 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5211 ASSERT_VK_SUCCESS(err);
5212
5213 // Create a pipeline that uses the given renderpass
5214 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5215 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5216
5217 VkPipelineLayout pipeline_layout;
5218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5219 ASSERT_VK_SUCCESS(err);
5220
5221 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5222 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5223 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005224 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005225 vp_state_ci.pViewports = &vp;
5226 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005227 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005228 vp_state_ci.pScissors = &scissors;
5229
5230 VkPipelineShaderStageCreateInfo shaderStages[2];
5231 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5232
5233 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005234 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 -06005235 // but add it to be able to run on more devices
5236 shaderStages[0] = vs.GetStageCreateInfo();
5237 shaderStages[1] = fs.GetStageCreateInfo();
5238
5239 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5240 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5241
5242 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5243 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5244 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5245
5246 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5247 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5248 rs_ci.rasterizerDiscardEnable = true;
5249 rs_ci.lineWidth = 1.0f;
5250
5251 VkPipelineColorBlendAttachmentState att = {};
5252 att.blendEnable = VK_FALSE;
5253 att.colorWriteMask = 0xf;
5254
5255 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5256 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5257 cb_ci.attachmentCount = 1;
5258 cb_ci.pAttachments = &att;
5259
5260 VkGraphicsPipelineCreateInfo gp_ci = {};
5261 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5262 gp_ci.stageCount = 2;
5263 gp_ci.pStages = shaderStages;
5264 gp_ci.pVertexInputState = &vi_ci;
5265 gp_ci.pInputAssemblyState = &ia_ci;
5266 gp_ci.pViewportState = &vp_state_ci;
5267 gp_ci.pRasterizationState = &rs_ci;
5268 gp_ci.pColorBlendState = &cb_ci;
5269 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5270 gp_ci.layout = pipeline_layout;
5271 gp_ci.renderPass = rp;
5272
5273 VkPipelineCacheCreateInfo pc_ci = {};
5274 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5275
5276 VkPipeline pipeline;
5277 VkPipelineCache pipe_cache;
5278 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5279 ASSERT_VK_SUCCESS(err);
5280
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005281 m_errorMonitor->SetUnexpectedError(
5282 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5283 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005284 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5285 ASSERT_VK_SUCCESS(err);
5286 // Bind pipeline to cmd buffer, will also bind renderpass
5287 m_commandBuffer->BeginCommandBuffer();
5288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5289 m_commandBuffer->EndCommandBuffer();
5290
5291 VkSubmitInfo submit_info = {};
5292 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5293 submit_info.commandBufferCount = 1;
5294 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5295 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5296
5297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5298 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5299 m_errorMonitor->VerifyFound();
5300
5301 // Wait for queue to complete so we can safely destroy everything
5302 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005303 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5304 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005305 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5306 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5307 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5308 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5309}
5310
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005311TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005312 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005313 ASSERT_NO_FATAL_FAILURE(InitState());
5314
5315 VkImage image;
5316 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5317 VkImageCreateInfo image_create_info = {};
5318 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5319 image_create_info.pNext = NULL;
5320 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5321 image_create_info.format = tex_format;
5322 image_create_info.extent.width = 32;
5323 image_create_info.extent.height = 32;
5324 image_create_info.extent.depth = 1;
5325 image_create_info.mipLevels = 1;
5326 image_create_info.arrayLayers = 1;
5327 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005329 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005330 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005331 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005332 ASSERT_VK_SUCCESS(err);
5333 // Have to bind memory to image before recording cmd in cmd buffer using it
5334 VkMemoryRequirements mem_reqs;
5335 VkDeviceMemory image_mem;
5336 bool pass;
5337 VkMemoryAllocateInfo mem_alloc = {};
5338 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5339 mem_alloc.pNext = NULL;
5340 mem_alloc.memoryTypeIndex = 0;
5341 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5342 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005343 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005344 ASSERT_TRUE(pass);
5345 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5346 ASSERT_VK_SUCCESS(err);
5347
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005348 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005350 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005351
5352 m_commandBuffer->BeginCommandBuffer();
5353 VkClearColorValue ccv;
5354 ccv.float32[0] = 1.0f;
5355 ccv.float32[1] = 1.0f;
5356 ccv.float32[2] = 1.0f;
5357 ccv.float32[3] = 1.0f;
5358 VkImageSubresourceRange isr = {};
5359 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5360 isr.baseArrayLayer = 0;
5361 isr.baseMipLevel = 0;
5362 isr.layerCount = 1;
5363 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005364 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005365 m_commandBuffer->EndCommandBuffer();
5366
5367 m_errorMonitor->VerifyFound();
5368 vkDestroyImage(m_device->device(), image, NULL);
5369 vkFreeMemory(m_device->device(), image_mem, nullptr);
5370}
5371
5372TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005373 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005374 ASSERT_NO_FATAL_FAILURE(InitState());
5375
5376 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005377 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 -06005378 VK_IMAGE_TILING_OPTIMAL, 0);
5379 ASSERT_TRUE(image.initialized());
5380
5381 VkBuffer buffer;
5382 VkDeviceMemory mem;
5383 VkMemoryRequirements mem_reqs;
5384
5385 VkBufferCreateInfo buf_info = {};
5386 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005387 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005388 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005389 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5390 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5391 ASSERT_VK_SUCCESS(err);
5392
5393 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5394
5395 VkMemoryAllocateInfo alloc_info = {};
5396 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005397 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005398 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005399 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 -06005400 if (!pass) {
5401 vkDestroyBuffer(m_device->device(), buffer, NULL);
5402 return;
5403 }
5404 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5405 ASSERT_VK_SUCCESS(err);
5406
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005407 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005409 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005410 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005411 region.bufferRowLength = 16;
5412 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005413 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5414
5415 region.imageSubresource.layerCount = 1;
5416 region.imageExtent.height = 4;
5417 region.imageExtent.width = 4;
5418 region.imageExtent.depth = 1;
5419 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5421 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005422 m_commandBuffer->EndCommandBuffer();
5423
5424 m_errorMonitor->VerifyFound();
5425
5426 vkDestroyBuffer(m_device->device(), buffer, NULL);
5427 vkFreeMemory(m_device->handle(), mem, NULL);
5428}
5429
Tobin Ehlis85940f52016-07-07 16:57:21 -06005430TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005431 TEST_DESCRIPTION(
5432 "Attempt to draw with a command buffer that is invalid "
5433 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005434 ASSERT_NO_FATAL_FAILURE(InitState());
5435
5436 VkEvent event;
5437 VkEventCreateInfo evci = {};
5438 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5439 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5440 ASSERT_VK_SUCCESS(result);
5441
5442 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005443 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005444 m_commandBuffer->EndCommandBuffer();
5445
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005447 // Destroy event dependency prior to submit to cause ERROR
5448 vkDestroyEvent(m_device->device(), event, NULL);
5449
5450 VkSubmitInfo submit_info = {};
5451 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5452 submit_info.commandBufferCount = 1;
5453 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5454 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5455
5456 m_errorMonitor->VerifyFound();
5457}
5458
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005459TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005460 TEST_DESCRIPTION(
5461 "Attempt to draw with a command buffer that is invalid "
5462 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005463 ASSERT_NO_FATAL_FAILURE(InitState());
5464
5465 VkQueryPool query_pool;
5466 VkQueryPoolCreateInfo qpci{};
5467 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5468 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5469 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005470 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005471 ASSERT_VK_SUCCESS(result);
5472
5473 m_commandBuffer->BeginCommandBuffer();
5474 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5475 m_commandBuffer->EndCommandBuffer();
5476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005478 // Destroy query pool dependency prior to submit to cause ERROR
5479 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5480
5481 VkSubmitInfo submit_info = {};
5482 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5483 submit_info.commandBufferCount = 1;
5484 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5485 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5486
5487 m_errorMonitor->VerifyFound();
5488}
5489
Tobin Ehlis24130d92016-07-08 15:50:53 -06005490TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005491 TEST_DESCRIPTION(
5492 "Attempt to draw with a command buffer that is invalid "
5493 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005494 ASSERT_NO_FATAL_FAILURE(InitState());
5495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5496
5497 VkResult err;
5498
5499 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5500 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5501
5502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005504 ASSERT_VK_SUCCESS(err);
5505
5506 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5507 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5508 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005509 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005510 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005511 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005512 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005513 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005514
5515 VkPipelineShaderStageCreateInfo shaderStages[2];
5516 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5517
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005519 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 -06005520 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005521 shaderStages[0] = vs.GetStageCreateInfo();
5522 shaderStages[1] = fs.GetStageCreateInfo();
5523
5524 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5525 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5526
5527 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5528 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5529 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5530
5531 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5532 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005533 rs_ci.rasterizerDiscardEnable = true;
5534 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005535
5536 VkPipelineColorBlendAttachmentState att = {};
5537 att.blendEnable = VK_FALSE;
5538 att.colorWriteMask = 0xf;
5539
5540 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5541 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5542 cb_ci.attachmentCount = 1;
5543 cb_ci.pAttachments = &att;
5544
5545 VkGraphicsPipelineCreateInfo gp_ci = {};
5546 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5547 gp_ci.stageCount = 2;
5548 gp_ci.pStages = shaderStages;
5549 gp_ci.pVertexInputState = &vi_ci;
5550 gp_ci.pInputAssemblyState = &ia_ci;
5551 gp_ci.pViewportState = &vp_state_ci;
5552 gp_ci.pRasterizationState = &rs_ci;
5553 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005554 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5555 gp_ci.layout = pipeline_layout;
5556 gp_ci.renderPass = renderPass();
5557
5558 VkPipelineCacheCreateInfo pc_ci = {};
5559 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5560
5561 VkPipeline pipeline;
5562 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005563 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005564 ASSERT_VK_SUCCESS(err);
5565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005566 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005567 ASSERT_VK_SUCCESS(err);
5568
5569 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005570 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005571 m_commandBuffer->EndCommandBuffer();
5572 // Now destroy pipeline in order to cause error when submitting
5573 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005576
5577 VkSubmitInfo submit_info = {};
5578 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5579 submit_info.commandBufferCount = 1;
5580 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5581 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5582
5583 m_errorMonitor->VerifyFound();
5584 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5585 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5586}
5587
Tobin Ehlis31289162016-08-17 14:57:58 -06005588TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005589 TEST_DESCRIPTION(
5590 "Attempt to draw with a command buffer that is invalid "
5591 "due to a bound descriptor set with a buffer dependency "
5592 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005593 ASSERT_NO_FATAL_FAILURE(InitState());
5594 ASSERT_NO_FATAL_FAILURE(InitViewport());
5595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5596
5597 VkDescriptorPoolSize ds_type_count = {};
5598 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5599 ds_type_count.descriptorCount = 1;
5600
5601 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5602 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5603 ds_pool_ci.pNext = NULL;
5604 ds_pool_ci.maxSets = 1;
5605 ds_pool_ci.poolSizeCount = 1;
5606 ds_pool_ci.pPoolSizes = &ds_type_count;
5607
5608 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005609 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005610 ASSERT_VK_SUCCESS(err);
5611
5612 VkDescriptorSetLayoutBinding dsl_binding = {};
5613 dsl_binding.binding = 0;
5614 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5615 dsl_binding.descriptorCount = 1;
5616 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5617 dsl_binding.pImmutableSamplers = NULL;
5618
5619 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5620 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5621 ds_layout_ci.pNext = NULL;
5622 ds_layout_ci.bindingCount = 1;
5623 ds_layout_ci.pBindings = &dsl_binding;
5624 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005625 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005626 ASSERT_VK_SUCCESS(err);
5627
5628 VkDescriptorSet descriptorSet;
5629 VkDescriptorSetAllocateInfo alloc_info = {};
5630 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5631 alloc_info.descriptorSetCount = 1;
5632 alloc_info.descriptorPool = ds_pool;
5633 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005634 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005635 ASSERT_VK_SUCCESS(err);
5636
5637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5639 pipeline_layout_ci.pNext = NULL;
5640 pipeline_layout_ci.setLayoutCount = 1;
5641 pipeline_layout_ci.pSetLayouts = &ds_layout;
5642
5643 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005645 ASSERT_VK_SUCCESS(err);
5646
5647 // Create a buffer to update the descriptor with
5648 uint32_t qfi = 0;
5649 VkBufferCreateInfo buffCI = {};
5650 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5651 buffCI.size = 1024;
5652 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5653 buffCI.queueFamilyIndexCount = 1;
5654 buffCI.pQueueFamilyIndices = &qfi;
5655
5656 VkBuffer buffer;
5657 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5658 ASSERT_VK_SUCCESS(err);
5659 // Allocate memory and bind to buffer so we can make it to the appropriate
5660 // error
5661 VkMemoryAllocateInfo mem_alloc = {};
5662 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5663 mem_alloc.pNext = NULL;
5664 mem_alloc.allocationSize = 1024;
5665 mem_alloc.memoryTypeIndex = 0;
5666
5667 VkMemoryRequirements memReqs;
5668 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005669 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005670 if (!pass) {
5671 vkDestroyBuffer(m_device->device(), buffer, NULL);
5672 return;
5673 }
5674
5675 VkDeviceMemory mem;
5676 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5677 ASSERT_VK_SUCCESS(err);
5678 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5679 ASSERT_VK_SUCCESS(err);
5680 // Correctly update descriptor to avoid "NOT_UPDATED" error
5681 VkDescriptorBufferInfo buffInfo = {};
5682 buffInfo.buffer = buffer;
5683 buffInfo.offset = 0;
5684 buffInfo.range = 1024;
5685
5686 VkWriteDescriptorSet descriptor_write;
5687 memset(&descriptor_write, 0, sizeof(descriptor_write));
5688 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5689 descriptor_write.dstSet = descriptorSet;
5690 descriptor_write.dstBinding = 0;
5691 descriptor_write.descriptorCount = 1;
5692 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5693 descriptor_write.pBufferInfo = &buffInfo;
5694
5695 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5696
5697 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005698 char const *vsSource =
5699 "#version 450\n"
5700 "\n"
5701 "out gl_PerVertex { \n"
5702 " vec4 gl_Position;\n"
5703 "};\n"
5704 "void main(){\n"
5705 " gl_Position = vec4(1);\n"
5706 "}\n";
5707 char const *fsSource =
5708 "#version 450\n"
5709 "\n"
5710 "layout(location=0) out vec4 x;\n"
5711 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5712 "void main(){\n"
5713 " x = vec4(bar.y);\n"
5714 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5717 VkPipelineObj pipe(m_device);
5718 pipe.AddShader(&vs);
5719 pipe.AddShader(&fs);
5720 pipe.AddColorAttachment();
5721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5722
Tony Barbour552f6c02016-12-21 14:34:07 -07005723 m_commandBuffer->BeginCommandBuffer();
5724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005725 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5726 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5727 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005728
5729 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5730 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5731
Tobin Ehlis31289162016-08-17 14:57:58 -06005732 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005733 m_commandBuffer->EndRenderPass();
5734 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005736 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5737 vkDestroyBuffer(m_device->device(), buffer, NULL);
5738 // Attempt to submit cmd buffer
5739 VkSubmitInfo submit_info = {};
5740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5741 submit_info.commandBufferCount = 1;
5742 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5743 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5744 m_errorMonitor->VerifyFound();
5745 // Cleanup
5746 vkFreeMemory(m_device->device(), mem, NULL);
5747
5748 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5749 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5751}
5752
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005753TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005754 TEST_DESCRIPTION(
5755 "Attempt to draw with a command buffer that is invalid "
5756 "due to a bound descriptor sets with a combined image "
5757 "sampler having their image, sampler, and descriptor set "
5758 "each respectively destroyed and then attempting to "
5759 "submit associated cmd buffers. Attempt to destroy a "
5760 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005761 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005762 ASSERT_NO_FATAL_FAILURE(InitViewport());
5763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5764
5765 VkDescriptorPoolSize ds_type_count = {};
5766 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5767 ds_type_count.descriptorCount = 1;
5768
5769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5771 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005772 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005773 ds_pool_ci.maxSets = 1;
5774 ds_pool_ci.poolSizeCount = 1;
5775 ds_pool_ci.pPoolSizes = &ds_type_count;
5776
5777 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkDescriptorSetLayoutBinding dsl_binding = {};
5782 dsl_binding.binding = 0;
5783 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5784 dsl_binding.descriptorCount = 1;
5785 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5786 dsl_binding.pImmutableSamplers = NULL;
5787
5788 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5789 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5790 ds_layout_ci.pNext = NULL;
5791 ds_layout_ci.bindingCount = 1;
5792 ds_layout_ci.pBindings = &dsl_binding;
5793 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005795 ASSERT_VK_SUCCESS(err);
5796
5797 VkDescriptorSet descriptorSet;
5798 VkDescriptorSetAllocateInfo alloc_info = {};
5799 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5800 alloc_info.descriptorSetCount = 1;
5801 alloc_info.descriptorPool = ds_pool;
5802 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005803 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005804 ASSERT_VK_SUCCESS(err);
5805
5806 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5807 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5808 pipeline_layout_ci.pNext = NULL;
5809 pipeline_layout_ci.setLayoutCount = 1;
5810 pipeline_layout_ci.pSetLayouts = &ds_layout;
5811
5812 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005813 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005814 ASSERT_VK_SUCCESS(err);
5815
5816 // Create images to update the descriptor with
5817 VkImage image;
5818 VkImage image2;
5819 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5820 const int32_t tex_width = 32;
5821 const int32_t tex_height = 32;
5822 VkImageCreateInfo image_create_info = {};
5823 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5824 image_create_info.pNext = NULL;
5825 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5826 image_create_info.format = tex_format;
5827 image_create_info.extent.width = tex_width;
5828 image_create_info.extent.height = tex_height;
5829 image_create_info.extent.depth = 1;
5830 image_create_info.mipLevels = 1;
5831 image_create_info.arrayLayers = 1;
5832 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5833 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5834 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5835 image_create_info.flags = 0;
5836 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5837 ASSERT_VK_SUCCESS(err);
5838 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5839 ASSERT_VK_SUCCESS(err);
5840
5841 VkMemoryRequirements memory_reqs;
5842 VkDeviceMemory image_memory;
5843 bool pass;
5844 VkMemoryAllocateInfo memory_info = {};
5845 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5846 memory_info.pNext = NULL;
5847 memory_info.allocationSize = 0;
5848 memory_info.memoryTypeIndex = 0;
5849 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5850 // Allocate enough memory for both images
5851 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005852 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005853 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005854 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005855 ASSERT_VK_SUCCESS(err);
5856 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5857 ASSERT_VK_SUCCESS(err);
5858 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005860 ASSERT_VK_SUCCESS(err);
5861
5862 VkImageViewCreateInfo image_view_create_info = {};
5863 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5864 image_view_create_info.image = image;
5865 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5866 image_view_create_info.format = tex_format;
5867 image_view_create_info.subresourceRange.layerCount = 1;
5868 image_view_create_info.subresourceRange.baseMipLevel = 0;
5869 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005870 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005871
5872 VkImageView view;
5873 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005874 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005875 ASSERT_VK_SUCCESS(err);
5876 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005877 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005878 ASSERT_VK_SUCCESS(err);
5879 // Create Samplers
5880 VkSamplerCreateInfo sampler_ci = {};
5881 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5882 sampler_ci.pNext = NULL;
5883 sampler_ci.magFilter = VK_FILTER_NEAREST;
5884 sampler_ci.minFilter = VK_FILTER_NEAREST;
5885 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5886 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5887 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5888 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5889 sampler_ci.mipLodBias = 1.0;
5890 sampler_ci.anisotropyEnable = VK_FALSE;
5891 sampler_ci.maxAnisotropy = 1;
5892 sampler_ci.compareEnable = VK_FALSE;
5893 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5894 sampler_ci.minLod = 1.0;
5895 sampler_ci.maxLod = 1.0;
5896 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5897 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5898 VkSampler sampler;
5899 VkSampler sampler2;
5900 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5901 ASSERT_VK_SUCCESS(err);
5902 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5903 ASSERT_VK_SUCCESS(err);
5904 // Update descriptor with image and sampler
5905 VkDescriptorImageInfo img_info = {};
5906 img_info.sampler = sampler;
5907 img_info.imageView = view;
5908 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5909
5910 VkWriteDescriptorSet descriptor_write;
5911 memset(&descriptor_write, 0, sizeof(descriptor_write));
5912 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5913 descriptor_write.dstSet = descriptorSet;
5914 descriptor_write.dstBinding = 0;
5915 descriptor_write.descriptorCount = 1;
5916 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5917 descriptor_write.pImageInfo = &img_info;
5918
5919 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5920
5921 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005922 char const *vsSource =
5923 "#version 450\n"
5924 "\n"
5925 "out gl_PerVertex { \n"
5926 " vec4 gl_Position;\n"
5927 "};\n"
5928 "void main(){\n"
5929 " gl_Position = vec4(1);\n"
5930 "}\n";
5931 char const *fsSource =
5932 "#version 450\n"
5933 "\n"
5934 "layout(set=0, binding=0) uniform sampler2D s;\n"
5935 "layout(location=0) out vec4 x;\n"
5936 "void main(){\n"
5937 " x = texture(s, vec2(1));\n"
5938 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005939 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5940 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5941 VkPipelineObj pipe(m_device);
5942 pipe.AddShader(&vs);
5943 pipe.AddShader(&fs);
5944 pipe.AddColorAttachment();
5945 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5946
5947 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005949 m_commandBuffer->BeginCommandBuffer();
5950 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005951 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5952 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5953 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005954 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5955 VkRect2D scissor = {{0, 0}, {16, 16}};
5956 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5957 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005958 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005959 m_commandBuffer->EndRenderPass();
5960 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005961 // Destroy sampler invalidates the cmd buffer, causing error on submit
5962 vkDestroySampler(m_device->device(), sampler, NULL);
5963 // Attempt to submit cmd buffer
5964 VkSubmitInfo submit_info = {};
5965 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5966 submit_info.commandBufferCount = 1;
5967 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5968 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5969 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005970
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005971 // Now re-update descriptor with valid sampler and delete image
5972 img_info.sampler = sampler2;
5973 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005974
5975 VkCommandBufferBeginInfo info = {};
5976 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5977 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005980 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005981 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005982 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5983 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5984 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005985 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5986 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005987 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005988 m_commandBuffer->EndRenderPass();
5989 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005990 // Destroy image invalidates the cmd buffer, causing error on submit
5991 vkDestroyImage(m_device->device(), image, NULL);
5992 // Attempt to submit cmd buffer
5993 submit_info = {};
5994 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5995 submit_info.commandBufferCount = 1;
5996 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5997 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5998 m_errorMonitor->VerifyFound();
5999 // Now update descriptor to be valid, but then free descriptor
6000 img_info.imageView = view2;
6001 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006002 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006003 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006004 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6005 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6006 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006007 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6008 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006009 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006010 m_commandBuffer->EndRenderPass();
6011 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006012 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006013
6014 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006016 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006017 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006018
6019 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006020 // 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 -07006021 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006022 m_errorMonitor->SetUnexpectedError(
6023 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6024 "either be a valid handle or VK_NULL_HANDLE");
6025 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006026 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6027
6028 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006029 submit_info = {};
6030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6031 submit_info.commandBufferCount = 1;
6032 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006034 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6035 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006036
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006037 // Cleanup
6038 vkFreeMemory(m_device->device(), image_memory, NULL);
6039 vkDestroySampler(m_device->device(), sampler2, NULL);
6040 vkDestroyImage(m_device->device(), image2, NULL);
6041 vkDestroyImageView(m_device->device(), view, NULL);
6042 vkDestroyImageView(m_device->device(), view2, NULL);
6043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6045 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6046}
6047
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006048TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6049 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6050 ASSERT_NO_FATAL_FAILURE(InitState());
6051 ASSERT_NO_FATAL_FAILURE(InitViewport());
6052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6053
6054 VkDescriptorPoolSize ds_type_count = {};
6055 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6056 ds_type_count.descriptorCount = 1;
6057
6058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6060 ds_pool_ci.pNext = NULL;
6061 ds_pool_ci.maxSets = 1;
6062 ds_pool_ci.poolSizeCount = 1;
6063 ds_pool_ci.pPoolSizes = &ds_type_count;
6064
6065 VkDescriptorPool ds_pool;
6066 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6067 ASSERT_VK_SUCCESS(err);
6068
6069 VkDescriptorSetLayoutBinding dsl_binding = {};
6070 dsl_binding.binding = 0;
6071 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6072 dsl_binding.descriptorCount = 1;
6073 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6074 dsl_binding.pImmutableSamplers = NULL;
6075
6076 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6077 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6078 ds_layout_ci.pNext = NULL;
6079 ds_layout_ci.bindingCount = 1;
6080 ds_layout_ci.pBindings = &dsl_binding;
6081 VkDescriptorSetLayout ds_layout;
6082 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6083 ASSERT_VK_SUCCESS(err);
6084
6085 VkDescriptorSet descriptor_set;
6086 VkDescriptorSetAllocateInfo alloc_info = {};
6087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6088 alloc_info.descriptorSetCount = 1;
6089 alloc_info.descriptorPool = ds_pool;
6090 alloc_info.pSetLayouts = &ds_layout;
6091 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6092 ASSERT_VK_SUCCESS(err);
6093
6094 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6095 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6096 pipeline_layout_ci.pNext = NULL;
6097 pipeline_layout_ci.setLayoutCount = 1;
6098 pipeline_layout_ci.pSetLayouts = &ds_layout;
6099
6100 VkPipelineLayout pipeline_layout;
6101 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6102 ASSERT_VK_SUCCESS(err);
6103
6104 // Create image to update the descriptor with
6105 VkImageObj image(m_device);
6106 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6107 ASSERT_TRUE(image.initialized());
6108
6109 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6110 // Create Sampler
6111 VkSamplerCreateInfo sampler_ci = {};
6112 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6113 sampler_ci.pNext = NULL;
6114 sampler_ci.magFilter = VK_FILTER_NEAREST;
6115 sampler_ci.minFilter = VK_FILTER_NEAREST;
6116 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6117 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6118 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6119 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6120 sampler_ci.mipLodBias = 1.0;
6121 sampler_ci.anisotropyEnable = VK_FALSE;
6122 sampler_ci.maxAnisotropy = 1;
6123 sampler_ci.compareEnable = VK_FALSE;
6124 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6125 sampler_ci.minLod = 1.0;
6126 sampler_ci.maxLod = 1.0;
6127 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6128 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6129 VkSampler sampler;
6130 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6131 ASSERT_VK_SUCCESS(err);
6132 // Update descriptor with image and sampler
6133 VkDescriptorImageInfo img_info = {};
6134 img_info.sampler = sampler;
6135 img_info.imageView = view;
6136 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6137
6138 VkWriteDescriptorSet descriptor_write;
6139 memset(&descriptor_write, 0, sizeof(descriptor_write));
6140 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6141 descriptor_write.dstSet = descriptor_set;
6142 descriptor_write.dstBinding = 0;
6143 descriptor_write.descriptorCount = 1;
6144 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6145 descriptor_write.pImageInfo = &img_info;
6146
6147 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6148
6149 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006150 char const *vsSource =
6151 "#version 450\n"
6152 "\n"
6153 "out gl_PerVertex { \n"
6154 " vec4 gl_Position;\n"
6155 "};\n"
6156 "void main(){\n"
6157 " gl_Position = vec4(1);\n"
6158 "}\n";
6159 char const *fsSource =
6160 "#version 450\n"
6161 "\n"
6162 "layout(set=0, binding=0) uniform sampler2D s;\n"
6163 "layout(location=0) out vec4 x;\n"
6164 "void main(){\n"
6165 " x = texture(s, vec2(1));\n"
6166 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006167 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6168 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6169 VkPipelineObj pipe(m_device);
6170 pipe.AddShader(&vs);
6171 pipe.AddShader(&fs);
6172 pipe.AddColorAttachment();
6173 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6174
Tony Barbour552f6c02016-12-21 14:34:07 -07006175 m_commandBuffer->BeginCommandBuffer();
6176 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006177 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6178 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6179 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006180
6181 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6182 VkRect2D scissor = {{0, 0}, {16, 16}};
6183 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6184 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6185
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006186 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006187 m_commandBuffer->EndRenderPass();
6188 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006189 // Submit cmd buffer to put pool in-flight
6190 VkSubmitInfo submit_info = {};
6191 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6192 submit_info.commandBufferCount = 1;
6193 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6194 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6195 // Destroy pool while in-flight, causing error
6196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6197 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6198 m_errorMonitor->VerifyFound();
6199 vkQueueWaitIdle(m_device->m_queue);
6200 // Cleanup
6201 vkDestroySampler(m_device->device(), sampler, NULL);
6202 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006204 m_errorMonitor->SetUnexpectedError(
6205 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6206 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006207 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006208 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006209}
6210
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006211TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6212 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6213 ASSERT_NO_FATAL_FAILURE(InitState());
6214 ASSERT_NO_FATAL_FAILURE(InitViewport());
6215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6216
6217 VkDescriptorPoolSize ds_type_count = {};
6218 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6219 ds_type_count.descriptorCount = 1;
6220
6221 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6222 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6223 ds_pool_ci.pNext = NULL;
6224 ds_pool_ci.maxSets = 1;
6225 ds_pool_ci.poolSizeCount = 1;
6226 ds_pool_ci.pPoolSizes = &ds_type_count;
6227
6228 VkDescriptorPool ds_pool;
6229 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6230 ASSERT_VK_SUCCESS(err);
6231
6232 VkDescriptorSetLayoutBinding dsl_binding = {};
6233 dsl_binding.binding = 0;
6234 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6235 dsl_binding.descriptorCount = 1;
6236 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6237 dsl_binding.pImmutableSamplers = NULL;
6238
6239 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6240 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6241 ds_layout_ci.pNext = NULL;
6242 ds_layout_ci.bindingCount = 1;
6243 ds_layout_ci.pBindings = &dsl_binding;
6244 VkDescriptorSetLayout ds_layout;
6245 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6246 ASSERT_VK_SUCCESS(err);
6247
6248 VkDescriptorSet descriptorSet;
6249 VkDescriptorSetAllocateInfo alloc_info = {};
6250 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6251 alloc_info.descriptorSetCount = 1;
6252 alloc_info.descriptorPool = ds_pool;
6253 alloc_info.pSetLayouts = &ds_layout;
6254 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6255 ASSERT_VK_SUCCESS(err);
6256
6257 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6258 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6259 pipeline_layout_ci.pNext = NULL;
6260 pipeline_layout_ci.setLayoutCount = 1;
6261 pipeline_layout_ci.pSetLayouts = &ds_layout;
6262
6263 VkPipelineLayout pipeline_layout;
6264 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6265 ASSERT_VK_SUCCESS(err);
6266
6267 // Create images to update the descriptor with
6268 VkImage image;
6269 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6270 const int32_t tex_width = 32;
6271 const int32_t tex_height = 32;
6272 VkImageCreateInfo image_create_info = {};
6273 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6274 image_create_info.pNext = NULL;
6275 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6276 image_create_info.format = tex_format;
6277 image_create_info.extent.width = tex_width;
6278 image_create_info.extent.height = tex_height;
6279 image_create_info.extent.depth = 1;
6280 image_create_info.mipLevels = 1;
6281 image_create_info.arrayLayers = 1;
6282 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6283 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6284 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6285 image_create_info.flags = 0;
6286 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6287 ASSERT_VK_SUCCESS(err);
6288 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6289 VkMemoryRequirements memory_reqs;
6290 VkDeviceMemory image_memory;
6291 bool pass;
6292 VkMemoryAllocateInfo memory_info = {};
6293 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6294 memory_info.pNext = NULL;
6295 memory_info.allocationSize = 0;
6296 memory_info.memoryTypeIndex = 0;
6297 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6298 // Allocate enough memory for image
6299 memory_info.allocationSize = memory_reqs.size;
6300 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6301 ASSERT_TRUE(pass);
6302 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6303 ASSERT_VK_SUCCESS(err);
6304 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6305 ASSERT_VK_SUCCESS(err);
6306
6307 VkImageViewCreateInfo image_view_create_info = {};
6308 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6309 image_view_create_info.image = image;
6310 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6311 image_view_create_info.format = tex_format;
6312 image_view_create_info.subresourceRange.layerCount = 1;
6313 image_view_create_info.subresourceRange.baseMipLevel = 0;
6314 image_view_create_info.subresourceRange.levelCount = 1;
6315 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6316
6317 VkImageView view;
6318 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6319 ASSERT_VK_SUCCESS(err);
6320 // Create Samplers
6321 VkSamplerCreateInfo sampler_ci = {};
6322 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6323 sampler_ci.pNext = NULL;
6324 sampler_ci.magFilter = VK_FILTER_NEAREST;
6325 sampler_ci.minFilter = VK_FILTER_NEAREST;
6326 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6327 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6328 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6329 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6330 sampler_ci.mipLodBias = 1.0;
6331 sampler_ci.anisotropyEnable = VK_FALSE;
6332 sampler_ci.maxAnisotropy = 1;
6333 sampler_ci.compareEnable = VK_FALSE;
6334 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6335 sampler_ci.minLod = 1.0;
6336 sampler_ci.maxLod = 1.0;
6337 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6338 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6339 VkSampler sampler;
6340 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6341 ASSERT_VK_SUCCESS(err);
6342 // Update descriptor with image and sampler
6343 VkDescriptorImageInfo img_info = {};
6344 img_info.sampler = sampler;
6345 img_info.imageView = view;
6346 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6347
6348 VkWriteDescriptorSet descriptor_write;
6349 memset(&descriptor_write, 0, sizeof(descriptor_write));
6350 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6351 descriptor_write.dstSet = descriptorSet;
6352 descriptor_write.dstBinding = 0;
6353 descriptor_write.descriptorCount = 1;
6354 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6355 descriptor_write.pImageInfo = &img_info;
6356 // Break memory binding and attempt update
6357 vkFreeMemory(m_device->device(), image_memory, nullptr);
6358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006359 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6361 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6363 m_errorMonitor->VerifyFound();
6364 // Cleanup
6365 vkDestroyImage(m_device->device(), image, NULL);
6366 vkDestroySampler(m_device->device(), sampler, NULL);
6367 vkDestroyImageView(m_device->device(), view, NULL);
6368 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6369 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6370 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6371}
6372
Karl Schultz6addd812016-02-02 17:17:23 -07006373TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006374 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6375 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006376 // Create a valid cmd buffer
6377 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006378 uint64_t fake_pipeline_handle = 0xbaad6001;
6379 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006380 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6382
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006384 m_commandBuffer->BeginCommandBuffer();
6385 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006387 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006388
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006389 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006390 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 -06006391 Draw(1, 0, 0, 0);
6392 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006393
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006394 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 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 -07006396 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006397 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6398 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006399}
6400
Karl Schultz6addd812016-02-02 17:17:23 -07006401TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006402 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006403 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006406
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006407 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006408 ASSERT_NO_FATAL_FAILURE(InitViewport());
6409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006410 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006411 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6412 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006413
6414 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006415 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6416 ds_pool_ci.pNext = NULL;
6417 ds_pool_ci.maxSets = 1;
6418 ds_pool_ci.poolSizeCount = 1;
6419 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006420
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006421 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006422 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006423 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006424
Tony Barboureb254902015-07-15 12:50:33 -06006425 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006426 dsl_binding.binding = 0;
6427 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6428 dsl_binding.descriptorCount = 1;
6429 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6430 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006431
Tony Barboureb254902015-07-15 12:50:33 -06006432 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006433 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6434 ds_layout_ci.pNext = NULL;
6435 ds_layout_ci.bindingCount = 1;
6436 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006437 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006439 ASSERT_VK_SUCCESS(err);
6440
6441 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006442 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006443 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006444 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006445 alloc_info.descriptorPool = ds_pool;
6446 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006447 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006448 ASSERT_VK_SUCCESS(err);
6449
Tony Barboureb254902015-07-15 12:50:33 -06006450 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006451 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6452 pipeline_layout_ci.pNext = NULL;
6453 pipeline_layout_ci.setLayoutCount = 1;
6454 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006455
6456 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006457 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006458 ASSERT_VK_SUCCESS(err);
6459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006461 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006462 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006463 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006464
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006465 VkPipelineObj pipe(m_device);
6466 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006467 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006468 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006469 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006470
Tony Barbour552f6c02016-12-21 14:34:07 -07006471 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006472 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6473 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6474 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006475
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006476 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006477
Chia-I Wuf7458c52015-10-26 21:10:41 +08006478 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6479 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6480 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006481}
6482
Karl Schultz6addd812016-02-02 17:17:23 -07006483TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006484 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006485 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006486
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006488
6489 ASSERT_NO_FATAL_FAILURE(InitState());
6490 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006491 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6492 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006493
6494 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006495 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6496 ds_pool_ci.pNext = NULL;
6497 ds_pool_ci.maxSets = 1;
6498 ds_pool_ci.poolSizeCount = 1;
6499 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006500
6501 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006502 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006503 ASSERT_VK_SUCCESS(err);
6504
6505 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006506 dsl_binding.binding = 0;
6507 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6508 dsl_binding.descriptorCount = 1;
6509 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6510 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006511
6512 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006513 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6514 ds_layout_ci.pNext = NULL;
6515 ds_layout_ci.bindingCount = 1;
6516 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006517 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006518 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006519 ASSERT_VK_SUCCESS(err);
6520
6521 VkDescriptorSet descriptorSet;
6522 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006523 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006524 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006525 alloc_info.descriptorPool = ds_pool;
6526 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006528 ASSERT_VK_SUCCESS(err);
6529
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006530 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006531 VkWriteDescriptorSet descriptor_write;
6532 memset(&descriptor_write, 0, sizeof(descriptor_write));
6533 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6534 descriptor_write.dstSet = descriptorSet;
6535 descriptor_write.dstBinding = 0;
6536 descriptor_write.descriptorCount = 1;
6537 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6538 descriptor_write.pTexelBufferView = &view;
6539
6540 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006542 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006543
6544 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6545 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6546}
6547
Mark Youngd339ba32016-05-30 13:28:35 -06006548TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006549 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 -06006550
6551 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006553 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006554
6555 ASSERT_NO_FATAL_FAILURE(InitState());
6556
6557 // Create a buffer with no bound memory and then attempt to create
6558 // a buffer view.
6559 VkBufferCreateInfo buff_ci = {};
6560 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006561 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006562 buff_ci.size = 256;
6563 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6564 VkBuffer buffer;
6565 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6566 ASSERT_VK_SUCCESS(err);
6567
6568 VkBufferViewCreateInfo buff_view_ci = {};
6569 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6570 buff_view_ci.buffer = buffer;
6571 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6572 buff_view_ci.range = VK_WHOLE_SIZE;
6573 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006574 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006575
6576 m_errorMonitor->VerifyFound();
6577 vkDestroyBuffer(m_device->device(), buffer, NULL);
6578 // If last error is success, it still created the view, so delete it.
6579 if (err == VK_SUCCESS) {
6580 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6581 }
6582}
6583
Karl Schultz6addd812016-02-02 17:17:23 -07006584TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6585 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6586 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006587 // 1. No dynamicOffset supplied
6588 // 2. Too many dynamicOffsets supplied
6589 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006590 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6592 " requires 1 dynamicOffsets, but only "
6593 "0 dynamicOffsets are left in "
6594 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006595
6596 ASSERT_NO_FATAL_FAILURE(InitState());
6597 ASSERT_NO_FATAL_FAILURE(InitViewport());
6598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6599
6600 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006601 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6602 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006603
6604 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006605 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6606 ds_pool_ci.pNext = NULL;
6607 ds_pool_ci.maxSets = 1;
6608 ds_pool_ci.poolSizeCount = 1;
6609 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006610
6611 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006612 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006613 ASSERT_VK_SUCCESS(err);
6614
6615 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006616 dsl_binding.binding = 0;
6617 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6618 dsl_binding.descriptorCount = 1;
6619 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6620 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006621
6622 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006623 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6624 ds_layout_ci.pNext = NULL;
6625 ds_layout_ci.bindingCount = 1;
6626 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006627 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006629 ASSERT_VK_SUCCESS(err);
6630
6631 VkDescriptorSet descriptorSet;
6632 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006633 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006634 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006635 alloc_info.descriptorPool = ds_pool;
6636 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006637 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006638 ASSERT_VK_SUCCESS(err);
6639
6640 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006641 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6642 pipeline_layout_ci.pNext = NULL;
6643 pipeline_layout_ci.setLayoutCount = 1;
6644 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006645
6646 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006647 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006648 ASSERT_VK_SUCCESS(err);
6649
6650 // Create a buffer to update the descriptor with
6651 uint32_t qfi = 0;
6652 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006653 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6654 buffCI.size = 1024;
6655 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6656 buffCI.queueFamilyIndexCount = 1;
6657 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006658
6659 VkBuffer dyub;
6660 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6661 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006662 // Allocate memory and bind to buffer so we can make it to the appropriate
6663 // error
6664 VkMemoryAllocateInfo mem_alloc = {};
6665 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6666 mem_alloc.pNext = NULL;
6667 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006668 mem_alloc.memoryTypeIndex = 0;
6669
6670 VkMemoryRequirements memReqs;
6671 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006672 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006673 if (!pass) {
6674 vkDestroyBuffer(m_device->device(), dyub, NULL);
6675 return;
6676 }
6677
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006678 VkDeviceMemory mem;
6679 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6680 ASSERT_VK_SUCCESS(err);
6681 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6682 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006683 // Correctly update descriptor to avoid "NOT_UPDATED" error
6684 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006685 buffInfo.buffer = dyub;
6686 buffInfo.offset = 0;
6687 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006688
6689 VkWriteDescriptorSet descriptor_write;
6690 memset(&descriptor_write, 0, sizeof(descriptor_write));
6691 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6692 descriptor_write.dstSet = descriptorSet;
6693 descriptor_write.dstBinding = 0;
6694 descriptor_write.descriptorCount = 1;
6695 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6696 descriptor_write.pBufferInfo = &buffInfo;
6697
6698 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6699
Tony Barbour552f6c02016-12-21 14:34:07 -07006700 m_commandBuffer->BeginCommandBuffer();
6701 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006702 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6703 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006704 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006705 uint32_t pDynOff[2] = {512, 756};
6706 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6708 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6709 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6710 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006711 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006712 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6714 " dynamic offset 512 combined with "
6715 "offset 0 and range 1024 that "
6716 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006717 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006718 char const *vsSource =
6719 "#version 450\n"
6720 "\n"
6721 "out gl_PerVertex { \n"
6722 " vec4 gl_Position;\n"
6723 "};\n"
6724 "void main(){\n"
6725 " gl_Position = vec4(1);\n"
6726 "}\n";
6727 char const *fsSource =
6728 "#version 450\n"
6729 "\n"
6730 "layout(location=0) out vec4 x;\n"
6731 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6732 "void main(){\n"
6733 " x = vec4(bar.y);\n"
6734 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006735 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6736 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6737 VkPipelineObj pipe(m_device);
6738 pipe.AddShader(&vs);
6739 pipe.AddShader(&fs);
6740 pipe.AddColorAttachment();
6741 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6742
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006743 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6744 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6745 VkRect2D scissor = {{0, 0}, {16, 16}};
6746 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006748 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006749 // This update should succeed, but offset size of 512 will overstep buffer
6750 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6752 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006753 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006754 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006755
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006756 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006757 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006758
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006760 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006761 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6762}
6763
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006764TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006765 TEST_DESCRIPTION(
6766 "Attempt to update a descriptor with a non-sparse buffer "
6767 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006768 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006770 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6772 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006773
6774 ASSERT_NO_FATAL_FAILURE(InitState());
6775 ASSERT_NO_FATAL_FAILURE(InitViewport());
6776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6777
6778 VkDescriptorPoolSize ds_type_count = {};
6779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6780 ds_type_count.descriptorCount = 1;
6781
6782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6784 ds_pool_ci.pNext = NULL;
6785 ds_pool_ci.maxSets = 1;
6786 ds_pool_ci.poolSizeCount = 1;
6787 ds_pool_ci.pPoolSizes = &ds_type_count;
6788
6789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006790 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006791 ASSERT_VK_SUCCESS(err);
6792
6793 VkDescriptorSetLayoutBinding dsl_binding = {};
6794 dsl_binding.binding = 0;
6795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6796 dsl_binding.descriptorCount = 1;
6797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6798 dsl_binding.pImmutableSamplers = NULL;
6799
6800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6802 ds_layout_ci.pNext = NULL;
6803 ds_layout_ci.bindingCount = 1;
6804 ds_layout_ci.pBindings = &dsl_binding;
6805 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006806 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006807 ASSERT_VK_SUCCESS(err);
6808
6809 VkDescriptorSet descriptorSet;
6810 VkDescriptorSetAllocateInfo alloc_info = {};
6811 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6812 alloc_info.descriptorSetCount = 1;
6813 alloc_info.descriptorPool = ds_pool;
6814 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006815 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006816 ASSERT_VK_SUCCESS(err);
6817
6818 // Create a buffer to update the descriptor with
6819 uint32_t qfi = 0;
6820 VkBufferCreateInfo buffCI = {};
6821 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6822 buffCI.size = 1024;
6823 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6824 buffCI.queueFamilyIndexCount = 1;
6825 buffCI.pQueueFamilyIndices = &qfi;
6826
6827 VkBuffer dyub;
6828 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6829 ASSERT_VK_SUCCESS(err);
6830
6831 // Attempt to update descriptor without binding memory to it
6832 VkDescriptorBufferInfo buffInfo = {};
6833 buffInfo.buffer = dyub;
6834 buffInfo.offset = 0;
6835 buffInfo.range = 1024;
6836
6837 VkWriteDescriptorSet descriptor_write;
6838 memset(&descriptor_write, 0, sizeof(descriptor_write));
6839 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6840 descriptor_write.dstSet = descriptorSet;
6841 descriptor_write.dstBinding = 0;
6842 descriptor_write.descriptorCount = 1;
6843 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6844 descriptor_write.pBufferInfo = &buffInfo;
6845
6846 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6847 m_errorMonitor->VerifyFound();
6848
6849 vkDestroyBuffer(m_device->device(), dyub, NULL);
6850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6852}
6853
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006854TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006855 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006856 ASSERT_NO_FATAL_FAILURE(InitState());
6857 ASSERT_NO_FATAL_FAILURE(InitViewport());
6858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6859
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006860 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006861 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6864 pipeline_layout_ci.pushConstantRangeCount = 1;
6865 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6866
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006867 //
6868 // Check for invalid push constant ranges in pipeline layouts.
6869 //
6870 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006871 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006872 char const *msg;
6873 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006874
Karl Schultzc81037d2016-05-12 08:11:23 -06006875 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6876 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6877 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6878 "vkCreatePipelineLayout() call has push constants index 0 with "
6879 "size 0."},
6880 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6881 "vkCreatePipelineLayout() call has push constants index 0 with "
6882 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006883 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006884 "vkCreatePipelineLayout() call has push constants index 0 with "
6885 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006886 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006887 "vkCreatePipelineLayout() call has push constants index 0 with "
6888 "size 0."},
6889 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6890 "vkCreatePipelineLayout() call has push constants index 0 with "
6891 "offset 1. Offset must"},
6892 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6893 "vkCreatePipelineLayout() call has push constants index 0 "
6894 "with offset "},
6895 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6896 "vkCreatePipelineLayout() call has push constants "
6897 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006898 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006899 "vkCreatePipelineLayout() call has push constants index 0 "
6900 "with offset "},
6901 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6902 "vkCreatePipelineLayout() call has push "
6903 "constants index 0 with offset "},
6904 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6905 "vkCreatePipelineLayout() call has push "
6906 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006907 }};
6908
6909 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006910 for (const auto &iter : range_tests) {
6911 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6913 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006914 m_errorMonitor->VerifyFound();
6915 if (VK_SUCCESS == err) {
6916 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6917 }
6918 }
6919
6920 // Check for invalid stage flag
6921 pc_range.offset = 0;
6922 pc_range.size = 16;
6923 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006924 m_errorMonitor->SetDesiredFailureMsg(
6925 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6926 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006927 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006928 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006929 if (VK_SUCCESS == err) {
6930 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6931 }
6932
Karl Schultzc59b72d2017-02-24 15:45:05 -07006933 // Check for duplicate stage flags in a list of push constant ranges.
6934 // A shader can only have one push constant block and that block is mapped
6935 // to the push constant range that has that shader's stage flag set.
6936 // The shader's stage flag can only appear once in all the ranges, so the
6937 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06006938 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006939 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006940 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006941 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006942 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07006943 // Overlapping ranges are OK, but a stage flag can appear only once.
6944 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
6945 {
6946 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6947 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6948 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6949 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006950 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07006951 {
6952 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
6953 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
6954 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6955 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
6956 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
6957 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
6958 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6959 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6960 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
6961 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
6962 }},
6963 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6964 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
6965 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6966 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6967 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6968 {
6969 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6970 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6971 }},
6972 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6973 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6974 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6975 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6976 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6977 {
6978 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6979 }},
6980 },
6981 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006982
Karl Schultzc59b72d2017-02-24 15:45:05 -07006983 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006984 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006985 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006987 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006988 m_errorMonitor->VerifyFound();
6989 if (VK_SUCCESS == err) {
6990 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6991 }
6992 }
6993
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006994 //
6995 // CmdPushConstants tests
6996 //
6997
Karl Schultzc59b72d2017-02-24 15:45:05 -07006998 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006999 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007000 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007001 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007002 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007003 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007005 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007006
7007 const uint8_t dummy_values[100] = {};
7008
7009 m_commandBuffer->BeginCommandBuffer();
7010 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007011
7012 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007013 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007015 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007016 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007017
Karl Schultzc59b72d2017-02-24 15:45:05 -07007018 m_errorMonitor->ExpectSuccess();
7019 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7020 m_errorMonitor->VerifyNotFound();
7021 m_errorMonitor->ExpectSuccess();
7022 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7023 m_errorMonitor->VerifyNotFound();
7024 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7025 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7026 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7027 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7028 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7029 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7030 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007031 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007032 for (const auto &iter : cmd_range_tests) {
7033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7034 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7035 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007036 m_errorMonitor->VerifyFound();
7037 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007038
Tony Barbour552f6c02016-12-21 14:34:07 -07007039 m_commandBuffer->EndRenderPass();
7040 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007041 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007042}
7043
Karl Schultz6addd812016-02-02 17:17:23 -07007044TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007045 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007046 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007047
7048 ASSERT_NO_FATAL_FAILURE(InitState());
7049 ASSERT_NO_FATAL_FAILURE(InitViewport());
7050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7051
7052 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7053 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007054 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7055 ds_type_count[0].descriptorCount = 10;
7056 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7057 ds_type_count[1].descriptorCount = 2;
7058 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7059 ds_type_count[2].descriptorCount = 2;
7060 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7061 ds_type_count[3].descriptorCount = 5;
7062 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7063 // type
7064 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7065 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7066 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007067
7068 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7070 ds_pool_ci.pNext = NULL;
7071 ds_pool_ci.maxSets = 5;
7072 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7073 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007074
7075 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007076 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007077 ASSERT_VK_SUCCESS(err);
7078
7079 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7080 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007081 dsl_binding[0].binding = 0;
7082 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7083 dsl_binding[0].descriptorCount = 5;
7084 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7085 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007086
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007087 // Create layout identical to set0 layout but w/ different stageFlags
7088 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007089 dsl_fs_stage_only.binding = 0;
7090 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7091 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007092 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7093 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007094 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007095 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007096 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7097 ds_layout_ci.pNext = NULL;
7098 ds_layout_ci.bindingCount = 1;
7099 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007100 static const uint32_t NUM_LAYOUTS = 4;
7101 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007102 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007103 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7104 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007105 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007106 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007107 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007108 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007109 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007110 dsl_binding[0].binding = 0;
7111 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007112 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007113 dsl_binding[1].binding = 1;
7114 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7115 dsl_binding[1].descriptorCount = 2;
7116 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7117 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007118 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007119 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007120 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007121 ASSERT_VK_SUCCESS(err);
7122 dsl_binding[0].binding = 0;
7123 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007124 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007125 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007127 ASSERT_VK_SUCCESS(err);
7128 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007129 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007130 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007131 ASSERT_VK_SUCCESS(err);
7132
7133 static const uint32_t NUM_SETS = 4;
7134 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7135 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007136 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007137 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007138 alloc_info.descriptorPool = ds_pool;
7139 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007140 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007141 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007142 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007143 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007144 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007147
7148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7150 pipeline_layout_ci.pNext = NULL;
7151 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7152 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007153
7154 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007156 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007157 // Create pipelineLayout with only one setLayout
7158 pipeline_layout_ci.setLayoutCount = 1;
7159 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007161 ASSERT_VK_SUCCESS(err);
7162 // Create pipelineLayout with 2 descriptor setLayout at index 0
7163 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7164 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007166 ASSERT_VK_SUCCESS(err);
7167 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7168 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7169 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007171 ASSERT_VK_SUCCESS(err);
7172 // Create pipelineLayout with UB type, but stageFlags for FS only
7173 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7174 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007176 ASSERT_VK_SUCCESS(err);
7177 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7178 VkDescriptorSetLayout pl_bad_s0[2] = {};
7179 pl_bad_s0[0] = ds_layout_fs_only;
7180 pl_bad_s0[1] = ds_layout[1];
7181 pipeline_layout_ci.setLayoutCount = 2;
7182 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7183 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007185 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007186
Tobin Ehlis88452832015-12-03 09:40:56 -07007187 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007188 char const *vsSource =
7189 "#version 450\n"
7190 "\n"
7191 "out gl_PerVertex {\n"
7192 " vec4 gl_Position;\n"
7193 "};\n"
7194 "void main(){\n"
7195 " gl_Position = vec4(1);\n"
7196 "}\n";
7197 char const *fsSource =
7198 "#version 450\n"
7199 "\n"
7200 "layout(location=0) out vec4 x;\n"
7201 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7202 "void main(){\n"
7203 " x = vec4(bar.y);\n"
7204 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007205 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7206 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007207 VkPipelineObj pipe(m_device);
7208 pipe.AddShader(&vs);
7209 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007210 pipe.AddColorAttachment();
7211 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007212
Tony Barbour552f6c02016-12-21 14:34:07 -07007213 m_commandBuffer->BeginCommandBuffer();
7214 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007216 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007217 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7218 // of PSO
7219 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7220 // cmd_pipeline.c
7221 // due to the fact that cmd_alloc_dset_data() has not been called in
7222 // cmd_bind_graphics_pipeline()
7223 // TODO : Want to cause various binding incompatibility issues here to test
7224 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007225 // First cause various verify_layout_compatibility() fails
7226 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007227 // verify_set_layout_compatibility fail cases:
7228 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007230 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7231 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007232 m_errorMonitor->VerifyFound();
7233
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007234 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7236 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7237 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007238 m_errorMonitor->VerifyFound();
7239
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007240 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007241 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7242 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7244 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7245 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007246 m_errorMonitor->VerifyFound();
7247
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007248 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7249 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7251 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7252 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007253 m_errorMonitor->VerifyFound();
7254
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007255 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7256 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7258 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7260 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007261 m_errorMonitor->VerifyFound();
7262
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007263 // Cause INFO messages due to disturbing previously bound Sets
7264 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007265 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7266 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007267 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7270 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007271 m_errorMonitor->VerifyFound();
7272
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007273 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7274 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007275 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7277 " newly bound as set #0 so set #1 and "
7278 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007279 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7280 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007281 m_errorMonitor->VerifyFound();
7282
Tobin Ehlis10fad692016-07-07 12:00:36 -06007283 // Now that we're done actively using the pipelineLayout that gfx pipeline
7284 // was created with, we should be able to delete it. Do that now to verify
7285 // that validation obeys pipelineLayout lifetime
7286 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7287
Tobin Ehlis88452832015-12-03 09:40:56 -07007288 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007289 // 1. Error due to not binding required set (we actually use same code as
7290 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007291 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7292 &descriptorSet[0], 0, NULL);
7293 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7294 &descriptorSet[1], 0, NULL);
7295 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 -07007296
7297 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7298 VkRect2D scissor = {{0, 0}, {16, 16}};
7299 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7300 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7301
Tobin Ehlis88452832015-12-03 09:40:56 -07007302 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007303 m_errorMonitor->VerifyFound();
7304
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007305 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007306 // 2. Error due to bound set not being compatible with PSO's
7307 // VkPipelineLayout (diff stageFlags in this case)
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 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007311 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007312 m_errorMonitor->VerifyFound();
7313
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007314 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007315 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007316 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7317 }
7318 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007319 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7321}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007322
Karl Schultz6addd812016-02-02 17:17:23 -07007323TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7325 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007326
7327 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007328 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007329 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007330 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007331
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007332 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007333}
7334
Karl Schultz6addd812016-02-02 17:17:23 -07007335TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7336 VkResult err;
7337 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007338
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007340
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007341 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007342
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007343 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007344 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007345 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007346 cmd.commandPool = m_commandPool;
7347 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007348 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007349
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007350 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007351 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007352
7353 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007354 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007355 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7356
7357 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007358 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007359 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 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 -07007361 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007362
7363 // The error should be caught by validation of the BeginCommandBuffer call
7364 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7365
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007366 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007367 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007368}
7369
Karl Schultz6addd812016-02-02 17:17:23 -07007370TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007371 // Cause error due to Begin while recording CB
7372 // Then cause 2 errors for attempting to reset CB w/o having
7373 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7374 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007376
7377 ASSERT_NO_FATAL_FAILURE(InitState());
7378
7379 // Calls AllocateCommandBuffers
7380 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7381
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007382 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007383 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007384 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7385 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007386 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7387 cmd_buf_info.pNext = NULL;
7388 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007389 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007390
7391 // Begin CB to transition to recording state
7392 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7393 // Can't re-begin. This should trigger error
7394 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007395 m_errorMonitor->VerifyFound();
7396
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007398 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007399 // Reset attempt will trigger error due to incorrect CommandPool state
7400 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007401 m_errorMonitor->VerifyFound();
7402
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007404 // Transition CB to RECORDED state
7405 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7406 // Now attempting to Begin will implicitly reset, which triggers error
7407 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007408 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007409}
7410
Karl Schultz6addd812016-02-02 17:17:23 -07007411TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007412 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007413 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007414
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7416 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007417
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007418 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007420
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007421 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7423 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007424
7425 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007426 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7427 ds_pool_ci.pNext = NULL;
7428 ds_pool_ci.maxSets = 1;
7429 ds_pool_ci.poolSizeCount = 1;
7430 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007431
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007432 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007433 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007434 ASSERT_VK_SUCCESS(err);
7435
Tony Barboureb254902015-07-15 12:50:33 -06007436 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007437 dsl_binding.binding = 0;
7438 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7439 dsl_binding.descriptorCount = 1;
7440 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7441 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007442
Tony Barboureb254902015-07-15 12:50:33 -06007443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7445 ds_layout_ci.pNext = NULL;
7446 ds_layout_ci.bindingCount = 1;
7447 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007448
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007449 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007451 ASSERT_VK_SUCCESS(err);
7452
7453 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007454 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007456 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007457 alloc_info.descriptorPool = ds_pool;
7458 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007460 ASSERT_VK_SUCCESS(err);
7461
Tony Barboureb254902015-07-15 12:50:33 -06007462 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007463 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7464 pipeline_layout_ci.setLayoutCount = 1;
7465 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007466
7467 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007469 ASSERT_VK_SUCCESS(err);
7470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007471 VkViewport vp = {}; // Just need dummy vp to point to
7472 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007473
7474 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007475 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7476 vp_state_ci.scissorCount = 1;
7477 vp_state_ci.pScissors = &sc;
7478 vp_state_ci.viewportCount = 1;
7479 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007481 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7482 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7483 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7484 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7485 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7486 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007487 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007488 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007489 rs_state_ci.lineWidth = 1.0f;
7490
7491 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7492 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7493 vi_ci.pNext = nullptr;
7494 vi_ci.vertexBindingDescriptionCount = 0;
7495 vi_ci.pVertexBindingDescriptions = nullptr;
7496 vi_ci.vertexAttributeDescriptionCount = 0;
7497 vi_ci.pVertexAttributeDescriptions = nullptr;
7498
7499 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7500 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7501 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7502
7503 VkPipelineShaderStageCreateInfo shaderStages[2];
7504 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7505
7506 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7507 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007508 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007509 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007510
Tony Barboureb254902015-07-15 12:50:33 -06007511 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007512 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7513 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007514 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007515 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7516 gp_ci.layout = pipeline_layout;
7517 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007518 gp_ci.pVertexInputState = &vi_ci;
7519 gp_ci.pInputAssemblyState = &ia_ci;
7520
7521 gp_ci.stageCount = 1;
7522 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007523
7524 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007525 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7526 pc_ci.initialDataSize = 0;
7527 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007528
7529 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007530 VkPipelineCache pipelineCache;
7531
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007532 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007533 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007534 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007535 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007536
Chia-I Wuf7458c52015-10-26 21:10:41 +08007537 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7538 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7539 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7540 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007541}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007542
Tobin Ehlis912df022015-09-17 08:46:18 -06007543/*// TODO : This test should be good, but needs Tess support in compiler to run
7544TEST_F(VkLayerTest, InvalidPatchControlPoints)
7545{
7546 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007547 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007548
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007550 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7551primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007552
Tobin Ehlis912df022015-09-17 08:46:18 -06007553 ASSERT_NO_FATAL_FAILURE(InitState());
7554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007555
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007556 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007557 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007558 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007559
7560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7562 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007563 ds_pool_ci.poolSizeCount = 1;
7564 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007565
7566 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007567 err = vkCreateDescriptorPool(m_device->device(),
7568VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007569 ASSERT_VK_SUCCESS(err);
7570
7571 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007572 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007573 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007574 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007575 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7576 dsl_binding.pImmutableSamplers = NULL;
7577
7578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007579 ds_layout_ci.sType =
7580VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007581 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007582 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007583 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007584
7585 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007586 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7587&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007588 ASSERT_VK_SUCCESS(err);
7589
7590 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007591 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7592VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007593 ASSERT_VK_SUCCESS(err);
7594
7595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007596 pipeline_layout_ci.sType =
7597VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007598 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007599 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007600 pipeline_layout_ci.pSetLayouts = &ds_layout;
7601
7602 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7604&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 ASSERT_VK_SUCCESS(err);
7606
7607 VkPipelineShaderStageCreateInfo shaderStages[3];
7608 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7609
Karl Schultz6addd812016-02-02 17:17:23 -07007610 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7611this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007612 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007613 VkShaderObj
7614tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7615this);
7616 VkShaderObj
7617te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7618this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007619
Karl Schultz6addd812016-02-02 17:17:23 -07007620 shaderStages[0].sType =
7621VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007622 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007623 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007624 shaderStages[1].sType =
7625VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007626 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007627 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007628 shaderStages[2].sType =
7629VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007630 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007631 shaderStages[2].shader = te.handle();
7632
7633 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007634 iaCI.sType =
7635VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007636 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007637
7638 VkPipelineTessellationStateCreateInfo tsCI = {};
7639 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7640 tsCI.patchControlPoints = 0; // This will cause an error
7641
7642 VkGraphicsPipelineCreateInfo gp_ci = {};
7643 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7644 gp_ci.pNext = NULL;
7645 gp_ci.stageCount = 3;
7646 gp_ci.pStages = shaderStages;
7647 gp_ci.pVertexInputState = NULL;
7648 gp_ci.pInputAssemblyState = &iaCI;
7649 gp_ci.pTessellationState = &tsCI;
7650 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007651 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007652 gp_ci.pMultisampleState = NULL;
7653 gp_ci.pDepthStencilState = NULL;
7654 gp_ci.pColorBlendState = NULL;
7655 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7656 gp_ci.layout = pipeline_layout;
7657 gp_ci.renderPass = renderPass();
7658
7659 VkPipelineCacheCreateInfo pc_ci = {};
7660 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7661 pc_ci.pNext = NULL;
7662 pc_ci.initialSize = 0;
7663 pc_ci.initialData = 0;
7664 pc_ci.maxSize = 0;
7665
7666 VkPipeline pipeline;
7667 VkPipelineCache pipelineCache;
7668
Karl Schultz6addd812016-02-02 17:17:23 -07007669 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7670&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007671 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007672 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7673&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007674
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007675 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007676
Chia-I Wuf7458c52015-10-26 21:10:41 +08007677 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7678 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7680 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007681}
7682*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007683
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007684TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007685 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007686
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007687 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007688
Tobin Ehlise68360f2015-10-01 11:15:13 -06007689 ASSERT_NO_FATAL_FAILURE(InitState());
7690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007692 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7694 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007695
7696 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007697 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7698 ds_pool_ci.maxSets = 1;
7699 ds_pool_ci.poolSizeCount = 1;
7700 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007701
7702 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007704 ASSERT_VK_SUCCESS(err);
7705
7706 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007707 dsl_binding.binding = 0;
7708 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7709 dsl_binding.descriptorCount = 1;
7710 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007711
7712 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007713 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7714 ds_layout_ci.bindingCount = 1;
7715 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007716
7717 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007718 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007719 ASSERT_VK_SUCCESS(err);
7720
7721 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007722 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007723 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007724 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007725 alloc_info.descriptorPool = ds_pool;
7726 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007727 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007728 ASSERT_VK_SUCCESS(err);
7729
7730 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007731 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7732 pipeline_layout_ci.setLayoutCount = 1;
7733 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007734
7735 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007737 ASSERT_VK_SUCCESS(err);
7738
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007739 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007740 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007741 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007742 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007743 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007744 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007745
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007746 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7747 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7748 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7749 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7750 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7751 rs_state_ci.depthClampEnable = VK_FALSE;
7752 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7753 rs_state_ci.depthBiasEnable = VK_FALSE;
7754
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007755 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7756 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7757 vi_ci.pNext = nullptr;
7758 vi_ci.vertexBindingDescriptionCount = 0;
7759 vi_ci.pVertexBindingDescriptions = nullptr;
7760 vi_ci.vertexAttributeDescriptionCount = 0;
7761 vi_ci.pVertexAttributeDescriptions = nullptr;
7762
7763 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7764 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7765 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7766
7767 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7768 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7769 pipe_ms_state_ci.pNext = NULL;
7770 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7771 pipe_ms_state_ci.sampleShadingEnable = 0;
7772 pipe_ms_state_ci.minSampleShading = 1.0;
7773 pipe_ms_state_ci.pSampleMask = NULL;
7774
Cody Northropeb3a6c12015-10-05 14:44:45 -06007775 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007776 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007778 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007779 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007780 shaderStages[0] = vs.GetStageCreateInfo();
7781 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782
7783 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007784 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7785 gp_ci.stageCount = 2;
7786 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007787 gp_ci.pVertexInputState = &vi_ci;
7788 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007789 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007790 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007791 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007792 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7793 gp_ci.layout = pipeline_layout;
7794 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007795
7796 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007797 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007798
7799 VkPipeline pipeline;
7800 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007801 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007802 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007803
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007804 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007805 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007806
7807 // Check case where multiViewport is disabled and viewport count is not 1
7808 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7811 vp_state_ci.scissorCount = 0;
7812 vp_state_ci.viewportCount = 0;
7813 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7814 m_errorMonitor->VerifyFound();
7815 } else {
7816 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007817 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007818 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007819 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007820
7821 // Check is that viewportcount and scissorcount match
7822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7823 vp_state_ci.scissorCount = 1;
7824 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7825 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7826 m_errorMonitor->VerifyFound();
7827
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007828 // Check case where multiViewport is enabled and viewport count is greater than max
7829 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7832 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7833 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7834 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7835 m_errorMonitor->VerifyFound();
7836 }
7837 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007838
Chia-I Wuf7458c52015-10-26 21:10:41 +08007839 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7840 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7841 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007843}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007844
7845// 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
7846// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007847TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007848 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007849
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007850 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7851
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007853
Tobin Ehlise68360f2015-10-01 11:15:13 -06007854 ASSERT_NO_FATAL_FAILURE(InitState());
7855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007856
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007857 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007858 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7859 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007860
7861 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007862 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7863 ds_pool_ci.maxSets = 1;
7864 ds_pool_ci.poolSizeCount = 1;
7865 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007866
7867 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007868 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007869 ASSERT_VK_SUCCESS(err);
7870
7871 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007872 dsl_binding.binding = 0;
7873 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7874 dsl_binding.descriptorCount = 1;
7875 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007876
7877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7879 ds_layout_ci.bindingCount = 1;
7880 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007881
7882 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007884 ASSERT_VK_SUCCESS(err);
7885
7886 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007887 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007888 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007889 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007890 alloc_info.descriptorPool = ds_pool;
7891 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007892 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007893 ASSERT_VK_SUCCESS(err);
7894
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007895 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7896 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7897 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7898
7899 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7900 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7901 vi_ci.pNext = nullptr;
7902 vi_ci.vertexBindingDescriptionCount = 0;
7903 vi_ci.pVertexBindingDescriptions = nullptr;
7904 vi_ci.vertexAttributeDescriptionCount = 0;
7905 vi_ci.pVertexAttributeDescriptions = nullptr;
7906
7907 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7908 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7909 pipe_ms_state_ci.pNext = NULL;
7910 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7911 pipe_ms_state_ci.sampleShadingEnable = 0;
7912 pipe_ms_state_ci.minSampleShading = 1.0;
7913 pipe_ms_state_ci.pSampleMask = NULL;
7914
Tobin Ehlise68360f2015-10-01 11:15:13 -06007915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7917 pipeline_layout_ci.setLayoutCount = 1;
7918 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007919
7920 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007922 ASSERT_VK_SUCCESS(err);
7923
7924 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7925 // Set scissor as dynamic to avoid second error
7926 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007927 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7928 dyn_state_ci.dynamicStateCount = 1;
7929 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007930
Cody Northropeb3a6c12015-10-05 14:44:45 -06007931 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007932 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007935 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7936 // 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 +08007937 shaderStages[0] = vs.GetStageCreateInfo();
7938 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007939
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007940 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7941 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7942 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7943 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7944 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7945 rs_state_ci.depthClampEnable = VK_FALSE;
7946 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7947 rs_state_ci.depthBiasEnable = VK_FALSE;
7948
Tobin Ehlise68360f2015-10-01 11:15:13 -06007949 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007950 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7951 gp_ci.stageCount = 2;
7952 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007953 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007954 // Not setting VP state w/o dynamic vp state should cause validation error
7955 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007956 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007957 gp_ci.pVertexInputState = &vi_ci;
7958 gp_ci.pInputAssemblyState = &ia_ci;
7959 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007960 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7961 gp_ci.layout = pipeline_layout;
7962 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007963
7964 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007965 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007966
7967 VkPipeline pipeline;
7968 VkPipelineCache pipelineCache;
7969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007970 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007971 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007972 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007974 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975
Chia-I Wuf7458c52015-10-26 21:10:41 +08007976 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007980}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007981
7982// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7983// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007984TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7985 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007986
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007988
Tobin Ehlise68360f2015-10-01 11:15:13 -06007989 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007990
7991 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007992 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007993 return;
7994 }
7995
Tobin Ehlise68360f2015-10-01 11:15:13 -06007996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007997
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007998 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007999 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8000 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008001
8002 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008003 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8004 ds_pool_ci.maxSets = 1;
8005 ds_pool_ci.poolSizeCount = 1;
8006 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008007
8008 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008009 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008010 ASSERT_VK_SUCCESS(err);
8011
8012 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008013 dsl_binding.binding = 0;
8014 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8015 dsl_binding.descriptorCount = 1;
8016 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008017
8018 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008019 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8020 ds_layout_ci.bindingCount = 1;
8021 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008022
8023 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008025 ASSERT_VK_SUCCESS(err);
8026
8027 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008028 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008029 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008030 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008031 alloc_info.descriptorPool = ds_pool;
8032 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008033 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008034 ASSERT_VK_SUCCESS(err);
8035
8036 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008037 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8038 pipeline_layout_ci.setLayoutCount = 1;
8039 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008040
8041 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008042 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008043 ASSERT_VK_SUCCESS(err);
8044
8045 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008046 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8047 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008048 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008049 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008050 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008051
8052 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8053 // Set scissor as dynamic to avoid that error
8054 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008055 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8056 dyn_state_ci.dynamicStateCount = 1;
8057 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008058
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008059 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8060 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8061 pipe_ms_state_ci.pNext = NULL;
8062 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8063 pipe_ms_state_ci.sampleShadingEnable = 0;
8064 pipe_ms_state_ci.minSampleShading = 1.0;
8065 pipe_ms_state_ci.pSampleMask = NULL;
8066
Cody Northropeb3a6c12015-10-05 14:44:45 -06008067 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008068 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008070 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008071 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8072 // 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 +08008073 shaderStages[0] = vs.GetStageCreateInfo();
8074 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008075
Cody Northropf6622dc2015-10-06 10:33:21 -06008076 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8077 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8078 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008079 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008080 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008081 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008082 vi_ci.pVertexAttributeDescriptions = nullptr;
8083
8084 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8085 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8086 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8087
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008088 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008089 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008090 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008091 rs_ci.pNext = nullptr;
8092
Mark Youngc89c6312016-03-31 16:03:20 -06008093 VkPipelineColorBlendAttachmentState att = {};
8094 att.blendEnable = VK_FALSE;
8095 att.colorWriteMask = 0xf;
8096
Cody Northropf6622dc2015-10-06 10:33:21 -06008097 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8098 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8099 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008100 cb_ci.attachmentCount = 1;
8101 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008102
Tobin Ehlise68360f2015-10-01 11:15:13 -06008103 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008104 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8105 gp_ci.stageCount = 2;
8106 gp_ci.pStages = shaderStages;
8107 gp_ci.pVertexInputState = &vi_ci;
8108 gp_ci.pInputAssemblyState = &ia_ci;
8109 gp_ci.pViewportState = &vp_state_ci;
8110 gp_ci.pRasterizationState = &rs_ci;
8111 gp_ci.pColorBlendState = &cb_ci;
8112 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008113 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008114 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8115 gp_ci.layout = pipeline_layout;
8116 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008117
8118 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008119 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008120
8121 VkPipeline pipeline;
8122 VkPipelineCache pipelineCache;
8123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008124 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008125 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008127
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008128 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008129
Tobin Ehlisd332f282015-10-02 11:00:56 -06008130 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008131 // First need to successfully create the PSO from above by setting
8132 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008133 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 -07008134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008135 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008136 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008138 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008139 m_commandBuffer->BeginCommandBuffer();
8140 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008142 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008143 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008144 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008145 Draw(1, 0, 0, 0);
8146
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008147 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008148
8149 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008153 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008154}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008155
8156// 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 -07008157// viewportCount
8158TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8159 VkResult err;
8160
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008162
8163 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008164
8165 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008166 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008167 return;
8168 }
8169
Karl Schultz6addd812016-02-02 17:17:23 -07008170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8171
8172 VkDescriptorPoolSize ds_type_count = {};
8173 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8174 ds_type_count.descriptorCount = 1;
8175
8176 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8177 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8178 ds_pool_ci.maxSets = 1;
8179 ds_pool_ci.poolSizeCount = 1;
8180 ds_pool_ci.pPoolSizes = &ds_type_count;
8181
8182 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008183 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008184 ASSERT_VK_SUCCESS(err);
8185
8186 VkDescriptorSetLayoutBinding dsl_binding = {};
8187 dsl_binding.binding = 0;
8188 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8189 dsl_binding.descriptorCount = 1;
8190 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8191
8192 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8193 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8194 ds_layout_ci.bindingCount = 1;
8195 ds_layout_ci.pBindings = &dsl_binding;
8196
8197 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008199 ASSERT_VK_SUCCESS(err);
8200
8201 VkDescriptorSet descriptorSet;
8202 VkDescriptorSetAllocateInfo alloc_info = {};
8203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8204 alloc_info.descriptorSetCount = 1;
8205 alloc_info.descriptorPool = ds_pool;
8206 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008208 ASSERT_VK_SUCCESS(err);
8209
8210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8212 pipeline_layout_ci.setLayoutCount = 1;
8213 pipeline_layout_ci.pSetLayouts = &ds_layout;
8214
8215 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008216 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008217 ASSERT_VK_SUCCESS(err);
8218
8219 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8220 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8221 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008222 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008223 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008224 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008225
8226 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8227 // Set scissor as dynamic to avoid that error
8228 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8229 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8230 dyn_state_ci.dynamicStateCount = 1;
8231 dyn_state_ci.pDynamicStates = &vp_state;
8232
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008233 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8234 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8235 pipe_ms_state_ci.pNext = NULL;
8236 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8237 pipe_ms_state_ci.sampleShadingEnable = 0;
8238 pipe_ms_state_ci.minSampleShading = 1.0;
8239 pipe_ms_state_ci.pSampleMask = NULL;
8240
Karl Schultz6addd812016-02-02 17:17:23 -07008241 VkPipelineShaderStageCreateInfo shaderStages[2];
8242 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8243
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008244 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008245 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8246 // 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 -07008247 shaderStages[0] = vs.GetStageCreateInfo();
8248 shaderStages[1] = fs.GetStageCreateInfo();
8249
8250 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8251 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8252 vi_ci.pNext = nullptr;
8253 vi_ci.vertexBindingDescriptionCount = 0;
8254 vi_ci.pVertexBindingDescriptions = nullptr;
8255 vi_ci.vertexAttributeDescriptionCount = 0;
8256 vi_ci.pVertexAttributeDescriptions = nullptr;
8257
8258 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8259 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8260 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8261
8262 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8263 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008264 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008265 rs_ci.pNext = nullptr;
8266
Mark Youngc89c6312016-03-31 16:03:20 -06008267 VkPipelineColorBlendAttachmentState att = {};
8268 att.blendEnable = VK_FALSE;
8269 att.colorWriteMask = 0xf;
8270
Karl Schultz6addd812016-02-02 17:17:23 -07008271 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8272 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8273 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008274 cb_ci.attachmentCount = 1;
8275 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008276
8277 VkGraphicsPipelineCreateInfo gp_ci = {};
8278 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8279 gp_ci.stageCount = 2;
8280 gp_ci.pStages = shaderStages;
8281 gp_ci.pVertexInputState = &vi_ci;
8282 gp_ci.pInputAssemblyState = &ia_ci;
8283 gp_ci.pViewportState = &vp_state_ci;
8284 gp_ci.pRasterizationState = &rs_ci;
8285 gp_ci.pColorBlendState = &cb_ci;
8286 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008287 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008288 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8289 gp_ci.layout = pipeline_layout;
8290 gp_ci.renderPass = renderPass();
8291
8292 VkPipelineCacheCreateInfo pc_ci = {};
8293 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8294
8295 VkPipeline pipeline;
8296 VkPipelineCache pipelineCache;
8297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008298 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008299 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008302 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008303
8304 // Now hit second fail case where we set scissor w/ different count than PSO
8305 // First need to successfully create the PSO from above by setting
8306 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8308 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008310 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008311 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008312 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008313 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008314 m_commandBuffer->BeginCommandBuffer();
8315 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008317 VkViewport viewports[1] = {};
8318 viewports[0].width = 8;
8319 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008320 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008321 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008322 Draw(1, 0, 0, 0);
8323
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008324 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008325
Chia-I Wuf7458c52015-10-26 21:10:41 +08008326 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8327 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8328 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8329 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008330 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008331}
8332
Mark Young7394fdd2016-03-31 14:56:43 -06008333TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8334 VkResult err;
8335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008337
8338 ASSERT_NO_FATAL_FAILURE(InitState());
8339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8340
8341 VkDescriptorPoolSize ds_type_count = {};
8342 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8343 ds_type_count.descriptorCount = 1;
8344
8345 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8346 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8347 ds_pool_ci.maxSets = 1;
8348 ds_pool_ci.poolSizeCount = 1;
8349 ds_pool_ci.pPoolSizes = &ds_type_count;
8350
8351 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008352 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008353 ASSERT_VK_SUCCESS(err);
8354
8355 VkDescriptorSetLayoutBinding dsl_binding = {};
8356 dsl_binding.binding = 0;
8357 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8358 dsl_binding.descriptorCount = 1;
8359 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8360
8361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8363 ds_layout_ci.bindingCount = 1;
8364 ds_layout_ci.pBindings = &dsl_binding;
8365
8366 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008368 ASSERT_VK_SUCCESS(err);
8369
8370 VkDescriptorSet descriptorSet;
8371 VkDescriptorSetAllocateInfo alloc_info = {};
8372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8373 alloc_info.descriptorSetCount = 1;
8374 alloc_info.descriptorPool = ds_pool;
8375 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008377 ASSERT_VK_SUCCESS(err);
8378
8379 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8380 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8381 pipeline_layout_ci.setLayoutCount = 1;
8382 pipeline_layout_ci.pSetLayouts = &ds_layout;
8383
8384 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008386 ASSERT_VK_SUCCESS(err);
8387
8388 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8389 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8390 vp_state_ci.scissorCount = 1;
8391 vp_state_ci.pScissors = NULL;
8392 vp_state_ci.viewportCount = 1;
8393 vp_state_ci.pViewports = NULL;
8394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008396 // Set scissor as dynamic to avoid that error
8397 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8398 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8399 dyn_state_ci.dynamicStateCount = 2;
8400 dyn_state_ci.pDynamicStates = dynamic_states;
8401
8402 VkPipelineShaderStageCreateInfo shaderStages[2];
8403 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8406 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008407 this); // TODO - We shouldn't need a fragment shader
8408 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008409 shaderStages[0] = vs.GetStageCreateInfo();
8410 shaderStages[1] = fs.GetStageCreateInfo();
8411
8412 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8413 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8414 vi_ci.pNext = nullptr;
8415 vi_ci.vertexBindingDescriptionCount = 0;
8416 vi_ci.pVertexBindingDescriptions = nullptr;
8417 vi_ci.vertexAttributeDescriptionCount = 0;
8418 vi_ci.pVertexAttributeDescriptions = nullptr;
8419
8420 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8421 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8422 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8423
8424 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8425 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8426 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008427 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008428
Mark Young47107952016-05-02 15:59:55 -06008429 // Check too low (line width of -1.0f).
8430 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008431
8432 VkPipelineColorBlendAttachmentState att = {};
8433 att.blendEnable = VK_FALSE;
8434 att.colorWriteMask = 0xf;
8435
8436 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8437 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8438 cb_ci.pNext = nullptr;
8439 cb_ci.attachmentCount = 1;
8440 cb_ci.pAttachments = &att;
8441
8442 VkGraphicsPipelineCreateInfo gp_ci = {};
8443 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8444 gp_ci.stageCount = 2;
8445 gp_ci.pStages = shaderStages;
8446 gp_ci.pVertexInputState = &vi_ci;
8447 gp_ci.pInputAssemblyState = &ia_ci;
8448 gp_ci.pViewportState = &vp_state_ci;
8449 gp_ci.pRasterizationState = &rs_ci;
8450 gp_ci.pColorBlendState = &cb_ci;
8451 gp_ci.pDynamicState = &dyn_state_ci;
8452 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8453 gp_ci.layout = pipeline_layout;
8454 gp_ci.renderPass = renderPass();
8455
8456 VkPipelineCacheCreateInfo pc_ci = {};
8457 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8458
8459 VkPipeline pipeline;
8460 VkPipelineCache pipelineCache;
8461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008463 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008464 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008465
8466 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008467 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008468
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008470
8471 // Check too high (line width of 65536.0f).
8472 rs_ci.lineWidth = 65536.0f;
8473
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008475 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008477
8478 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008479 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008480
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008482
8483 dyn_state_ci.dynamicStateCount = 3;
8484
8485 rs_ci.lineWidth = 1.0f;
8486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008488 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008489 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008490 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008492
8493 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008494 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008495 m_errorMonitor->VerifyFound();
8496
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008498
8499 // Check too high with dynamic setting.
8500 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8501 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008502 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008503
8504 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8505 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8506 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8507 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008508 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008509}
8510
Karl Schultz6addd812016-02-02 17:17:23 -07008511TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008512 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008514 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008515
8516 ASSERT_NO_FATAL_FAILURE(InitState());
8517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008518
Tony Barbour552f6c02016-12-21 14:34:07 -07008519 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008520 // Don't care about RenderPass handle b/c error should be flagged before
8521 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008523
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008524 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008525}
8526
Karl Schultz6addd812016-02-02 17:17:23 -07008527TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008528 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8530 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008531
8532 ASSERT_NO_FATAL_FAILURE(InitState());
8533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008534
Tony Barbour552f6c02016-12-21 14:34:07 -07008535 m_commandBuffer->BeginCommandBuffer();
8536 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008537 // Just create a dummy Renderpass that's non-NULL so we can get to the
8538 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008540
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008541 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008542}
8543
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008544TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008545 TEST_DESCRIPTION(
8546 "Begin a renderPass where clearValueCount is less than"
8547 "the number of renderPass attachments that use loadOp"
8548 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008549
8550 ASSERT_NO_FATAL_FAILURE(InitState());
8551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8552
8553 // Create a renderPass with a single attachment that uses loadOp CLEAR
8554 VkAttachmentReference attach = {};
8555 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8556 VkSubpassDescription subpass = {};
8557 subpass.inputAttachmentCount = 1;
8558 subpass.pInputAttachments = &attach;
8559 VkRenderPassCreateInfo rpci = {};
8560 rpci.subpassCount = 1;
8561 rpci.pSubpasses = &subpass;
8562 rpci.attachmentCount = 1;
8563 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008564 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008565 // Set loadOp to CLEAR
8566 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8567 rpci.pAttachments = &attach_desc;
8568 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8569 VkRenderPass rp;
8570 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8571
8572 VkCommandBufferInheritanceInfo hinfo = {};
8573 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8574 hinfo.renderPass = VK_NULL_HANDLE;
8575 hinfo.subpass = 0;
8576 hinfo.framebuffer = VK_NULL_HANDLE;
8577 hinfo.occlusionQueryEnable = VK_FALSE;
8578 hinfo.queryFlags = 0;
8579 hinfo.pipelineStatistics = 0;
8580 VkCommandBufferBeginInfo info = {};
8581 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8582 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8583 info.pInheritanceInfo = &hinfo;
8584
8585 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8586 VkRenderPassBeginInfo rp_begin = {};
8587 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8588 rp_begin.pNext = NULL;
8589 rp_begin.renderPass = renderPass();
8590 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008591 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008592
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008594
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008595 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008596
8597 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008598
8599 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008600}
8601
Slawomir Cygan0808f392016-11-28 17:53:23 +01008602TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008603 TEST_DESCRIPTION(
8604 "Begin a renderPass where clearValueCount is greater than"
8605 "the number of renderPass attachments that use loadOp"
8606 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008607
8608 ASSERT_NO_FATAL_FAILURE(InitState());
8609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8610
8611 // Create a renderPass with a single attachment that uses loadOp CLEAR
8612 VkAttachmentReference attach = {};
8613 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8614 VkSubpassDescription subpass = {};
8615 subpass.inputAttachmentCount = 1;
8616 subpass.pInputAttachments = &attach;
8617 VkRenderPassCreateInfo rpci = {};
8618 rpci.subpassCount = 1;
8619 rpci.pSubpasses = &subpass;
8620 rpci.attachmentCount = 1;
8621 VkAttachmentDescription attach_desc = {};
8622 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8623 // Set loadOp to CLEAR
8624 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8625 rpci.pAttachments = &attach_desc;
8626 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8627 VkRenderPass rp;
8628 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8629
8630 VkCommandBufferBeginInfo info = {};
8631 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8632 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8633
8634 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8635 VkRenderPassBeginInfo rp_begin = {};
8636 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8637 rp_begin.pNext = NULL;
8638 rp_begin.renderPass = renderPass();
8639 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008640 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008641
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8643 " has a clearValueCount of"
8644 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008645
8646 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8647
8648 m_errorMonitor->VerifyFound();
8649
8650 vkDestroyRenderPass(m_device->device(), rp, NULL);
8651}
8652
Cody Northrop3bb4d962016-05-09 16:15:57 -06008653TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008654 TEST_DESCRIPTION("End a command buffer with an active render pass");
8655
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8657 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008658
8659 ASSERT_NO_FATAL_FAILURE(InitState());
8660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8661
Tony Barbour552f6c02016-12-21 14:34:07 -07008662 m_commandBuffer->BeginCommandBuffer();
8663 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8664 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008665
8666 m_errorMonitor->VerifyFound();
8667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008668 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8669 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008670}
8671
Karl Schultz6addd812016-02-02 17:17:23 -07008672TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008673 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8675 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008676
8677 ASSERT_NO_FATAL_FAILURE(InitState());
8678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008679
Tony Barbour552f6c02016-12-21 14:34:07 -07008680 m_commandBuffer->BeginCommandBuffer();
8681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008682
8683 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008684 vk_testing::Buffer dstBuffer;
8685 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008686
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008687 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008688
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008689 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008690}
8691
Karl Schultz6addd812016-02-02 17:17:23 -07008692TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8695 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008696
8697 ASSERT_NO_FATAL_FAILURE(InitState());
8698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008699
Tony Barbour552f6c02016-12-21 14:34:07 -07008700 m_commandBuffer->BeginCommandBuffer();
8701 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008702
8703 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008704 vk_testing::Buffer dstBuffer;
8705 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008706
Karl Schultz6addd812016-02-02 17:17:23 -07008707 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008708 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8709 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8710 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008711
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008712 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008713}
8714
Karl Schultz6addd812016-02-02 17:17:23 -07008715TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008716 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8718 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008719
8720 ASSERT_NO_FATAL_FAILURE(InitState());
8721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008722
Tony Barbour552f6c02016-12-21 14:34:07 -07008723 m_commandBuffer->BeginCommandBuffer();
8724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008725
Michael Lentine0a369f62016-02-03 16:51:46 -06008726 VkClearColorValue clear_color;
8727 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008728 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8730 const int32_t tex_width = 32;
8731 const int32_t tex_height = 32;
8732 VkImageCreateInfo image_create_info = {};
8733 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8734 image_create_info.pNext = NULL;
8735 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8736 image_create_info.format = tex_format;
8737 image_create_info.extent.width = tex_width;
8738 image_create_info.extent.height = tex_height;
8739 image_create_info.extent.depth = 1;
8740 image_create_info.mipLevels = 1;
8741 image_create_info.arrayLayers = 1;
8742 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8743 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07008744 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008745
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008746 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008747 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008750
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008751 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008752
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008753 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008754}
8755
Karl Schultz6addd812016-02-02 17:17:23 -07008756TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008757 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8759 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760
8761 ASSERT_NO_FATAL_FAILURE(InitState());
8762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008763
Tony Barbourf887b162017-03-09 10:06:46 -07008764 auto depth_format = find_depth_stencil_format(m_device);
8765 if (!depth_format) {
8766 printf(" No Depth + Stencil format found. Skipped.\n");
8767 return;
8768 }
8769
Tony Barbour552f6c02016-12-21 14:34:07 -07008770 m_commandBuffer->BeginCommandBuffer();
8771 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772
8773 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008774 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008775 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07008777 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07008778 image_create_info.extent.width = 64;
8779 image_create_info.extent.height = 64;
8780 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8781 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008782
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008783 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008784 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008786 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008787
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008788 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8789 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008790
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008791 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008792}
8793
Karl Schultz6addd812016-02-02 17:17:23 -07008794TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008795 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008796 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008797
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8799 "vkCmdClearAttachments(): This call "
8800 "must be issued inside an active "
8801 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008802
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008803 ASSERT_NO_FATAL_FAILURE(InitState());
8804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008805
8806 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008807 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008808 ASSERT_VK_SUCCESS(err);
8809
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008810 VkClearAttachment color_attachment;
8811 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8812 color_attachment.clearValue.color.float32[0] = 0;
8813 color_attachment.clearValue.color.float32[1] = 0;
8814 color_attachment.clearValue.color.float32[2] = 0;
8815 color_attachment.clearValue.color.float32[3] = 0;
8816 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008817 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008818 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008820 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008821}
8822
Chris Forbes3b97e932016-09-07 11:29:24 +12008823TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008824 TEST_DESCRIPTION(
8825 "Test that an error is produced when CmdNextSubpass is "
8826 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008827
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8829 "vkCmdNextSubpass(): Attempted to advance "
8830 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008831
8832 ASSERT_NO_FATAL_FAILURE(InitState());
8833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8834
Tony Barbour552f6c02016-12-21 14:34:07 -07008835 m_commandBuffer->BeginCommandBuffer();
8836 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008837
8838 // error here.
8839 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8840 m_errorMonitor->VerifyFound();
8841
Tony Barbour552f6c02016-12-21 14:34:07 -07008842 m_commandBuffer->EndRenderPass();
8843 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008844}
8845
Chris Forbes6d624702016-09-07 13:57:05 +12008846TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008847 TEST_DESCRIPTION(
8848 "Test that an error is produced when CmdEndRenderPass is "
8849 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008850
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8852 "vkCmdEndRenderPass(): Called before reaching "
8853 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008854
8855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008856 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8857 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008860
8861 VkRenderPass rp;
8862 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8863 ASSERT_VK_SUCCESS(err);
8864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008865 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008866
8867 VkFramebuffer fb;
8868 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8869 ASSERT_VK_SUCCESS(err);
8870
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008871 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008873 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 +12008874
8875 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8876
8877 // Error here.
8878 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8879 m_errorMonitor->VerifyFound();
8880
8881 // Clean up.
8882 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8883 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8884}
8885
Karl Schultz9e66a292016-04-21 15:57:51 -06008886TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8887 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8889 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008890
8891 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008892 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008893
8894 VkBufferMemoryBarrier buf_barrier = {};
8895 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8896 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8897 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8898 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8899 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8900 buf_barrier.buffer = VK_NULL_HANDLE;
8901 buf_barrier.offset = 0;
8902 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008903 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8904 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008905
8906 m_errorMonitor->VerifyFound();
8907}
8908
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008909TEST_F(VkLayerTest, InvalidBarriers) {
8910 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008913
8914 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07008915 auto depth_format = find_depth_stencil_format(m_device);
8916 if (!depth_format) {
8917 printf(" No Depth + Stencil format found. Skipped.\n");
8918 return;
8919 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8921
8922 VkMemoryBarrier mem_barrier = {};
8923 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8924 mem_barrier.pNext = NULL;
8925 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8926 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008927 m_commandBuffer->BeginCommandBuffer();
8928 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008929 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008930 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008931 &mem_barrier, 0, nullptr, 0, nullptr);
8932 m_errorMonitor->VerifyFound();
8933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008935 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008936 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 -06008937 ASSERT_TRUE(image.initialized());
8938 VkImageMemoryBarrier img_barrier = {};
8939 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8940 img_barrier.pNext = NULL;
8941 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8942 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8943 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8944 // New layout can't be UNDEFINED
8945 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8946 img_barrier.image = image.handle();
8947 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8948 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8949 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8950 img_barrier.subresourceRange.baseArrayLayer = 0;
8951 img_barrier.subresourceRange.baseMipLevel = 0;
8952 img_barrier.subresourceRange.layerCount = 1;
8953 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008954 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8955 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008956 m_errorMonitor->VerifyFound();
8957 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8958
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8960 "Subresource must have the sum of the "
8961 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008962 // baseArrayLayer + layerCount must be <= image's arrayLayers
8963 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8965 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008966 m_errorMonitor->VerifyFound();
8967 img_barrier.subresourceRange.baseArrayLayer = 0;
8968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008970 // baseMipLevel + levelCount must be <= image's mipLevels
8971 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008972 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8973 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008974 m_errorMonitor->VerifyFound();
8975 img_barrier.subresourceRange.baseMipLevel = 0;
8976
Mike Weiblen7053aa32017-01-25 15:21:10 -07008977 // levelCount must be non-zero.
8978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8979 img_barrier.subresourceRange.levelCount = 0;
8980 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8981 nullptr, 0, nullptr, 1, &img_barrier);
8982 m_errorMonitor->VerifyFound();
8983 img_barrier.subresourceRange.levelCount = 1;
8984
8985 // layerCount must be non-zero.
8986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8987 img_barrier.subresourceRange.layerCount = 0;
8988 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8989 nullptr, 0, nullptr, 1, &img_barrier);
8990 m_errorMonitor->VerifyFound();
8991 img_barrier.subresourceRange.layerCount = 1;
8992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008993 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 -06008994 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008995 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8996 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008997 VkBufferMemoryBarrier buf_barrier = {};
8998 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8999 buf_barrier.pNext = NULL;
9000 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9001 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9002 buf_barrier.buffer = buffer.handle();
9003 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9004 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9005 buf_barrier.offset = 0;
9006 buf_barrier.size = VK_WHOLE_SIZE;
9007 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009008 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9009 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009010 m_errorMonitor->VerifyFound();
9011 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9012
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009014 buf_barrier.offset = 257;
9015 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009016 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9017 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009018 m_errorMonitor->VerifyFound();
9019 buf_barrier.offset = 0;
9020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009022 buf_barrier.size = 257;
9023 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009024 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9025 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009026 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009027
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009028 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009029 m_errorMonitor->SetDesiredFailureMsg(
9030 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009031 "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 -06009032 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009033 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009034 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009035 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9036 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009037 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009038
9039 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009040 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009041 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9042 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009043 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009044
9045 // Having anything other than DEPTH or STENCIL is an error
9046 m_errorMonitor->SetDesiredFailureMsg(
9047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9048 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9049 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9050 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9051 nullptr, 0, nullptr, 1, &img_barrier);
9052 m_errorMonitor->VerifyFound();
9053
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009054 // Now test depth-only
9055 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009056 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9057 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009058 VkDepthStencilObj d_image(m_device);
9059 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9060 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009061 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009062 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009063 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009064
9065 // DEPTH bit must be set
9066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9067 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009068 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009069 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9070 0, nullptr, 0, nullptr, 1, &img_barrier);
9071 m_errorMonitor->VerifyFound();
9072
9073 // No bits other than DEPTH may be set
9074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9075 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9076 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009077 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9078 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009079 m_errorMonitor->VerifyFound();
9080 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009081
9082 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009083 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9084 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009085 VkDepthStencilObj s_image(m_device);
9086 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9087 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009088 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009089 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009090 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009091 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9093 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009094 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009095 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9096 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009097 m_errorMonitor->VerifyFound();
9098 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009099
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009100 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009101 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009102 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 -06009103 ASSERT_TRUE(c_image.initialized());
9104 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9105 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9106 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009107
9108 // COLOR bit must be set
9109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9110 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009111 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009112 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9113 nullptr, 0, nullptr, 1, &img_barrier);
9114 m_errorMonitor->VerifyFound();
9115
9116 // No bits other than COLOR may be set
9117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9118 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9119 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009120 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9121 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009122 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009123
9124 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9125
9126 // Create command pool with incompatible queueflags
9127 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9128 uint32_t queue_family_index = UINT32_MAX;
9129 for (uint32_t i = 0; i < queue_props.size(); i++) {
9130 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9131 queue_family_index = i;
9132 break;
9133 }
9134 }
9135 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009136 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009137 return;
9138 }
9139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9140
9141 VkCommandPool command_pool;
9142 VkCommandPoolCreateInfo pool_create_info{};
9143 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9144 pool_create_info.queueFamilyIndex = queue_family_index;
9145 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9146 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9147
9148 // Allocate a command buffer
9149 VkCommandBuffer bad_command_buffer;
9150 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9151 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9152 command_buffer_allocate_info.commandPool = command_pool;
9153 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9154 command_buffer_allocate_info.commandBufferCount = 1;
9155 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9156
9157 VkCommandBufferBeginInfo cbbi = {};
9158 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9159 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9160 buf_barrier.offset = 0;
9161 buf_barrier.size = VK_WHOLE_SIZE;
9162 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9163 &buf_barrier, 0, nullptr);
9164 m_errorMonitor->VerifyFound();
9165
9166 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9167 vkEndCommandBuffer(bad_command_buffer);
9168 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009169 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009170 return;
9171 }
9172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9173 VkEvent event;
9174 VkEventCreateInfo event_create_info{};
9175 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9176 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9177 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9178 nullptr, 0, nullptr);
9179 m_errorMonitor->VerifyFound();
9180
9181 vkEndCommandBuffer(bad_command_buffer);
9182 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009183}
9184
Tony Barbour18ba25c2016-09-29 13:42:40 -06009185TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9186 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9187
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009189 ASSERT_NO_FATAL_FAILURE(InitState());
9190 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -07009191 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
9192 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009193 ASSERT_TRUE(image.initialized());
9194
9195 VkImageMemoryBarrier barrier = {};
9196 VkImageSubresourceRange range;
9197 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9198 barrier.srcAccessMask = 0;
9199 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9200 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9201 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9202 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9203 barrier.image = image.handle();
9204 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9205 range.baseMipLevel = 0;
9206 range.levelCount = 1;
9207 range.baseArrayLayer = 0;
9208 range.layerCount = 1;
9209 barrier.subresourceRange = range;
9210 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9211 cmdbuf.BeginCommandBuffer();
9212 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9213 &barrier);
9214 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9215 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9216 barrier.srcAccessMask = 0;
9217 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9218 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9219 &barrier);
9220
9221 m_errorMonitor->VerifyFound();
9222}
9223
Karl Schultz6addd812016-02-02 17:17:23 -07009224TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009225 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009226 ASSERT_NO_FATAL_FAILURE(InitState());
9227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009228
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009229 uint32_t const indices[] = {0};
9230 VkBufferCreateInfo buf_info = {};
9231 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9232 buf_info.size = 1024;
9233 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9234 buf_info.queueFamilyIndexCount = 1;
9235 buf_info.pQueueFamilyIndices = indices;
9236
9237 VkBuffer buffer;
9238 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
9239 ASSERT_VK_SUCCESS(err);
9240
9241 VkMemoryRequirements requirements;
9242 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
9243
9244 VkMemoryAllocateInfo alloc_info{};
9245 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9246 alloc_info.pNext = NULL;
9247 alloc_info.memoryTypeIndex = 0;
9248 alloc_info.allocationSize = requirements.size;
9249 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
9250 ASSERT_TRUE(pass);
9251
9252 VkDeviceMemory memory;
9253 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
9254 ASSERT_VK_SUCCESS(err);
9255
9256 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009257 ASSERT_VK_SUCCESS(err);
9258
Tony Barbour552f6c02016-12-21 14:34:07 -07009259 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009260 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009261
Karl Schultz6addd812016-02-02 17:17:23 -07009262 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9263 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009264 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
9266 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009267 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009268
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009269 vkFreeMemory(m_device->device(), memory, NULL);
9270 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009271}
9272
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009273TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9274 // Create an out-of-range queueFamilyIndex
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009275 ASSERT_NO_FATAL_FAILURE(InitState());
9276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9277 VkBufferCreateInfo buffCI = {};
9278 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9279 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009280 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009281 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009282 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009283 uint32_t qfi[2];
9284 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009285 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009286
9287 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009288 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009289
9290 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9292 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one of the indices "
9293 "specified when the device was created, via the VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009294 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009295 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009296
9297 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -07009298 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9300
9301 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9302 buffCI.queueFamilyIndexCount = 2;
9303 qfi[0] = 1;
9304 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -07009305 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009306 VkDeviceMemory mem;
9307 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -07009308 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009309
9310 VkMemoryAllocateInfo alloc_info = {};
9311 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9312 alloc_info.allocationSize = 1024;
9313 bool pass = false;
9314 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9315 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -07009316 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009317 return;
9318 }
9319 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -07009320 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009321
9322 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -07009323 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009324 m_commandBuffer->end();
9325 QueueCommandBuffer(false);
9326 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -07009327 vkDestroyBuffer(m_device->device(), ib2, NULL);
9328 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009329 }
9330
Tony Barbourdf4c0042016-06-01 15:55:43 -06009331 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009332}
9333
Karl Schultz6addd812016-02-02 17:17:23 -07009334TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009335 TEST_DESCRIPTION(
9336 "Attempt vkCmdExecuteCommands with a primary command buffer"
9337 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009338
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009339 ASSERT_NO_FATAL_FAILURE(InitState());
9340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009341
Chris Forbesf29a84f2016-10-06 18:39:28 +13009342 // An empty primary command buffer
9343 VkCommandBufferObj cb(m_device, m_commandPool);
9344 cb.BeginCommandBuffer();
9345 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009346
Chris Forbesf29a84f2016-10-06 18:39:28 +13009347 m_commandBuffer->BeginCommandBuffer();
9348 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9349 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009350
Chris Forbesf29a84f2016-10-06 18:39:28 +13009351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9352 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009353 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009354
9355 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009356}
9357
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009358TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009359 TEST_DESCRIPTION(
9360 "Attempt to update descriptor sets for images and buffers "
9361 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009362 VkResult err;
9363
9364 ASSERT_NO_FATAL_FAILURE(InitState());
9365 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9366 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9367 ds_type_count[i].type = VkDescriptorType(i);
9368 ds_type_count[i].descriptorCount = 1;
9369 }
9370 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9371 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9372 ds_pool_ci.pNext = NULL;
9373 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9374 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9375 ds_pool_ci.pPoolSizes = ds_type_count;
9376
9377 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009378 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009379 ASSERT_VK_SUCCESS(err);
9380
9381 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009382 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009383 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9384 dsl_binding[i].binding = 0;
9385 dsl_binding[i].descriptorType = VkDescriptorType(i);
9386 dsl_binding[i].descriptorCount = 1;
9387 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9388 dsl_binding[i].pImmutableSamplers = NULL;
9389 }
9390
9391 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9392 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9393 ds_layout_ci.pNext = NULL;
9394 ds_layout_ci.bindingCount = 1;
9395 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9396 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9397 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009399 ASSERT_VK_SUCCESS(err);
9400 }
9401 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9402 VkDescriptorSetAllocateInfo alloc_info = {};
9403 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9404 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9405 alloc_info.descriptorPool = ds_pool;
9406 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009407 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009408 ASSERT_VK_SUCCESS(err);
9409
9410 // Create a buffer & bufferView to be used for invalid updates
9411 VkBufferCreateInfo buff_ci = {};
9412 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009413 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009414 buff_ci.size = 256;
9415 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009416 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009417 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9418 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009419
9420 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9421 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9422 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9423 ASSERT_VK_SUCCESS(err);
9424
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009425 VkMemoryRequirements mem_reqs;
9426 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9427 VkMemoryAllocateInfo mem_alloc_info = {};
9428 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9429 mem_alloc_info.pNext = NULL;
9430 mem_alloc_info.memoryTypeIndex = 0;
9431 mem_alloc_info.allocationSize = mem_reqs.size;
9432 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9433 if (!pass) {
9434 vkDestroyBuffer(m_device->device(), buffer, NULL);
9435 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9436 return;
9437 }
9438 VkDeviceMemory mem;
9439 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9440 ASSERT_VK_SUCCESS(err);
9441 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9442 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009443
9444 VkBufferViewCreateInfo buff_view_ci = {};
9445 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9446 buff_view_ci.buffer = buffer;
9447 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9448 buff_view_ci.range = VK_WHOLE_SIZE;
9449 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009450 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009451 ASSERT_VK_SUCCESS(err);
9452
Tony Barbour415497c2017-01-24 10:06:09 -07009453 // Now get resources / view for storage_texel_buffer
9454 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9455 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9456 if (!pass) {
9457 vkDestroyBuffer(m_device->device(), buffer, NULL);
9458 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9459 vkFreeMemory(m_device->device(), mem, NULL);
9460 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9461 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9462 return;
9463 }
9464 VkDeviceMemory storage_texel_buffer_mem;
9465 VkBufferView storage_texel_buffer_view;
9466 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9467 ASSERT_VK_SUCCESS(err);
9468 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9469 ASSERT_VK_SUCCESS(err);
9470 buff_view_ci.buffer = storage_texel_buffer;
9471 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9472 ASSERT_VK_SUCCESS(err);
9473
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009474 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009475 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009476 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009477 image_ci.format = VK_FORMAT_UNDEFINED;
9478 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9479 VkFormat format = static_cast<VkFormat>(f);
9480 VkFormatProperties fProps = m_device->format_properties(format);
9481 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9482 image_ci.format = format;
9483 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9484 break;
9485 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9486 image_ci.format = format;
9487 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9488 break;
9489 }
9490 }
9491 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9492 return;
9493 }
9494
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009495 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9496 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009497 image_ci.extent.width = 64;
9498 image_ci.extent.height = 64;
9499 image_ci.extent.depth = 1;
9500 image_ci.mipLevels = 1;
9501 image_ci.arrayLayers = 1;
9502 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009503 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009504 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009505 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9506 VkImage image;
9507 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9508 ASSERT_VK_SUCCESS(err);
9509 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009510 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009511
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009512 VkMemoryAllocateInfo mem_alloc = {};
9513 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9514 mem_alloc.pNext = NULL;
9515 mem_alloc.allocationSize = 0;
9516 mem_alloc.memoryTypeIndex = 0;
9517 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9518 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009519 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009520 ASSERT_TRUE(pass);
9521 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9522 ASSERT_VK_SUCCESS(err);
9523 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9524 ASSERT_VK_SUCCESS(err);
9525 // Now create view for image
9526 VkImageViewCreateInfo image_view_ci = {};
9527 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9528 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009529 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009530 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9531 image_view_ci.subresourceRange.layerCount = 1;
9532 image_view_ci.subresourceRange.baseArrayLayer = 0;
9533 image_view_ci.subresourceRange.levelCount = 1;
9534 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9535 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009536 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009537 ASSERT_VK_SUCCESS(err);
9538
9539 VkDescriptorBufferInfo buff_info = {};
9540 buff_info.buffer = buffer;
9541 VkDescriptorImageInfo img_info = {};
9542 img_info.imageView = image_view;
9543 VkWriteDescriptorSet descriptor_write = {};
9544 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9545 descriptor_write.dstBinding = 0;
9546 descriptor_write.descriptorCount = 1;
9547 descriptor_write.pTexelBufferView = &buff_view;
9548 descriptor_write.pBufferInfo = &buff_info;
9549 descriptor_write.pImageInfo = &img_info;
9550
9551 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009552 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009553 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9554 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9555 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9556 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9557 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9558 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9559 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9560 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9561 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9562 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9563 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009564 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009565 // Start loop at 1 as SAMPLER desc type has no usage bit error
9566 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009567 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9568 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9569 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9570 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009571 descriptor_write.descriptorType = VkDescriptorType(i);
9572 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009575 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009576
9577 m_errorMonitor->VerifyFound();
9578 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009579 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9580 descriptor_write.pTexelBufferView = &buff_view;
9581 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009582 }
Tony Barbour415497c2017-01-24 10:06:09 -07009583
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009584 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9585 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009586 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009587 vkDestroyImageView(m_device->device(), image_view, NULL);
9588 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009589 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009590 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009591 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009592 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009593 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009594 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9595}
9596
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009597TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009598 TEST_DESCRIPTION(
9599 "Attempt to update buffer descriptor set that has incorrect "
9600 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009601 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009602 "2. range value of 0\n"
9603 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009604 VkResult err;
9605
9606 ASSERT_NO_FATAL_FAILURE(InitState());
9607 VkDescriptorPoolSize ds_type_count = {};
9608 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9609 ds_type_count.descriptorCount = 1;
9610
9611 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9612 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9613 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009614 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009615 ds_pool_ci.maxSets = 1;
9616 ds_pool_ci.poolSizeCount = 1;
9617 ds_pool_ci.pPoolSizes = &ds_type_count;
9618
9619 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009620 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009621 ASSERT_VK_SUCCESS(err);
9622
9623 // Create layout with single uniform buffer descriptor
9624 VkDescriptorSetLayoutBinding dsl_binding = {};
9625 dsl_binding.binding = 0;
9626 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9627 dsl_binding.descriptorCount = 1;
9628 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9629 dsl_binding.pImmutableSamplers = NULL;
9630
9631 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9632 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9633 ds_layout_ci.pNext = NULL;
9634 ds_layout_ci.bindingCount = 1;
9635 ds_layout_ci.pBindings = &dsl_binding;
9636 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009637 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009638 ASSERT_VK_SUCCESS(err);
9639
9640 VkDescriptorSet descriptor_set = {};
9641 VkDescriptorSetAllocateInfo alloc_info = {};
9642 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9643 alloc_info.descriptorSetCount = 1;
9644 alloc_info.descriptorPool = ds_pool;
9645 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009646 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009647 ASSERT_VK_SUCCESS(err);
9648
9649 // Create a buffer to be used for invalid updates
9650 VkBufferCreateInfo buff_ci = {};
9651 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9652 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009653 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009654 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9655 VkBuffer buffer;
9656 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9657 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009658
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009659 // Have to bind memory to buffer before descriptor update
9660 VkMemoryAllocateInfo mem_alloc = {};
9661 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9662 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009663 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009664 mem_alloc.memoryTypeIndex = 0;
9665
9666 VkMemoryRequirements mem_reqs;
9667 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009668 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009669 if (!pass) {
9670 vkDestroyBuffer(m_device->device(), buffer, NULL);
9671 return;
9672 }
9673
9674 VkDeviceMemory mem;
9675 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9676 ASSERT_VK_SUCCESS(err);
9677 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9678 ASSERT_VK_SUCCESS(err);
9679
9680 VkDescriptorBufferInfo buff_info = {};
9681 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009682 // Cause error due to offset out of range
9683 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009684 buff_info.range = VK_WHOLE_SIZE;
9685 VkWriteDescriptorSet descriptor_write = {};
9686 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9687 descriptor_write.dstBinding = 0;
9688 descriptor_write.descriptorCount = 1;
9689 descriptor_write.pTexelBufferView = nullptr;
9690 descriptor_write.pBufferInfo = &buff_info;
9691 descriptor_write.pImageInfo = nullptr;
9692
9693 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9694 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009696
9697 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9698
9699 m_errorMonitor->VerifyFound();
9700 // Now cause error due to range of 0
9701 buff_info.offset = 0;
9702 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009704
9705 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9706
9707 m_errorMonitor->VerifyFound();
9708 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009709 buff_info.offset = 0;
9710 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009712
9713 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9714
9715 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009716 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009717 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9718 vkDestroyBuffer(m_device->device(), buffer, NULL);
9719 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9720 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9721}
9722
Tobin Ehlis845887e2017-02-02 19:01:44 -07009723TEST_F(VkLayerTest, DSBufferLimitErrors) {
9724 TEST_DESCRIPTION(
9725 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9726 "Test cases include:\n"
9727 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9728 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9729 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9730 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9731 VkResult err;
9732
9733 ASSERT_NO_FATAL_FAILURE(InitState());
9734 VkDescriptorPoolSize ds_type_count[2] = {};
9735 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9736 ds_type_count[0].descriptorCount = 1;
9737 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9738 ds_type_count[1].descriptorCount = 1;
9739
9740 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9741 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9742 ds_pool_ci.pNext = NULL;
9743 ds_pool_ci.maxSets = 1;
9744 ds_pool_ci.poolSizeCount = 2;
9745 ds_pool_ci.pPoolSizes = ds_type_count;
9746
9747 VkDescriptorPool ds_pool;
9748 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9749 ASSERT_VK_SUCCESS(err);
9750
9751 // Create layout with single uniform buffer & single storage buffer descriptor
9752 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9753 dsl_binding[0].binding = 0;
9754 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9755 dsl_binding[0].descriptorCount = 1;
9756 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9757 dsl_binding[0].pImmutableSamplers = NULL;
9758 dsl_binding[1].binding = 1;
9759 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9760 dsl_binding[1].descriptorCount = 1;
9761 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9762 dsl_binding[1].pImmutableSamplers = NULL;
9763
9764 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9765 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9766 ds_layout_ci.pNext = NULL;
9767 ds_layout_ci.bindingCount = 2;
9768 ds_layout_ci.pBindings = dsl_binding;
9769 VkDescriptorSetLayout ds_layout;
9770 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9771 ASSERT_VK_SUCCESS(err);
9772
9773 VkDescriptorSet descriptor_set = {};
9774 VkDescriptorSetAllocateInfo alloc_info = {};
9775 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9776 alloc_info.descriptorSetCount = 1;
9777 alloc_info.descriptorPool = ds_pool;
9778 alloc_info.pSetLayouts = &ds_layout;
9779 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9780 ASSERT_VK_SUCCESS(err);
9781
9782 // Create a buffer to be used for invalid updates
9783 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9784 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9785 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9786 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9787 VkBufferCreateInfo ub_ci = {};
9788 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9789 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9790 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9791 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9792 VkBuffer uniform_buffer;
9793 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9794 ASSERT_VK_SUCCESS(err);
9795 VkBufferCreateInfo sb_ci = {};
9796 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9797 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9798 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9799 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9800 VkBuffer storage_buffer;
9801 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9802 ASSERT_VK_SUCCESS(err);
9803 // Have to bind memory to buffer before descriptor update
9804 VkMemoryAllocateInfo mem_alloc = {};
9805 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9806 mem_alloc.pNext = NULL;
9807 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9808 mem_alloc.memoryTypeIndex = 0;
9809
Cort Stratton77a0d592017-02-17 13:14:13 -08009810 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9811 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9812 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9813 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9814 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009815 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009816 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009817 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009818 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9819 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009820 return;
9821 }
9822
9823 VkDeviceMemory mem;
9824 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009825 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009826 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009827 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9828 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9829 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9830 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9831 return;
9832 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009833 ASSERT_VK_SUCCESS(err);
9834 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9835 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009836 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009837 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9838 ASSERT_VK_SUCCESS(err);
9839
9840 VkDescriptorBufferInfo buff_info = {};
9841 buff_info.buffer = uniform_buffer;
9842 buff_info.range = ub_ci.size; // This will exceed limit
9843 VkWriteDescriptorSet descriptor_write = {};
9844 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9845 descriptor_write.dstBinding = 0;
9846 descriptor_write.descriptorCount = 1;
9847 descriptor_write.pTexelBufferView = nullptr;
9848 descriptor_write.pBufferInfo = &buff_info;
9849 descriptor_write.pImageInfo = nullptr;
9850
9851 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9852 descriptor_write.dstSet = descriptor_set;
9853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9854 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9855 m_errorMonitor->VerifyFound();
9856
9857 // Reduce size of range to acceptable limit & cause offset error
9858 buff_info.range = max_ub_range;
9859 buff_info.offset = min_ub_align - 1;
9860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9861 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9862 m_errorMonitor->VerifyFound();
9863
9864 // Now break storage updates
9865 buff_info.buffer = storage_buffer;
9866 buff_info.range = sb_ci.size; // This will exceed limit
9867 buff_info.offset = 0; // Reset offset for this update
9868
9869 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9870 descriptor_write.dstBinding = 1;
9871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9872 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9873 m_errorMonitor->VerifyFound();
9874
9875 // Reduce size of range to acceptable limit & cause offset error
9876 buff_info.range = max_sb_range;
9877 buff_info.offset = min_sb_align - 1;
9878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9879 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9880 m_errorMonitor->VerifyFound();
9881
9882 vkFreeMemory(m_device->device(), mem, NULL);
9883 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9884 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9885 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9886 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9887}
9888
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009889TEST_F(VkLayerTest, DSAspectBitsErrors) {
9890 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9891 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009892 TEST_DESCRIPTION(
9893 "Attempt to update descriptor sets for images "
9894 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009895 VkResult err;
9896
9897 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07009898 auto depth_format = find_depth_stencil_format(m_device);
9899 if (!depth_format) {
9900 printf(" No Depth + Stencil format found. Skipped.\n");
9901 return;
9902 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009903 VkDescriptorPoolSize ds_type_count = {};
9904 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9905 ds_type_count.descriptorCount = 1;
9906
9907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9909 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -07009910 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009911 ds_pool_ci.maxSets = 5;
9912 ds_pool_ci.poolSizeCount = 1;
9913 ds_pool_ci.pPoolSizes = &ds_type_count;
9914
9915 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009916 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009917 ASSERT_VK_SUCCESS(err);
9918
9919 VkDescriptorSetLayoutBinding dsl_binding = {};
9920 dsl_binding.binding = 0;
9921 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9922 dsl_binding.descriptorCount = 1;
9923 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9924 dsl_binding.pImmutableSamplers = NULL;
9925
9926 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9927 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9928 ds_layout_ci.pNext = NULL;
9929 ds_layout_ci.bindingCount = 1;
9930 ds_layout_ci.pBindings = &dsl_binding;
9931 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009932 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009933 ASSERT_VK_SUCCESS(err);
9934
9935 VkDescriptorSet descriptor_set = {};
9936 VkDescriptorSetAllocateInfo alloc_info = {};
9937 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9938 alloc_info.descriptorSetCount = 1;
9939 alloc_info.descriptorPool = ds_pool;
9940 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009941 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009942 ASSERT_VK_SUCCESS(err);
9943
9944 // Create an image to be used for invalid updates
9945 VkImageCreateInfo image_ci = {};
9946 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9947 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009948 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009949 image_ci.extent.width = 64;
9950 image_ci.extent.height = 64;
9951 image_ci.extent.depth = 1;
9952 image_ci.mipLevels = 1;
9953 image_ci.arrayLayers = 1;
9954 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -07009955 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009956 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9957 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9958 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9959 VkImage image;
9960 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9961 ASSERT_VK_SUCCESS(err);
9962 // Bind memory to image
9963 VkMemoryRequirements mem_reqs;
9964 VkDeviceMemory image_mem;
9965 bool pass;
9966 VkMemoryAllocateInfo mem_alloc = {};
9967 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9968 mem_alloc.pNext = NULL;
9969 mem_alloc.allocationSize = 0;
9970 mem_alloc.memoryTypeIndex = 0;
9971 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9972 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009973 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009974 ASSERT_TRUE(pass);
9975 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9976 ASSERT_VK_SUCCESS(err);
9977 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9978 ASSERT_VK_SUCCESS(err);
9979 // Now create view for image
9980 VkImageViewCreateInfo image_view_ci = {};
9981 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9982 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -07009983 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009984 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9985 image_view_ci.subresourceRange.layerCount = 1;
9986 image_view_ci.subresourceRange.baseArrayLayer = 0;
9987 image_view_ci.subresourceRange.levelCount = 1;
9988 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009989 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009990
9991 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009992 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009993 ASSERT_VK_SUCCESS(err);
9994
9995 VkDescriptorImageInfo img_info = {};
9996 img_info.imageView = image_view;
9997 VkWriteDescriptorSet descriptor_write = {};
9998 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9999 descriptor_write.dstBinding = 0;
10000 descriptor_write.descriptorCount = 1;
10001 descriptor_write.pTexelBufferView = NULL;
10002 descriptor_write.pBufferInfo = NULL;
10003 descriptor_write.pImageInfo = &img_info;
10004 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10005 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010006 const char *error_msg =
10007 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10008 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010010
10011 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10012
10013 m_errorMonitor->VerifyFound();
10014 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10015 vkDestroyImage(m_device->device(), image, NULL);
10016 vkFreeMemory(m_device->device(), image_mem, NULL);
10017 vkDestroyImageView(m_device->device(), image_view, NULL);
10018 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10019 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10020}
10021
Karl Schultz6addd812016-02-02 17:17:23 -070010022TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010023 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010024 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010025
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10027 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10028 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010029
Tobin Ehlis3b780662015-05-28 12:11:26 -060010030 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010031 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010032 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010033 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10034 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010035
10036 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010037 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10038 ds_pool_ci.pNext = NULL;
10039 ds_pool_ci.maxSets = 1;
10040 ds_pool_ci.poolSizeCount = 1;
10041 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010042
Tobin Ehlis3b780662015-05-28 12:11:26 -060010043 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010044 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010045 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010046 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010047 dsl_binding.binding = 0;
10048 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10049 dsl_binding.descriptorCount = 1;
10050 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10051 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010052
Tony Barboureb254902015-07-15 12:50:33 -060010053 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010054 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10055 ds_layout_ci.pNext = NULL;
10056 ds_layout_ci.bindingCount = 1;
10057 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010058
Tobin Ehlis3b780662015-05-28 12:11:26 -060010059 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010060 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010061 ASSERT_VK_SUCCESS(err);
10062
10063 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010064 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010065 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010066 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010067 alloc_info.descriptorPool = ds_pool;
10068 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010069 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010070 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010071
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010072 VkSamplerCreateInfo sampler_ci = {};
10073 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10074 sampler_ci.pNext = NULL;
10075 sampler_ci.magFilter = VK_FILTER_NEAREST;
10076 sampler_ci.minFilter = VK_FILTER_NEAREST;
10077 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10078 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10079 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10080 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10081 sampler_ci.mipLodBias = 1.0;
10082 sampler_ci.anisotropyEnable = VK_FALSE;
10083 sampler_ci.maxAnisotropy = 1;
10084 sampler_ci.compareEnable = VK_FALSE;
10085 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10086 sampler_ci.minLod = 1.0;
10087 sampler_ci.maxLod = 1.0;
10088 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10089 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10090 VkSampler sampler;
10091 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10092 ASSERT_VK_SUCCESS(err);
10093
10094 VkDescriptorImageInfo info = {};
10095 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010096
10097 VkWriteDescriptorSet descriptor_write;
10098 memset(&descriptor_write, 0, sizeof(descriptor_write));
10099 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010100 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010101 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010102 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010103 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010104 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010105
10106 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10107
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010108 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010109
Chia-I Wuf7458c52015-10-26 21:10:41 +080010110 vkDestroySampler(m_device->device(), sampler, NULL);
10111 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10112 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010113}
10114
Karl Schultz6addd812016-02-02 17:17:23 -070010115TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010116 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010117 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010118
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010120
Tobin Ehlis3b780662015-05-28 12:11:26 -060010121 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010122 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010123 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010124 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10125 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010126
10127 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010128 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10129 ds_pool_ci.pNext = NULL;
10130 ds_pool_ci.maxSets = 1;
10131 ds_pool_ci.poolSizeCount = 1;
10132 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010133
Tobin Ehlis3b780662015-05-28 12:11:26 -060010134 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010135 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010136 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010137
Tony Barboureb254902015-07-15 12:50:33 -060010138 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010139 dsl_binding.binding = 0;
10140 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10141 dsl_binding.descriptorCount = 1;
10142 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10143 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010144
10145 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010146 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10147 ds_layout_ci.pNext = NULL;
10148 ds_layout_ci.bindingCount = 1;
10149 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010150
Tobin Ehlis3b780662015-05-28 12:11:26 -060010151 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010152 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010153 ASSERT_VK_SUCCESS(err);
10154
10155 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010156 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010157 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010158 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010159 alloc_info.descriptorPool = ds_pool;
10160 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010161 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010162 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010163
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010164 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10165
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010166 // Correctly update descriptor to avoid "NOT_UPDATED" error
10167 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010168 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010169 buff_info.offset = 0;
10170 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010171
10172 VkWriteDescriptorSet descriptor_write;
10173 memset(&descriptor_write, 0, sizeof(descriptor_write));
10174 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010175 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010176 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010177 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010178 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10179 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010180
10181 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10182
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010183 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010184
Chia-I Wuf7458c52015-10-26 21:10:41 +080010185 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010187}
10188
Karl Schultz6addd812016-02-02 17:17:23 -070010189TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010190 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010191 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010192
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010194
Tobin Ehlis3b780662015-05-28 12:11:26 -060010195 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010196 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010197 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010198 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10199 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010200
10201 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010202 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10203 ds_pool_ci.pNext = NULL;
10204 ds_pool_ci.maxSets = 1;
10205 ds_pool_ci.poolSizeCount = 1;
10206 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010207
Tobin Ehlis3b780662015-05-28 12:11:26 -060010208 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010209 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010210 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010211
Tony Barboureb254902015-07-15 12:50:33 -060010212 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010213 dsl_binding.binding = 0;
10214 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10215 dsl_binding.descriptorCount = 1;
10216 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10217 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010218
10219 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010220 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10221 ds_layout_ci.pNext = NULL;
10222 ds_layout_ci.bindingCount = 1;
10223 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010224 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010225 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010226 ASSERT_VK_SUCCESS(err);
10227
10228 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010229 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010230 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010231 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010232 alloc_info.descriptorPool = ds_pool;
10233 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010234 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010235 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010236
Tony Barboureb254902015-07-15 12:50:33 -060010237 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010238 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10239 sampler_ci.pNext = NULL;
10240 sampler_ci.magFilter = VK_FILTER_NEAREST;
10241 sampler_ci.minFilter = VK_FILTER_NEAREST;
10242 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10243 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10244 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10245 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10246 sampler_ci.mipLodBias = 1.0;
10247 sampler_ci.anisotropyEnable = VK_FALSE;
10248 sampler_ci.maxAnisotropy = 1;
10249 sampler_ci.compareEnable = VK_FALSE;
10250 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10251 sampler_ci.minLod = 1.0;
10252 sampler_ci.maxLod = 1.0;
10253 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10254 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010255
Tobin Ehlis3b780662015-05-28 12:11:26 -060010256 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010257 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010258 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010259
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010260 VkDescriptorImageInfo info = {};
10261 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010262
10263 VkWriteDescriptorSet descriptor_write;
10264 memset(&descriptor_write, 0, sizeof(descriptor_write));
10265 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010266 descriptor_write.dstSet = descriptorSet;
10267 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010268 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010269 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010270 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010271 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010272
10273 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10274
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010275 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010276
Chia-I Wuf7458c52015-10-26 21:10:41 +080010277 vkDestroySampler(m_device->device(), sampler, NULL);
10278 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10279 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010280}
10281
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010282TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10283 // Create layout w/ empty binding and attempt to update it
10284 VkResult err;
10285
10286 ASSERT_NO_FATAL_FAILURE(InitState());
10287
10288 VkDescriptorPoolSize ds_type_count = {};
10289 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10290 ds_type_count.descriptorCount = 1;
10291
10292 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10293 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10294 ds_pool_ci.pNext = NULL;
10295 ds_pool_ci.maxSets = 1;
10296 ds_pool_ci.poolSizeCount = 1;
10297 ds_pool_ci.pPoolSizes = &ds_type_count;
10298
10299 VkDescriptorPool ds_pool;
10300 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10301 ASSERT_VK_SUCCESS(err);
10302
10303 VkDescriptorSetLayoutBinding dsl_binding = {};
10304 dsl_binding.binding = 0;
10305 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10306 dsl_binding.descriptorCount = 0;
10307 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10308 dsl_binding.pImmutableSamplers = NULL;
10309
10310 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10311 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10312 ds_layout_ci.pNext = NULL;
10313 ds_layout_ci.bindingCount = 1;
10314 ds_layout_ci.pBindings = &dsl_binding;
10315 VkDescriptorSetLayout ds_layout;
10316 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10317 ASSERT_VK_SUCCESS(err);
10318
10319 VkDescriptorSet descriptor_set;
10320 VkDescriptorSetAllocateInfo alloc_info = {};
10321 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10322 alloc_info.descriptorSetCount = 1;
10323 alloc_info.descriptorPool = ds_pool;
10324 alloc_info.pSetLayouts = &ds_layout;
10325 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10326 ASSERT_VK_SUCCESS(err);
10327
10328 VkSamplerCreateInfo sampler_ci = {};
10329 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10330 sampler_ci.magFilter = VK_FILTER_NEAREST;
10331 sampler_ci.minFilter = VK_FILTER_NEAREST;
10332 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10333 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10334 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10335 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10336 sampler_ci.mipLodBias = 1.0;
10337 sampler_ci.maxAnisotropy = 1;
10338 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10339 sampler_ci.minLod = 1.0;
10340 sampler_ci.maxLod = 1.0;
10341 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10342
10343 VkSampler sampler;
10344 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10345 ASSERT_VK_SUCCESS(err);
10346
10347 VkDescriptorImageInfo info = {};
10348 info.sampler = sampler;
10349
10350 VkWriteDescriptorSet descriptor_write;
10351 memset(&descriptor_write, 0, sizeof(descriptor_write));
10352 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10353 descriptor_write.dstSet = descriptor_set;
10354 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010355 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010356 // This is the wrong type, but empty binding error will be flagged first
10357 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10358 descriptor_write.pImageInfo = &info;
10359
10360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10361 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10362 m_errorMonitor->VerifyFound();
10363
10364 vkDestroySampler(m_device->device(), sampler, NULL);
10365 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10366 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10367}
10368
Karl Schultz6addd812016-02-02 17:17:23 -070010369TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10370 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10371 // types
10372 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010374 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 -060010375
Tobin Ehlis3b780662015-05-28 12:11:26 -060010376 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010377
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010378 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010379 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10380 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010381
10382 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010383 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10384 ds_pool_ci.pNext = NULL;
10385 ds_pool_ci.maxSets = 1;
10386 ds_pool_ci.poolSizeCount = 1;
10387 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010388
Tobin Ehlis3b780662015-05-28 12:11:26 -060010389 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010390 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010391 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010392 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010393 dsl_binding.binding = 0;
10394 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10395 dsl_binding.descriptorCount = 1;
10396 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10397 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010398
Tony Barboureb254902015-07-15 12:50:33 -060010399 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010400 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10401 ds_layout_ci.pNext = NULL;
10402 ds_layout_ci.bindingCount = 1;
10403 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010404
Tobin Ehlis3b780662015-05-28 12:11:26 -060010405 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010407 ASSERT_VK_SUCCESS(err);
10408
10409 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010410 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010411 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010412 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010413 alloc_info.descriptorPool = ds_pool;
10414 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010415 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010416 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010417
Tony Barboureb254902015-07-15 12:50:33 -060010418 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010419 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10420 sampler_ci.pNext = NULL;
10421 sampler_ci.magFilter = VK_FILTER_NEAREST;
10422 sampler_ci.minFilter = VK_FILTER_NEAREST;
10423 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10424 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10425 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10426 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10427 sampler_ci.mipLodBias = 1.0;
10428 sampler_ci.anisotropyEnable = VK_FALSE;
10429 sampler_ci.maxAnisotropy = 1;
10430 sampler_ci.compareEnable = VK_FALSE;
10431 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10432 sampler_ci.minLod = 1.0;
10433 sampler_ci.maxLod = 1.0;
10434 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10435 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010436 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010437 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010438 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010439
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010440 VkDescriptorImageInfo info = {};
10441 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010442
10443 VkWriteDescriptorSet descriptor_write;
10444 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010445 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010446 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010447 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010448 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010449 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010450 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010451
10452 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10453
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010454 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010455
Chia-I Wuf7458c52015-10-26 21:10:41 +080010456 vkDestroySampler(m_device->device(), sampler, NULL);
10457 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10458 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010459}
10460
Karl Schultz6addd812016-02-02 17:17:23 -070010461TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010462 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010463 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010464
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010466
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010467 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010468 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10469 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010470 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010471 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10472 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010473
10474 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010475 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10476 ds_pool_ci.pNext = NULL;
10477 ds_pool_ci.maxSets = 1;
10478 ds_pool_ci.poolSizeCount = 1;
10479 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010480
10481 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010482 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010483 ASSERT_VK_SUCCESS(err);
10484
10485 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010486 dsl_binding.binding = 0;
10487 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10488 dsl_binding.descriptorCount = 1;
10489 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10490 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010491
10492 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010493 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10494 ds_layout_ci.pNext = NULL;
10495 ds_layout_ci.bindingCount = 1;
10496 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010497 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010498 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010499 ASSERT_VK_SUCCESS(err);
10500
10501 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010502 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010503 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010504 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010505 alloc_info.descriptorPool = ds_pool;
10506 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010507 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010508 ASSERT_VK_SUCCESS(err);
10509
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010510 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010511
10512 VkDescriptorImageInfo descriptor_info;
10513 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10514 descriptor_info.sampler = sampler;
10515
10516 VkWriteDescriptorSet descriptor_write;
10517 memset(&descriptor_write, 0, sizeof(descriptor_write));
10518 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010519 descriptor_write.dstSet = descriptorSet;
10520 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010521 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010522 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10523 descriptor_write.pImageInfo = &descriptor_info;
10524
10525 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10526
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010527 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010528
Chia-I Wuf7458c52015-10-26 21:10:41 +080010529 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10530 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010531}
10532
Karl Schultz6addd812016-02-02 17:17:23 -070010533TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10534 // Create a single combined Image/Sampler descriptor and send it an invalid
10535 // imageView
10536 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010537
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010539
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010540 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010541 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010542 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10543 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010544
10545 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010546 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10547 ds_pool_ci.pNext = NULL;
10548 ds_pool_ci.maxSets = 1;
10549 ds_pool_ci.poolSizeCount = 1;
10550 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010551
10552 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010553 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010554 ASSERT_VK_SUCCESS(err);
10555
10556 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010557 dsl_binding.binding = 0;
10558 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10559 dsl_binding.descriptorCount = 1;
10560 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10561 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010562
10563 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010564 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10565 ds_layout_ci.pNext = NULL;
10566 ds_layout_ci.bindingCount = 1;
10567 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010568 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010569 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010570 ASSERT_VK_SUCCESS(err);
10571
10572 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010573 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010574 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010575 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010576 alloc_info.descriptorPool = ds_pool;
10577 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010578 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010579 ASSERT_VK_SUCCESS(err);
10580
10581 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010582 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10583 sampler_ci.pNext = NULL;
10584 sampler_ci.magFilter = VK_FILTER_NEAREST;
10585 sampler_ci.minFilter = VK_FILTER_NEAREST;
10586 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10587 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10588 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10589 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10590 sampler_ci.mipLodBias = 1.0;
10591 sampler_ci.anisotropyEnable = VK_FALSE;
10592 sampler_ci.maxAnisotropy = 1;
10593 sampler_ci.compareEnable = VK_FALSE;
10594 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10595 sampler_ci.minLod = 1.0;
10596 sampler_ci.maxLod = 1.0;
10597 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10598 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010599
10600 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010601 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010602 ASSERT_VK_SUCCESS(err);
10603
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010604 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010605
10606 VkDescriptorImageInfo descriptor_info;
10607 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10608 descriptor_info.sampler = sampler;
10609 descriptor_info.imageView = view;
10610
10611 VkWriteDescriptorSet descriptor_write;
10612 memset(&descriptor_write, 0, sizeof(descriptor_write));
10613 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010614 descriptor_write.dstSet = descriptorSet;
10615 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010616 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010617 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10618 descriptor_write.pImageInfo = &descriptor_info;
10619
10620 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10621
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010622 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010623
Chia-I Wuf7458c52015-10-26 21:10:41 +080010624 vkDestroySampler(m_device->device(), sampler, NULL);
10625 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010627}
10628
Karl Schultz6addd812016-02-02 17:17:23 -070010629TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10630 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10631 // into the other
10632 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010633
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10635 " binding #1 with type "
10636 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10637 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010638
Tobin Ehlis04356f92015-10-27 16:35:27 -060010639 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010640 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010641 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010642 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10643 ds_type_count[0].descriptorCount = 1;
10644 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10645 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010646
10647 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010648 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10649 ds_pool_ci.pNext = NULL;
10650 ds_pool_ci.maxSets = 1;
10651 ds_pool_ci.poolSizeCount = 2;
10652 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010653
10654 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010655 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010656 ASSERT_VK_SUCCESS(err);
10657 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010658 dsl_binding[0].binding = 0;
10659 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10660 dsl_binding[0].descriptorCount = 1;
10661 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10662 dsl_binding[0].pImmutableSamplers = NULL;
10663 dsl_binding[1].binding = 1;
10664 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10665 dsl_binding[1].descriptorCount = 1;
10666 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10667 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010668
10669 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010670 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10671 ds_layout_ci.pNext = NULL;
10672 ds_layout_ci.bindingCount = 2;
10673 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010674
10675 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010676 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010677 ASSERT_VK_SUCCESS(err);
10678
10679 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010680 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010681 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010682 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010683 alloc_info.descriptorPool = ds_pool;
10684 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010685 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010686 ASSERT_VK_SUCCESS(err);
10687
10688 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010689 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10690 sampler_ci.pNext = NULL;
10691 sampler_ci.magFilter = VK_FILTER_NEAREST;
10692 sampler_ci.minFilter = VK_FILTER_NEAREST;
10693 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10694 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10695 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10696 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10697 sampler_ci.mipLodBias = 1.0;
10698 sampler_ci.anisotropyEnable = VK_FALSE;
10699 sampler_ci.maxAnisotropy = 1;
10700 sampler_ci.compareEnable = VK_FALSE;
10701 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10702 sampler_ci.minLod = 1.0;
10703 sampler_ci.maxLod = 1.0;
10704 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10705 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010706
10707 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010708 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010709 ASSERT_VK_SUCCESS(err);
10710
10711 VkDescriptorImageInfo info = {};
10712 info.sampler = sampler;
10713
10714 VkWriteDescriptorSet descriptor_write;
10715 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10716 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010717 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010718 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010719 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010720 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10721 descriptor_write.pImageInfo = &info;
10722 // This write update should succeed
10723 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10724 // Now perform a copy update that fails due to type mismatch
10725 VkCopyDescriptorSet copy_ds_update;
10726 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10727 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10728 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010729 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010730 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010731 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10732 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010733 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10734
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010735 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010736 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010737 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 -060010738 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10739 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10740 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010741 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010742 copy_ds_update.dstSet = descriptorSet;
10743 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010744 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010745 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10746
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010747 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010748
Tobin Ehlis04356f92015-10-27 16:35:27 -060010749 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10751 " binding#1 with offset index of 1 plus "
10752 "update array offset of 0 and update of "
10753 "5 descriptors oversteps total number "
10754 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010755
Tobin Ehlis04356f92015-10-27 16:35:27 -060010756 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10757 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10758 copy_ds_update.srcSet = descriptorSet;
10759 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010760 copy_ds_update.dstSet = descriptorSet;
10761 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010762 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010763 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10764
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010765 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010766
Chia-I Wuf7458c52015-10-26 21:10:41 +080010767 vkDestroySampler(m_device->device(), sampler, NULL);
10768 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10769 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010770}
10771
Karl Schultz6addd812016-02-02 17:17:23 -070010772TEST_F(VkLayerTest, NumSamplesMismatch) {
10773 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10774 // sampleCount
10775 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010778
Tobin Ehlis3b780662015-05-28 12:11:26 -060010779 ASSERT_NO_FATAL_FAILURE(InitState());
10780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010781 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010782 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010783 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010784
10785 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010786 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10787 ds_pool_ci.pNext = NULL;
10788 ds_pool_ci.maxSets = 1;
10789 ds_pool_ci.poolSizeCount = 1;
10790 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010791
Tobin Ehlis3b780662015-05-28 12:11:26 -060010792 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010794 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010795
Tony Barboureb254902015-07-15 12:50:33 -060010796 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010797 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010798 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010799 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010800 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10801 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010802
Tony Barboureb254902015-07-15 12:50:33 -060010803 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10804 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10805 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010806 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010807 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010808
Tobin Ehlis3b780662015-05-28 12:11:26 -060010809 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010810 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010811 ASSERT_VK_SUCCESS(err);
10812
10813 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010814 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010815 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010816 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010817 alloc_info.descriptorPool = ds_pool;
10818 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010819 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010820 ASSERT_VK_SUCCESS(err);
10821
Tony Barboureb254902015-07-15 12:50:33 -060010822 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010823 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010824 pipe_ms_state_ci.pNext = NULL;
10825 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10826 pipe_ms_state_ci.sampleShadingEnable = 0;
10827 pipe_ms_state_ci.minSampleShading = 1.0;
10828 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010829
Tony Barboureb254902015-07-15 12:50:33 -060010830 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010831 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10832 pipeline_layout_ci.pNext = NULL;
10833 pipeline_layout_ci.setLayoutCount = 1;
10834 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010835
10836 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010837 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010838 ASSERT_VK_SUCCESS(err);
10839
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010840 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010841 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 -060010842 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010843 VkPipelineObj pipe(m_device);
10844 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010845 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010846 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010847 pipe.SetMSAA(&pipe_ms_state_ci);
10848 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010849
Tony Barbour552f6c02016-12-21 14:34:07 -070010850 m_commandBuffer->BeginCommandBuffer();
10851 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010852 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010853
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010854 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10855 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10856 VkRect2D scissor = {{0, 0}, {16, 16}};
10857 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10858
Mark Young29927482016-05-04 14:38:51 -060010859 // Render triangle (the error should trigger on the attempt to draw).
10860 Draw(3, 1, 0, 0);
10861
10862 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010863 m_commandBuffer->EndRenderPass();
10864 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010865
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010866 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010867
Chia-I Wuf7458c52015-10-26 21:10:41 +080010868 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10869 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10870 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010871}
Mark Young29927482016-05-04 14:38:51 -060010872
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010873TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010874 TEST_DESCRIPTION(
10875 "Hit RenderPass incompatible cases. "
10876 "Initial case is drawing with an active renderpass that's "
10877 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010878 VkResult err;
10879
10880 ASSERT_NO_FATAL_FAILURE(InitState());
10881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10882
10883 VkDescriptorSetLayoutBinding dsl_binding = {};
10884 dsl_binding.binding = 0;
10885 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10886 dsl_binding.descriptorCount = 1;
10887 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10888 dsl_binding.pImmutableSamplers = NULL;
10889
10890 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10891 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10892 ds_layout_ci.pNext = NULL;
10893 ds_layout_ci.bindingCount = 1;
10894 ds_layout_ci.pBindings = &dsl_binding;
10895
10896 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010897 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010898 ASSERT_VK_SUCCESS(err);
10899
10900 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10901 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10902 pipeline_layout_ci.pNext = NULL;
10903 pipeline_layout_ci.setLayoutCount = 1;
10904 pipeline_layout_ci.pSetLayouts = &ds_layout;
10905
10906 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010907 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010908 ASSERT_VK_SUCCESS(err);
10909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010910 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010911 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 -060010912 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010913 // Create a renderpass that will be incompatible with default renderpass
10914 VkAttachmentReference attach = {};
10915 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10916 VkAttachmentReference color_att = {};
10917 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10918 VkSubpassDescription subpass = {};
10919 subpass.inputAttachmentCount = 1;
10920 subpass.pInputAttachments = &attach;
10921 subpass.colorAttachmentCount = 1;
10922 subpass.pColorAttachments = &color_att;
10923 VkRenderPassCreateInfo rpci = {};
10924 rpci.subpassCount = 1;
10925 rpci.pSubpasses = &subpass;
10926 rpci.attachmentCount = 1;
10927 VkAttachmentDescription attach_desc = {};
10928 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010929 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10930 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010931 rpci.pAttachments = &attach_desc;
10932 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10933 VkRenderPass rp;
10934 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10935 VkPipelineObj pipe(m_device);
10936 pipe.AddShader(&vs);
10937 pipe.AddShader(&fs);
10938 pipe.AddColorAttachment();
10939 VkViewport view_port = {};
10940 m_viewports.push_back(view_port);
10941 pipe.SetViewport(m_viewports);
10942 VkRect2D rect = {};
10943 m_scissors.push_back(rect);
10944 pipe.SetScissor(m_scissors);
10945 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10946
10947 VkCommandBufferInheritanceInfo cbii = {};
10948 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10949 cbii.renderPass = rp;
10950 cbii.subpass = 0;
10951 VkCommandBufferBeginInfo cbbi = {};
10952 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10953 cbbi.pInheritanceInfo = &cbii;
10954 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10955 VkRenderPassBeginInfo rpbi = {};
10956 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10957 rpbi.framebuffer = m_framebuffer;
10958 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010959 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10960 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010963 // Render triangle (the error should trigger on the attempt to draw).
10964 Draw(3, 1, 0, 0);
10965
10966 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010967 m_commandBuffer->EndRenderPass();
10968 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010969
10970 m_errorMonitor->VerifyFound();
10971
10972 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10973 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10974 vkDestroyRenderPass(m_device->device(), rp, NULL);
10975}
10976
Mark Youngc89c6312016-03-31 16:03:20 -060010977TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10978 // Create Pipeline where the number of blend attachments doesn't match the
10979 // number of color attachments. In this case, we don't add any color
10980 // blend attachments even though we have a color attachment.
10981 VkResult err;
10982
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010984
10985 ASSERT_NO_FATAL_FAILURE(InitState());
10986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10987 VkDescriptorPoolSize ds_type_count = {};
10988 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10989 ds_type_count.descriptorCount = 1;
10990
10991 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10992 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10993 ds_pool_ci.pNext = NULL;
10994 ds_pool_ci.maxSets = 1;
10995 ds_pool_ci.poolSizeCount = 1;
10996 ds_pool_ci.pPoolSizes = &ds_type_count;
10997
10998 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010999 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011000 ASSERT_VK_SUCCESS(err);
11001
11002 VkDescriptorSetLayoutBinding dsl_binding = {};
11003 dsl_binding.binding = 0;
11004 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11005 dsl_binding.descriptorCount = 1;
11006 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11007 dsl_binding.pImmutableSamplers = NULL;
11008
11009 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11010 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11011 ds_layout_ci.pNext = NULL;
11012 ds_layout_ci.bindingCount = 1;
11013 ds_layout_ci.pBindings = &dsl_binding;
11014
11015 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011016 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011017 ASSERT_VK_SUCCESS(err);
11018
11019 VkDescriptorSet descriptorSet;
11020 VkDescriptorSetAllocateInfo alloc_info = {};
11021 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11022 alloc_info.descriptorSetCount = 1;
11023 alloc_info.descriptorPool = ds_pool;
11024 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011025 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011026 ASSERT_VK_SUCCESS(err);
11027
11028 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011029 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011030 pipe_ms_state_ci.pNext = NULL;
11031 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11032 pipe_ms_state_ci.sampleShadingEnable = 0;
11033 pipe_ms_state_ci.minSampleShading = 1.0;
11034 pipe_ms_state_ci.pSampleMask = NULL;
11035
11036 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11037 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11038 pipeline_layout_ci.pNext = NULL;
11039 pipeline_layout_ci.setLayoutCount = 1;
11040 pipeline_layout_ci.pSetLayouts = &ds_layout;
11041
11042 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011043 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011044 ASSERT_VK_SUCCESS(err);
11045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011046 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011047 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 -060011048 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011049 VkPipelineObj pipe(m_device);
11050 pipe.AddShader(&vs);
11051 pipe.AddShader(&fs);
11052 pipe.SetMSAA(&pipe_ms_state_ci);
11053 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011054 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011055
11056 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11057 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11058 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11059}
Mark Young29927482016-05-04 14:38:51 -060011060
Mark Muellerd4914412016-06-13 17:52:06 -060011061TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011062 TEST_DESCRIPTION(
11063 "Points to a wrong colorAttachment index in a VkClearAttachment "
11064 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011065 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011067
11068 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11069 m_errorMonitor->VerifyFound();
11070}
11071
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011072TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011073 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11074 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011075
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011076 ASSERT_NO_FATAL_FAILURE(InitState());
11077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011078
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011079 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011080 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11081 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011082
11083 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011084 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11085 ds_pool_ci.pNext = NULL;
11086 ds_pool_ci.maxSets = 1;
11087 ds_pool_ci.poolSizeCount = 1;
11088 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011089
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011090 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011091 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011092 ASSERT_VK_SUCCESS(err);
11093
Tony Barboureb254902015-07-15 12:50:33 -060011094 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011095 dsl_binding.binding = 0;
11096 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11097 dsl_binding.descriptorCount = 1;
11098 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11099 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011100
Tony Barboureb254902015-07-15 12:50:33 -060011101 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011102 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11103 ds_layout_ci.pNext = NULL;
11104 ds_layout_ci.bindingCount = 1;
11105 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011106
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011107 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011108 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011109 ASSERT_VK_SUCCESS(err);
11110
11111 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011112 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011113 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011114 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011115 alloc_info.descriptorPool = ds_pool;
11116 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011117 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011118 ASSERT_VK_SUCCESS(err);
11119
Tony Barboureb254902015-07-15 12:50:33 -060011120 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011122 pipe_ms_state_ci.pNext = NULL;
11123 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11124 pipe_ms_state_ci.sampleShadingEnable = 0;
11125 pipe_ms_state_ci.minSampleShading = 1.0;
11126 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011127
Tony Barboureb254902015-07-15 12:50:33 -060011128 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011129 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11130 pipeline_layout_ci.pNext = NULL;
11131 pipeline_layout_ci.setLayoutCount = 1;
11132 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011133
11134 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011136 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011138 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011139 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011140 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011141 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011142
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011143 VkPipelineObj pipe(m_device);
11144 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011145 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011146 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011147 pipe.SetMSAA(&pipe_ms_state_ci);
11148 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011149
Tony Barbour552f6c02016-12-21 14:34:07 -070011150 m_commandBuffer->BeginCommandBuffer();
11151 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011152
Karl Schultz6addd812016-02-02 17:17:23 -070011153 // Main thing we care about for this test is that the VkImage obj we're
11154 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011155 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011156 VkClearAttachment color_attachment;
11157 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11158 color_attachment.clearValue.color.float32[0] = 1.0;
11159 color_attachment.clearValue.color.float32[1] = 1.0;
11160 color_attachment.clearValue.color.float32[2] = 1.0;
11161 color_attachment.clearValue.color.float32[3] = 1.0;
11162 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011163 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011164
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011165 // Call for full-sized FB Color attachment prior to issuing a Draw
11166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011167 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011168 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011169 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011170
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011171 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11172 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11174 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11175 m_errorMonitor->VerifyFound();
11176
11177 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11178 clear_rect.layerCount = 2;
11179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11180 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011181 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011182
Chia-I Wuf7458c52015-10-26 21:10:41 +080011183 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11184 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011186}
11187
Karl Schultz6addd812016-02-02 17:17:23 -070011188TEST_F(VkLayerTest, VtxBufferBadIndex) {
11189 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11192 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011193
Tobin Ehlis502480b2015-06-24 15:53:07 -060011194 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011195 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011197
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011198 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011199 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11200 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011201
11202 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011203 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11204 ds_pool_ci.pNext = NULL;
11205 ds_pool_ci.maxSets = 1;
11206 ds_pool_ci.poolSizeCount = 1;
11207 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011208
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011209 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011210 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011211 ASSERT_VK_SUCCESS(err);
11212
Tony Barboureb254902015-07-15 12:50:33 -060011213 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011214 dsl_binding.binding = 0;
11215 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11216 dsl_binding.descriptorCount = 1;
11217 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11218 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011219
Tony Barboureb254902015-07-15 12:50:33 -060011220 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011221 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11222 ds_layout_ci.pNext = NULL;
11223 ds_layout_ci.bindingCount = 1;
11224 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011225
Tobin Ehlis502480b2015-06-24 15:53:07 -060011226 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011227 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011228 ASSERT_VK_SUCCESS(err);
11229
11230 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011231 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011232 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011233 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011234 alloc_info.descriptorPool = ds_pool;
11235 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011236 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011237 ASSERT_VK_SUCCESS(err);
11238
Tony Barboureb254902015-07-15 12:50:33 -060011239 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011240 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011241 pipe_ms_state_ci.pNext = NULL;
11242 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11243 pipe_ms_state_ci.sampleShadingEnable = 0;
11244 pipe_ms_state_ci.minSampleShading = 1.0;
11245 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011246
Tony Barboureb254902015-07-15 12:50:33 -060011247 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011248 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11249 pipeline_layout_ci.pNext = NULL;
11250 pipeline_layout_ci.setLayoutCount = 1;
11251 pipeline_layout_ci.pSetLayouts = &ds_layout;
11252 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011254 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011255 ASSERT_VK_SUCCESS(err);
11256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011257 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011258 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 -060011259 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011260 VkPipelineObj pipe(m_device);
11261 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011262 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011263 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011264 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011265 pipe.SetViewport(m_viewports);
11266 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011267 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011268
Tony Barbour552f6c02016-12-21 14:34:07 -070011269 m_commandBuffer->BeginCommandBuffer();
11270 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011271 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011272 // Don't care about actual data, just need to get to draw to flag error
11273 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011274 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011275 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011276 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011277
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011278 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011279
Chia-I Wuf7458c52015-10-26 21:10:41 +080011280 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011283}
Mark Muellerdfe37552016-07-07 14:47:42 -060011284
Mark Mueller2ee294f2016-08-04 12:59:48 -060011285TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011286 TEST_DESCRIPTION(
11287 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11288 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011289 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011290
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011291 const char *invalid_queueFamilyIndex_message =
11292 "Invalid queue create request in vkCreateDevice(). Invalid "
11293 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011295 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011296
Mark Mueller880fce52016-08-17 15:23:23 -060011297 // The following test fails with recent NVidia drivers.
11298 // By the time core_validation is reached, the NVidia
11299 // driver has sanitized the invalid condition and core_validation
11300 // is not introduced to the failure condition. This is not the case
11301 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011302 // uint32_t count = static_cast<uint32_t>(~0);
11303 // VkPhysicalDevice physical_device;
11304 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11305 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011308 float queue_priority = 0.0;
11309
11310 VkDeviceQueueCreateInfo queue_create_info = {};
11311 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11312 queue_create_info.queueCount = 1;
11313 queue_create_info.pQueuePriorities = &queue_priority;
11314 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11315
11316 VkPhysicalDeviceFeatures features = m_device->phy().features();
11317 VkDevice testDevice;
11318 VkDeviceCreateInfo device_create_info = {};
11319 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11320 device_create_info.queueCreateInfoCount = 1;
11321 device_create_info.pQueueCreateInfos = &queue_create_info;
11322 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011323 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011324 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11325 m_errorMonitor->VerifyFound();
11326
11327 queue_create_info.queueFamilyIndex = 1;
11328
11329 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11330 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11331 for (unsigned i = 0; i < feature_count; i++) {
11332 if (VK_FALSE == feature_array[i]) {
11333 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011335 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011336 m_errorMonitor->SetUnexpectedError(
11337 "You requested features that are unavailable on this device. You should first query feature availability by "
11338 "calling vkGetPhysicalDeviceFeatures().");
11339 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011340 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11341 m_errorMonitor->VerifyFound();
11342 break;
11343 }
11344 }
11345}
11346
Tobin Ehlis16edf082016-11-21 12:33:49 -070011347TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11348 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11349
11350 ASSERT_NO_FATAL_FAILURE(InitState());
11351
11352 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11353 std::vector<VkDeviceQueueCreateInfo> queue_info;
11354 queue_info.reserve(queue_props.size());
11355 std::vector<std::vector<float>> queue_priorities;
11356 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11357 VkDeviceQueueCreateInfo qi{};
11358 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11359 qi.queueFamilyIndex = i;
11360 qi.queueCount = queue_props[i].queueCount;
11361 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11362 qi.pQueuePriorities = queue_priorities[i].data();
11363 queue_info.push_back(qi);
11364 }
11365
11366 std::vector<const char *> device_extension_names;
11367
11368 VkDevice local_device;
11369 VkDeviceCreateInfo device_create_info = {};
11370 auto features = m_device->phy().features();
11371 // Intentionally disable pipeline stats
11372 features.pipelineStatisticsQuery = VK_FALSE;
11373 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11374 device_create_info.pNext = NULL;
11375 device_create_info.queueCreateInfoCount = queue_info.size();
11376 device_create_info.pQueueCreateInfos = queue_info.data();
11377 device_create_info.enabledLayerCount = 0;
11378 device_create_info.ppEnabledLayerNames = NULL;
11379 device_create_info.pEnabledFeatures = &features;
11380 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11381 ASSERT_VK_SUCCESS(err);
11382
11383 VkQueryPoolCreateInfo qpci{};
11384 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11385 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11386 qpci.queryCount = 1;
11387 VkQueryPool query_pool;
11388
11389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11390 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11391 m_errorMonitor->VerifyFound();
11392
11393 vkDestroyDevice(local_device, nullptr);
11394}
11395
Mark Mueller2ee294f2016-08-04 12:59:48 -060011396TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011397 TEST_DESCRIPTION(
11398 "Use an invalid queue index in a vkCmdWaitEvents call."
11399 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011400
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011401 const char *invalid_queue_index =
11402 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11403 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11404 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011406 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011409
11410 ASSERT_NO_FATAL_FAILURE(InitState());
11411
11412 VkEvent event;
11413 VkEventCreateInfo event_create_info{};
11414 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11415 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11416
Mark Mueller2ee294f2016-08-04 12:59:48 -060011417 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011418 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011419
Tony Barbour552f6c02016-12-21 14:34:07 -070011420 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011421
11422 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011423 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 -060011424 ASSERT_TRUE(image.initialized());
11425 VkImageMemoryBarrier img_barrier = {};
11426 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11427 img_barrier.pNext = NULL;
11428 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11429 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11430 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11431 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11432 img_barrier.image = image.handle();
11433 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011434
11435 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11436 // that layer validation catches the case when it is not.
11437 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011438 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11439 img_barrier.subresourceRange.baseArrayLayer = 0;
11440 img_barrier.subresourceRange.baseMipLevel = 0;
11441 img_barrier.subresourceRange.layerCount = 1;
11442 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011443 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11444 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011445 m_errorMonitor->VerifyFound();
11446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011448
11449 VkQueryPool query_pool;
11450 VkQueryPoolCreateInfo query_pool_create_info = {};
11451 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11452 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11453 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011454 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011456 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011457 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11458
11459 vkEndCommandBuffer(m_commandBuffer->handle());
11460 m_errorMonitor->VerifyFound();
11461
11462 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11463 vkDestroyEvent(m_device->device(), event, nullptr);
11464}
11465
Mark Muellerdfe37552016-07-07 14:47:42 -060011466TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011467 TEST_DESCRIPTION(
11468 "Submit a command buffer using deleted vertex buffer, "
11469 "delete a buffer twice, use an invalid offset for each "
11470 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011471
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011472 const char *deleted_buffer_in_command_buffer =
11473 "Cannot submit cmd buffer "
11474 "using deleted buffer ";
11475 const char *invalid_offset_message =
11476 "vkBindBufferMemory(): "
11477 "memoryOffset is 0x";
11478 const char *invalid_storage_buffer_offset_message =
11479 "vkBindBufferMemory(): "
11480 "storage memoryOffset "
11481 "is 0x";
11482 const char *invalid_texel_buffer_offset_message =
11483 "vkBindBufferMemory(): "
11484 "texel memoryOffset "
11485 "is 0x";
11486 const char *invalid_uniform_buffer_offset_message =
11487 "vkBindBufferMemory(): "
11488 "uniform memoryOffset "
11489 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011490
11491 ASSERT_NO_FATAL_FAILURE(InitState());
11492 ASSERT_NO_FATAL_FAILURE(InitViewport());
11493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11494
11495 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011496 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011497 pipe_ms_state_ci.pNext = NULL;
11498 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11499 pipe_ms_state_ci.sampleShadingEnable = 0;
11500 pipe_ms_state_ci.minSampleShading = 1.0;
11501 pipe_ms_state_ci.pSampleMask = nullptr;
11502
11503 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11504 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11505 VkPipelineLayout pipeline_layout;
11506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011507 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011508 ASSERT_VK_SUCCESS(err);
11509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011510 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11511 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011512 VkPipelineObj pipe(m_device);
11513 pipe.AddShader(&vs);
11514 pipe.AddShader(&fs);
11515 pipe.AddColorAttachment();
11516 pipe.SetMSAA(&pipe_ms_state_ci);
11517 pipe.SetViewport(m_viewports);
11518 pipe.SetScissor(m_scissors);
11519 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11520
Tony Barbour552f6c02016-12-21 14:34:07 -070011521 m_commandBuffer->BeginCommandBuffer();
11522 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011523 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011524
11525 {
11526 // Create and bind a vertex buffer in a reduced scope, which will cause
11527 // it to be deleted upon leaving this scope
11528 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011529 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011530 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11531 draw_verticies.AddVertexInputToPipe(pipe);
11532 }
11533
11534 Draw(1, 0, 0, 0);
11535
Tony Barbour552f6c02016-12-21 14:34:07 -070011536 m_commandBuffer->EndRenderPass();
11537 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011540 QueueCommandBuffer(false);
11541 m_errorMonitor->VerifyFound();
11542
11543 {
11544 // Create and bind a vertex buffer in a reduced scope, and delete it
11545 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011546 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011548 buffer_test.TestDoubleDestroy();
11549 }
11550 m_errorMonitor->VerifyFound();
11551
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011552 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011553 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011554 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011556 m_errorMonitor->SetUnexpectedError(
11557 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11558 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011559 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11560 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011561 m_errorMonitor->VerifyFound();
11562 }
11563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011564 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11565 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011566 // Create and bind a memory buffer with an invalid offset again,
11567 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011569 m_errorMonitor->SetUnexpectedError(
11570 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11571 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011572 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11573 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011574 m_errorMonitor->VerifyFound();
11575 }
11576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011577 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011578 // Create and bind a memory buffer with an invalid offset again, but
11579 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011581 m_errorMonitor->SetUnexpectedError(
11582 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11583 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011584 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11585 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011586 m_errorMonitor->VerifyFound();
11587 }
11588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011589 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011590 // Create and bind a memory buffer with an invalid offset again, but
11591 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011593 m_errorMonitor->SetUnexpectedError(
11594 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11595 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011596 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11597 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011598 m_errorMonitor->VerifyFound();
11599 }
11600
11601 {
11602 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011604 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11605 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011606 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11607 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011608 m_errorMonitor->VerifyFound();
11609 }
11610
11611 {
11612 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011614 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11615 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011616 }
11617 m_errorMonitor->VerifyFound();
11618
11619 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11620}
11621
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011622// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11623TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011624 TEST_DESCRIPTION(
11625 "Hit all possible validation checks associated with the "
11626 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11627 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011628 // 3 in ValidateCmdBufImageLayouts
11629 // * -1 Attempt to submit cmd buf w/ deleted image
11630 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11631 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011632
11633 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070011634 auto depth_format = find_depth_stencil_format(m_device);
11635 if (!depth_format) {
11636 printf(" No Depth + Stencil format found. Skipped.\n");
11637 return;
11638 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011639 // Create src & dst images to use for copy operations
11640 VkImage src_image;
11641 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011642 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011643
11644 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11645 const int32_t tex_width = 32;
11646 const int32_t tex_height = 32;
11647
11648 VkImageCreateInfo image_create_info = {};
11649 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11650 image_create_info.pNext = NULL;
11651 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11652 image_create_info.format = tex_format;
11653 image_create_info.extent.width = tex_width;
11654 image_create_info.extent.height = tex_height;
11655 image_create_info.extent.depth = 1;
11656 image_create_info.mipLevels = 1;
11657 image_create_info.arrayLayers = 4;
11658 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11659 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11660 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011661 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011662 image_create_info.flags = 0;
11663
11664 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11665 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011666 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011667 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11668 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011669 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11670 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11671 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11672 ASSERT_VK_SUCCESS(err);
11673
11674 // Allocate memory
11675 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011676 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011677 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011678 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11679 mem_alloc.pNext = NULL;
11680 mem_alloc.allocationSize = 0;
11681 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011682
11683 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011684 mem_alloc.allocationSize = img_mem_reqs.size;
11685 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011686 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011687 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011688 ASSERT_VK_SUCCESS(err);
11689
11690 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011691 mem_alloc.allocationSize = img_mem_reqs.size;
11692 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011693 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011694 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011695 ASSERT_VK_SUCCESS(err);
11696
11697 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011698 mem_alloc.allocationSize = img_mem_reqs.size;
11699 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011700 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011701 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011702 ASSERT_VK_SUCCESS(err);
11703
11704 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11705 ASSERT_VK_SUCCESS(err);
11706 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11707 ASSERT_VK_SUCCESS(err);
11708 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11709 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011710
Tony Barbour552f6c02016-12-21 14:34:07 -070011711 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011712 VkImageCopy copy_region;
11713 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11714 copy_region.srcSubresource.mipLevel = 0;
11715 copy_region.srcSubresource.baseArrayLayer = 0;
11716 copy_region.srcSubresource.layerCount = 1;
11717 copy_region.srcOffset.x = 0;
11718 copy_region.srcOffset.y = 0;
11719 copy_region.srcOffset.z = 0;
11720 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11721 copy_region.dstSubresource.mipLevel = 0;
11722 copy_region.dstSubresource.baseArrayLayer = 0;
11723 copy_region.dstSubresource.layerCount = 1;
11724 copy_region.dstOffset.x = 0;
11725 copy_region.dstOffset.y = 0;
11726 copy_region.dstOffset.z = 0;
11727 copy_region.extent.width = 1;
11728 copy_region.extent.height = 1;
11729 copy_region.extent.depth = 1;
11730
11731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11732 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011733 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011734 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 -060011735 m_errorMonitor->VerifyFound();
11736 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11738 "Cannot copy from an image whose source layout is "
11739 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11740 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011741 m_errorMonitor->SetUnexpectedError(
11742 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011743 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 -060011744 m_errorMonitor->VerifyFound();
11745 // Final src error is due to bad layout type
11746 m_errorMonitor->SetDesiredFailureMsg(
11747 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11748 "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 -070011749 m_errorMonitor->SetUnexpectedError(
11750 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11751 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011752 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 -060011753 m_errorMonitor->VerifyFound();
11754 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11756 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011757 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011758 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 -060011759 m_errorMonitor->VerifyFound();
11760 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11762 "Cannot copy from an image whose dest layout is "
11763 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11764 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011765 m_errorMonitor->SetUnexpectedError(
11766 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011767 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 -060011768 m_errorMonitor->VerifyFound();
11769 m_errorMonitor->SetDesiredFailureMsg(
11770 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11771 "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 -070011772 m_errorMonitor->SetUnexpectedError(
11773 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11774 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011775 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 -060011776 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011777
Cort3b021012016-12-07 12:00:57 -080011778 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11779 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11780 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11781 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11782 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11783 transfer_dst_image_barrier[0].srcAccessMask = 0;
11784 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11785 transfer_dst_image_barrier[0].image = dst_image;
11786 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11787 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11788 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11789 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11790 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11791 transfer_dst_image_barrier[0].image = depth_image;
11792 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11793 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11794 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11795
11796 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011797 VkClearColorValue color_clear_value = {};
11798 VkImageSubresourceRange clear_range;
11799 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11800 clear_range.baseMipLevel = 0;
11801 clear_range.baseArrayLayer = 0;
11802 clear_range.layerCount = 1;
11803 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011804
Cort3b021012016-12-07 12:00:57 -080011805 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11806 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011809 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011810 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011811 // Fail due to provided layout not matching actual current layout for color clear.
11812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011813 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011814 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011815
Cort530cf382016-12-08 09:59:47 -080011816 VkClearDepthStencilValue depth_clear_value = {};
11817 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011818
11819 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11820 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011823 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011824 m_errorMonitor->VerifyFound();
11825 // Fail due to provided layout not matching actual current layout for depth clear.
11826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011827 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011828 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011829
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011830 // Now cause error due to bad image layout transition in PipelineBarrier
11831 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011832 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011833 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011834 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011835 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011836 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11837 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011838 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11840 "You cannot transition the layout of aspect 1 from "
11841 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11842 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070011843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011844 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11845 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011846 m_errorMonitor->VerifyFound();
11847
11848 // Finally some layout errors at RenderPass create time
11849 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11850 VkAttachmentReference attach = {};
11851 // perf warning for GENERAL layout w/ non-DS input attachment
11852 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11853 VkSubpassDescription subpass = {};
11854 subpass.inputAttachmentCount = 1;
11855 subpass.pInputAttachments = &attach;
11856 VkRenderPassCreateInfo rpci = {};
11857 rpci.subpassCount = 1;
11858 rpci.pSubpasses = &subpass;
11859 rpci.attachmentCount = 1;
11860 VkAttachmentDescription attach_desc = {};
11861 attach_desc.format = VK_FORMAT_UNDEFINED;
11862 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011863 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011864 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11866 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011867 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11868 m_errorMonitor->VerifyFound();
11869 // error w/ non-general layout
11870 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11871
11872 m_errorMonitor->SetDesiredFailureMsg(
11873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11874 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11875 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11876 m_errorMonitor->VerifyFound();
11877 subpass.inputAttachmentCount = 0;
11878 subpass.colorAttachmentCount = 1;
11879 subpass.pColorAttachments = &attach;
11880 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11881 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11883 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011884 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11885 m_errorMonitor->VerifyFound();
11886 // error w/ non-color opt or GENERAL layout for color attachment
11887 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11888 m_errorMonitor->SetDesiredFailureMsg(
11889 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11890 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11891 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11892 m_errorMonitor->VerifyFound();
11893 subpass.colorAttachmentCount = 0;
11894 subpass.pDepthStencilAttachment = &attach;
11895 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11896 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11898 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011899 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11900 m_errorMonitor->VerifyFound();
11901 // error w/ non-ds opt or GENERAL layout for color attachment
11902 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11904 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11905 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011906 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11907 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011908 // For this error we need a valid renderpass so create default one
11909 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11910 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070011911 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011912 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11913 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11914 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11915 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11916 // Can't do a CLEAR load on READ_ONLY initialLayout
11917 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11918 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11919 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11921 " with invalid first layout "
11922 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11923 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011924 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11925 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011926
Cort3b021012016-12-07 12:00:57 -080011927 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11928 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11929 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011930 vkDestroyImage(m_device->device(), src_image, NULL);
11931 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011932 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011933}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011934
Tobin Ehlise0936662016-10-11 08:10:51 -060011935TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11936 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11937 VkResult err;
11938
11939 ASSERT_NO_FATAL_FAILURE(InitState());
11940
11941 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11942 VkImageTiling tiling;
11943 VkFormatProperties format_properties;
11944 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11945 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11946 tiling = VK_IMAGE_TILING_LINEAR;
11947 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11948 tiling = VK_IMAGE_TILING_OPTIMAL;
11949 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011950 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011951 return;
11952 }
11953
11954 VkDescriptorPoolSize ds_type = {};
11955 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11956 ds_type.descriptorCount = 1;
11957
11958 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11959 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11960 ds_pool_ci.maxSets = 1;
11961 ds_pool_ci.poolSizeCount = 1;
11962 ds_pool_ci.pPoolSizes = &ds_type;
11963 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11964
11965 VkDescriptorPool ds_pool;
11966 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11967 ASSERT_VK_SUCCESS(err);
11968
11969 VkDescriptorSetLayoutBinding dsl_binding = {};
11970 dsl_binding.binding = 0;
11971 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11972 dsl_binding.descriptorCount = 1;
11973 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11974 dsl_binding.pImmutableSamplers = NULL;
11975
11976 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11977 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11978 ds_layout_ci.pNext = NULL;
11979 ds_layout_ci.bindingCount = 1;
11980 ds_layout_ci.pBindings = &dsl_binding;
11981
11982 VkDescriptorSetLayout ds_layout;
11983 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11984 ASSERT_VK_SUCCESS(err);
11985
11986 VkDescriptorSetAllocateInfo alloc_info = {};
11987 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11988 alloc_info.descriptorSetCount = 1;
11989 alloc_info.descriptorPool = ds_pool;
11990 alloc_info.pSetLayouts = &ds_layout;
11991 VkDescriptorSet descriptor_set;
11992 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11993 ASSERT_VK_SUCCESS(err);
11994
11995 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11996 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11997 pipeline_layout_ci.pNext = NULL;
11998 pipeline_layout_ci.setLayoutCount = 1;
11999 pipeline_layout_ci.pSetLayouts = &ds_layout;
12000 VkPipelineLayout pipeline_layout;
12001 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12002 ASSERT_VK_SUCCESS(err);
12003
12004 VkImageObj image(m_device);
12005 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
12006 ASSERT_TRUE(image.initialized());
12007 VkImageView view = image.targetView(tex_format);
12008
12009 VkDescriptorImageInfo image_info = {};
12010 image_info.imageView = view;
12011 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12012
12013 VkWriteDescriptorSet descriptor_write = {};
12014 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12015 descriptor_write.dstSet = descriptor_set;
12016 descriptor_write.dstBinding = 0;
12017 descriptor_write.descriptorCount = 1;
12018 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12019 descriptor_write.pImageInfo = &image_info;
12020
12021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12022 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12023 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12024 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12025 m_errorMonitor->VerifyFound();
12026
12027 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12028 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12029 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12030 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12031}
12032
Mark Mueller93b938f2016-08-18 10:27:40 -060012033TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012034 TEST_DESCRIPTION(
12035 "Use vkCmdExecuteCommands with invalid state "
12036 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012037
12038 ASSERT_NO_FATAL_FAILURE(InitState());
12039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12040
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012041 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012042 const char *simultaneous_use_message2 =
12043 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12044 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012045
12046 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012047 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012048 command_buffer_allocate_info.commandPool = m_commandPool;
12049 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12050 command_buffer_allocate_info.commandBufferCount = 1;
12051
12052 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012053 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012054 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12055 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012056 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012057 command_buffer_inheritance_info.renderPass = m_renderPass;
12058 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012059
Mark Mueller93b938f2016-08-18 10:27:40 -060012060 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012061 command_buffer_begin_info.flags =
12062 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012063 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12064
12065 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12066 vkEndCommandBuffer(secondary_command_buffer);
12067
Mark Mueller93b938f2016-08-18 10:27:40 -060012068 VkSubmitInfo submit_info = {};
12069 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12070 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012072
Mark Mueller4042b652016-09-05 22:52:21 -060012073 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012074 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12076 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012077 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012078 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012079 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12080 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012081
Dave Houltonfbf52152017-01-06 12:55:29 -070012082 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012083 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012084 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012085
Mark Mueller4042b652016-09-05 22:52:21 -060012086 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012087 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12088 m_errorMonitor->SetUnexpectedError(
12089 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12090 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012091 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012092 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12095 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012096 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012097 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12098 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012099
12100 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012101
12102 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012103}
12104
Tony Barbour626994c2017-02-08 15:29:37 -070012105TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12106 TEST_DESCRIPTION(
12107 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12108 "errors");
12109 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12110 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12111 ASSERT_NO_FATAL_FAILURE(InitState());
12112
12113 VkCommandBuffer cmd_bufs[2];
12114 VkCommandBufferAllocateInfo alloc_info;
12115 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12116 alloc_info.pNext = NULL;
12117 alloc_info.commandBufferCount = 2;
12118 alloc_info.commandPool = m_commandPool;
12119 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12120 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12121
12122 VkCommandBufferBeginInfo cb_binfo;
12123 cb_binfo.pNext = NULL;
12124 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12125 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12126 cb_binfo.flags = 0;
12127 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12128 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12129 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12130 vkEndCommandBuffer(cmd_bufs[0]);
12131 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12132
12133 VkSubmitInfo submit_info = {};
12134 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12135 submit_info.commandBufferCount = 2;
12136 submit_info.pCommandBuffers = duplicates;
12137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12138 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12139 m_errorMonitor->VerifyFound();
12140 vkQueueWaitIdle(m_device->m_queue);
12141
12142 // Set one time use and now look for one time submit
12143 duplicates[0] = duplicates[1] = cmd_bufs[1];
12144 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12145 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12146 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12147 vkEndCommandBuffer(cmd_bufs[1]);
12148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12149 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12150 m_errorMonitor->VerifyFound();
12151 vkQueueWaitIdle(m_device->m_queue);
12152}
12153
Tobin Ehlisb093da82017-01-19 12:05:27 -070012154TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012155 TEST_DESCRIPTION(
12156 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12157 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012158
12159 ASSERT_NO_FATAL_FAILURE(InitState());
12160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12161
12162 std::vector<const char *> device_extension_names;
12163 auto features = m_device->phy().features();
12164 // Make sure gs & ts are disabled
12165 features.geometryShader = false;
12166 features.tessellationShader = false;
12167 // The sacrificial device object
12168 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12169
12170 VkCommandPoolCreateInfo pool_create_info{};
12171 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12172 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12173
12174 VkCommandPool command_pool;
12175 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12176
12177 VkCommandBufferAllocateInfo cmd = {};
12178 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12179 cmd.pNext = NULL;
12180 cmd.commandPool = command_pool;
12181 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12182 cmd.commandBufferCount = 1;
12183
12184 VkCommandBuffer cmd_buffer;
12185 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12186 ASSERT_VK_SUCCESS(err);
12187
12188 VkEvent event;
12189 VkEventCreateInfo evci = {};
12190 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12191 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12192 ASSERT_VK_SUCCESS(result);
12193
12194 VkCommandBufferBeginInfo cbbi = {};
12195 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12196 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12198 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12199 m_errorMonitor->VerifyFound();
12200
12201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12202 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12203 m_errorMonitor->VerifyFound();
12204
12205 vkDestroyEvent(test_device.handle(), event, NULL);
12206 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12207}
12208
Mark Mueller917f6bc2016-08-30 10:57:19 -060012209TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012210 TEST_DESCRIPTION(
12211 "Use vkCmdExecuteCommands with invalid state "
12212 "in primary and secondary command buffers. "
12213 "Delete objects that are inuse. Call VkQueueSubmit "
12214 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012215
12216 ASSERT_NO_FATAL_FAILURE(InitState());
12217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12218
Tony Barbour552f6c02016-12-21 14:34:07 -070012219 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012220
12221 VkEvent event;
12222 VkEventCreateInfo event_create_info = {};
12223 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12224 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012225 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012226
Tony Barbour552f6c02016-12-21 14:34:07 -070012227 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012228 vkDestroyEvent(m_device->device(), event, nullptr);
12229
12230 VkSubmitInfo submit_info = {};
12231 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12232 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012233 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012235 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12236 m_errorMonitor->VerifyFound();
12237
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012238 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012239 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12240
12241 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12242
Mark Mueller917f6bc2016-08-30 10:57:19 -060012243 VkSemaphoreCreateInfo semaphore_create_info = {};
12244 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12245 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012246 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012247 VkFenceCreateInfo fence_create_info = {};
12248 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12249 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012250 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012251
12252 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012253 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012254 descriptor_pool_type_count.descriptorCount = 1;
12255
12256 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12257 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12258 descriptor_pool_create_info.maxSets = 1;
12259 descriptor_pool_create_info.poolSizeCount = 1;
12260 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012261 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012262
12263 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012264 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012265
12266 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012267 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012268 descriptorset_layout_binding.descriptorCount = 1;
12269 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12270
12271 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012272 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012273 descriptorset_layout_create_info.bindingCount = 1;
12274 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12275
12276 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012277 ASSERT_VK_SUCCESS(
12278 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012279
12280 VkDescriptorSet descriptorset;
12281 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012282 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012283 descriptorset_allocate_info.descriptorSetCount = 1;
12284 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12285 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012286 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012287
Mark Mueller4042b652016-09-05 22:52:21 -060012288 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12289
12290 VkDescriptorBufferInfo buffer_info = {};
12291 buffer_info.buffer = buffer_test.GetBuffer();
12292 buffer_info.offset = 0;
12293 buffer_info.range = 1024;
12294
12295 VkWriteDescriptorSet write_descriptor_set = {};
12296 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12297 write_descriptor_set.dstSet = descriptorset;
12298 write_descriptor_set.descriptorCount = 1;
12299 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12300 write_descriptor_set.pBufferInfo = &buffer_info;
12301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012302 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012304 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12305 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012306
12307 VkPipelineObj pipe(m_device);
12308 pipe.AddColorAttachment();
12309 pipe.AddShader(&vs);
12310 pipe.AddShader(&fs);
12311
12312 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012313 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012314 pipeline_layout_create_info.setLayoutCount = 1;
12315 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12316
12317 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012318 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012319
12320 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12321
Tony Barbour552f6c02016-12-21 14:34:07 -070012322 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012323 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012325 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12326 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12327 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012328
Tony Barbour552f6c02016-12-21 14:34:07 -070012329 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012330
Mark Mueller917f6bc2016-08-30 10:57:19 -060012331 submit_info.signalSemaphoreCount = 1;
12332 submit_info.pSignalSemaphores = &semaphore;
12333 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012334 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012335
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012337 vkDestroyEvent(m_device->device(), event, nullptr);
12338 m_errorMonitor->VerifyFound();
12339
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012341 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12342 m_errorMonitor->VerifyFound();
12343
Jeremy Hayes08369882017-02-02 10:31:06 -070012344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012345 vkDestroyFence(m_device->device(), fence, nullptr);
12346 m_errorMonitor->VerifyFound();
12347
Tobin Ehlis122207b2016-09-01 08:50:06 -070012348 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012349 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12350 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012351 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012352 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12353 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012354 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012355 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12356 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012357 vkDestroyEvent(m_device->device(), event, nullptr);
12358 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012359 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012360 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12361}
12362
Tobin Ehlis2adda372016-09-01 08:51:06 -070012363TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12364 TEST_DESCRIPTION("Delete in-use query pool.");
12365
12366 ASSERT_NO_FATAL_FAILURE(InitState());
12367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12368
12369 VkQueryPool query_pool;
12370 VkQueryPoolCreateInfo query_pool_ci{};
12371 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12372 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12373 query_pool_ci.queryCount = 1;
12374 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012375 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012376 // Reset query pool to create binding with cmd buffer
12377 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12378
Tony Barbour552f6c02016-12-21 14:34:07 -070012379 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012380
12381 VkSubmitInfo submit_info = {};
12382 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12383 submit_info.commandBufferCount = 1;
12384 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12385 // Submit cmd buffer and then destroy query pool while in-flight
12386 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12387
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012389 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12390 m_errorMonitor->VerifyFound();
12391
12392 vkQueueWaitIdle(m_device->m_queue);
12393 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012394 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12395 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012396 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12397}
12398
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012399TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12400 TEST_DESCRIPTION("Delete in-use pipeline.");
12401
12402 ASSERT_NO_FATAL_FAILURE(InitState());
12403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12404
12405 // Empty pipeline layout used for binding PSO
12406 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12407 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12408 pipeline_layout_ci.setLayoutCount = 0;
12409 pipeline_layout_ci.pSetLayouts = NULL;
12410
12411 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012412 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012413 ASSERT_VK_SUCCESS(err);
12414
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012416 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012417 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12418 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012419 // Store pipeline handle so we can actually delete it before test finishes
12420 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012421 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012422 VkPipelineObj pipe(m_device);
12423 pipe.AddShader(&vs);
12424 pipe.AddShader(&fs);
12425 pipe.AddColorAttachment();
12426 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12427 delete_this_pipeline = pipe.handle();
12428
Tony Barbour552f6c02016-12-21 14:34:07 -070012429 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012430 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012431 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012432
Tony Barbour552f6c02016-12-21 14:34:07 -070012433 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012434
12435 VkSubmitInfo submit_info = {};
12436 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12437 submit_info.commandBufferCount = 1;
12438 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12439 // Submit cmd buffer and then pipeline destroyed while in-flight
12440 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012441 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012442 m_errorMonitor->VerifyFound();
12443 // Make sure queue finished and then actually delete pipeline
12444 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012445 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12446 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012447 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12448 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12449}
12450
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012451TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12452 TEST_DESCRIPTION("Delete in-use imageView.");
12453
12454 ASSERT_NO_FATAL_FAILURE(InitState());
12455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12456
12457 VkDescriptorPoolSize ds_type_count;
12458 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12459 ds_type_count.descriptorCount = 1;
12460
12461 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12462 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12463 ds_pool_ci.maxSets = 1;
12464 ds_pool_ci.poolSizeCount = 1;
12465 ds_pool_ci.pPoolSizes = &ds_type_count;
12466
12467 VkDescriptorPool ds_pool;
12468 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12469 ASSERT_VK_SUCCESS(err);
12470
12471 VkSamplerCreateInfo sampler_ci = {};
12472 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12473 sampler_ci.pNext = NULL;
12474 sampler_ci.magFilter = VK_FILTER_NEAREST;
12475 sampler_ci.minFilter = VK_FILTER_NEAREST;
12476 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12477 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12478 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12479 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12480 sampler_ci.mipLodBias = 1.0;
12481 sampler_ci.anisotropyEnable = VK_FALSE;
12482 sampler_ci.maxAnisotropy = 1;
12483 sampler_ci.compareEnable = VK_FALSE;
12484 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12485 sampler_ci.minLod = 1.0;
12486 sampler_ci.maxLod = 1.0;
12487 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12488 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12489 VkSampler sampler;
12490
12491 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12492 ASSERT_VK_SUCCESS(err);
12493
12494 VkDescriptorSetLayoutBinding layout_binding;
12495 layout_binding.binding = 0;
12496 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12497 layout_binding.descriptorCount = 1;
12498 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12499 layout_binding.pImmutableSamplers = NULL;
12500
12501 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12502 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12503 ds_layout_ci.bindingCount = 1;
12504 ds_layout_ci.pBindings = &layout_binding;
12505 VkDescriptorSetLayout ds_layout;
12506 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12507 ASSERT_VK_SUCCESS(err);
12508
12509 VkDescriptorSetAllocateInfo alloc_info = {};
12510 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12511 alloc_info.descriptorSetCount = 1;
12512 alloc_info.descriptorPool = ds_pool;
12513 alloc_info.pSetLayouts = &ds_layout;
12514 VkDescriptorSet descriptor_set;
12515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12516 ASSERT_VK_SUCCESS(err);
12517
12518 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12519 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12520 pipeline_layout_ci.pNext = NULL;
12521 pipeline_layout_ci.setLayoutCount = 1;
12522 pipeline_layout_ci.pSetLayouts = &ds_layout;
12523
12524 VkPipelineLayout pipeline_layout;
12525 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12526 ASSERT_VK_SUCCESS(err);
12527
12528 VkImageObj image(m_device);
12529 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12530 ASSERT_TRUE(image.initialized());
12531
12532 VkImageView view;
12533 VkImageViewCreateInfo ivci = {};
12534 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12535 ivci.image = image.handle();
12536 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12537 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12538 ivci.subresourceRange.layerCount = 1;
12539 ivci.subresourceRange.baseMipLevel = 0;
12540 ivci.subresourceRange.levelCount = 1;
12541 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12542
12543 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12544 ASSERT_VK_SUCCESS(err);
12545
12546 VkDescriptorImageInfo image_info{};
12547 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12548 image_info.imageView = view;
12549 image_info.sampler = sampler;
12550
12551 VkWriteDescriptorSet descriptor_write = {};
12552 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12553 descriptor_write.dstSet = descriptor_set;
12554 descriptor_write.dstBinding = 0;
12555 descriptor_write.descriptorCount = 1;
12556 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12557 descriptor_write.pImageInfo = &image_info;
12558
12559 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12560
12561 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012562 char const *vsSource =
12563 "#version 450\n"
12564 "\n"
12565 "out gl_PerVertex { \n"
12566 " vec4 gl_Position;\n"
12567 "};\n"
12568 "void main(){\n"
12569 " gl_Position = vec4(1);\n"
12570 "}\n";
12571 char const *fsSource =
12572 "#version 450\n"
12573 "\n"
12574 "layout(set=0, binding=0) uniform sampler2D s;\n"
12575 "layout(location=0) out vec4 x;\n"
12576 "void main(){\n"
12577 " x = texture(s, vec2(1));\n"
12578 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012579 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12580 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12581 VkPipelineObj pipe(m_device);
12582 pipe.AddShader(&vs);
12583 pipe.AddShader(&fs);
12584 pipe.AddColorAttachment();
12585 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12586
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012588
Tony Barbour552f6c02016-12-21 14:34:07 -070012589 m_commandBuffer->BeginCommandBuffer();
12590 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012591 // Bind pipeline to cmd buffer
12592 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12593 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12594 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012595
12596 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12597 VkRect2D scissor = {{0, 0}, {16, 16}};
12598 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12599 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12600
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012601 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012602 m_commandBuffer->EndRenderPass();
12603 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012604 // Submit cmd buffer then destroy sampler
12605 VkSubmitInfo submit_info = {};
12606 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12607 submit_info.commandBufferCount = 1;
12608 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12609 // Submit cmd buffer and then destroy imageView while in-flight
12610 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12611
12612 vkDestroyImageView(m_device->device(), view, nullptr);
12613 m_errorMonitor->VerifyFound();
12614 vkQueueWaitIdle(m_device->m_queue);
12615 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012616 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12617 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012618 vkDestroyImageView(m_device->device(), view, NULL);
12619 vkDestroySampler(m_device->device(), sampler, nullptr);
12620 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12621 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12622 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12623}
12624
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012625TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12626 TEST_DESCRIPTION("Delete in-use bufferView.");
12627
12628 ASSERT_NO_FATAL_FAILURE(InitState());
12629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12630
12631 VkDescriptorPoolSize ds_type_count;
12632 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12633 ds_type_count.descriptorCount = 1;
12634
12635 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12636 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12637 ds_pool_ci.maxSets = 1;
12638 ds_pool_ci.poolSizeCount = 1;
12639 ds_pool_ci.pPoolSizes = &ds_type_count;
12640
12641 VkDescriptorPool ds_pool;
12642 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12643 ASSERT_VK_SUCCESS(err);
12644
12645 VkDescriptorSetLayoutBinding layout_binding;
12646 layout_binding.binding = 0;
12647 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12648 layout_binding.descriptorCount = 1;
12649 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12650 layout_binding.pImmutableSamplers = NULL;
12651
12652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12653 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12654 ds_layout_ci.bindingCount = 1;
12655 ds_layout_ci.pBindings = &layout_binding;
12656 VkDescriptorSetLayout ds_layout;
12657 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12658 ASSERT_VK_SUCCESS(err);
12659
12660 VkDescriptorSetAllocateInfo alloc_info = {};
12661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12662 alloc_info.descriptorSetCount = 1;
12663 alloc_info.descriptorPool = ds_pool;
12664 alloc_info.pSetLayouts = &ds_layout;
12665 VkDescriptorSet descriptor_set;
12666 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12667 ASSERT_VK_SUCCESS(err);
12668
12669 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12670 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12671 pipeline_layout_ci.pNext = NULL;
12672 pipeline_layout_ci.setLayoutCount = 1;
12673 pipeline_layout_ci.pSetLayouts = &ds_layout;
12674
12675 VkPipelineLayout pipeline_layout;
12676 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12677 ASSERT_VK_SUCCESS(err);
12678
12679 VkBuffer buffer;
12680 uint32_t queue_family_index = 0;
12681 VkBufferCreateInfo buffer_create_info = {};
12682 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12683 buffer_create_info.size = 1024;
12684 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12685 buffer_create_info.queueFamilyIndexCount = 1;
12686 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12687
12688 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12689 ASSERT_VK_SUCCESS(err);
12690
12691 VkMemoryRequirements memory_reqs;
12692 VkDeviceMemory buffer_memory;
12693
12694 VkMemoryAllocateInfo memory_info = {};
12695 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12696 memory_info.allocationSize = 0;
12697 memory_info.memoryTypeIndex = 0;
12698
12699 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12700 memory_info.allocationSize = memory_reqs.size;
12701 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12702 ASSERT_TRUE(pass);
12703
12704 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12705 ASSERT_VK_SUCCESS(err);
12706 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12707 ASSERT_VK_SUCCESS(err);
12708
12709 VkBufferView view;
12710 VkBufferViewCreateInfo bvci = {};
12711 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12712 bvci.buffer = buffer;
12713 bvci.format = VK_FORMAT_R8_UNORM;
12714 bvci.range = VK_WHOLE_SIZE;
12715
12716 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12717 ASSERT_VK_SUCCESS(err);
12718
12719 VkWriteDescriptorSet descriptor_write = {};
12720 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12721 descriptor_write.dstSet = descriptor_set;
12722 descriptor_write.dstBinding = 0;
12723 descriptor_write.descriptorCount = 1;
12724 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12725 descriptor_write.pTexelBufferView = &view;
12726
12727 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12728
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012729 char const *vsSource =
12730 "#version 450\n"
12731 "\n"
12732 "out gl_PerVertex { \n"
12733 " vec4 gl_Position;\n"
12734 "};\n"
12735 "void main(){\n"
12736 " gl_Position = vec4(1);\n"
12737 "}\n";
12738 char const *fsSource =
12739 "#version 450\n"
12740 "\n"
12741 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12742 "layout(location=0) out vec4 x;\n"
12743 "void main(){\n"
12744 " x = imageLoad(s, 0);\n"
12745 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012746 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12747 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12748 VkPipelineObj pipe(m_device);
12749 pipe.AddShader(&vs);
12750 pipe.AddShader(&fs);
12751 pipe.AddColorAttachment();
12752 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12753
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012755
Tony Barbour552f6c02016-12-21 14:34:07 -070012756 m_commandBuffer->BeginCommandBuffer();
12757 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012758 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12759 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12760 VkRect2D scissor = {{0, 0}, {16, 16}};
12761 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12762 // Bind pipeline to cmd buffer
12763 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12764 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12765 &descriptor_set, 0, nullptr);
12766 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012767 m_commandBuffer->EndRenderPass();
12768 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012769
12770 VkSubmitInfo submit_info = {};
12771 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12772 submit_info.commandBufferCount = 1;
12773 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12774 // Submit cmd buffer and then destroy bufferView while in-flight
12775 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12776
12777 vkDestroyBufferView(m_device->device(), view, nullptr);
12778 m_errorMonitor->VerifyFound();
12779 vkQueueWaitIdle(m_device->m_queue);
12780 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012781 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12782 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012783 vkDestroyBufferView(m_device->device(), view, NULL);
12784 vkDestroyBuffer(m_device->device(), buffer, NULL);
12785 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12786 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12787 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12788 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12789}
12790
Tobin Ehlis209532e2016-09-07 13:52:18 -060012791TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12792 TEST_DESCRIPTION("Delete in-use sampler.");
12793
12794 ASSERT_NO_FATAL_FAILURE(InitState());
12795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12796
12797 VkDescriptorPoolSize ds_type_count;
12798 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12799 ds_type_count.descriptorCount = 1;
12800
12801 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12802 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12803 ds_pool_ci.maxSets = 1;
12804 ds_pool_ci.poolSizeCount = 1;
12805 ds_pool_ci.pPoolSizes = &ds_type_count;
12806
12807 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012808 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012809 ASSERT_VK_SUCCESS(err);
12810
12811 VkSamplerCreateInfo sampler_ci = {};
12812 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12813 sampler_ci.pNext = NULL;
12814 sampler_ci.magFilter = VK_FILTER_NEAREST;
12815 sampler_ci.minFilter = VK_FILTER_NEAREST;
12816 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12817 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12818 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12819 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12820 sampler_ci.mipLodBias = 1.0;
12821 sampler_ci.anisotropyEnable = VK_FALSE;
12822 sampler_ci.maxAnisotropy = 1;
12823 sampler_ci.compareEnable = VK_FALSE;
12824 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12825 sampler_ci.minLod = 1.0;
12826 sampler_ci.maxLod = 1.0;
12827 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12828 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12829 VkSampler sampler;
12830
12831 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12832 ASSERT_VK_SUCCESS(err);
12833
12834 VkDescriptorSetLayoutBinding layout_binding;
12835 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012836 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012837 layout_binding.descriptorCount = 1;
12838 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12839 layout_binding.pImmutableSamplers = NULL;
12840
12841 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12842 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12843 ds_layout_ci.bindingCount = 1;
12844 ds_layout_ci.pBindings = &layout_binding;
12845 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012846 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012847 ASSERT_VK_SUCCESS(err);
12848
12849 VkDescriptorSetAllocateInfo alloc_info = {};
12850 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12851 alloc_info.descriptorSetCount = 1;
12852 alloc_info.descriptorPool = ds_pool;
12853 alloc_info.pSetLayouts = &ds_layout;
12854 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012855 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012856 ASSERT_VK_SUCCESS(err);
12857
12858 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12859 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12860 pipeline_layout_ci.pNext = NULL;
12861 pipeline_layout_ci.setLayoutCount = 1;
12862 pipeline_layout_ci.pSetLayouts = &ds_layout;
12863
12864 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012865 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012866 ASSERT_VK_SUCCESS(err);
12867
12868 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012869 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 -060012870 ASSERT_TRUE(image.initialized());
12871
12872 VkImageView view;
12873 VkImageViewCreateInfo ivci = {};
12874 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12875 ivci.image = image.handle();
12876 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12877 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12878 ivci.subresourceRange.layerCount = 1;
12879 ivci.subresourceRange.baseMipLevel = 0;
12880 ivci.subresourceRange.levelCount = 1;
12881 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12882
12883 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12884 ASSERT_VK_SUCCESS(err);
12885
12886 VkDescriptorImageInfo image_info{};
12887 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12888 image_info.imageView = view;
12889 image_info.sampler = sampler;
12890
12891 VkWriteDescriptorSet descriptor_write = {};
12892 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12893 descriptor_write.dstSet = descriptor_set;
12894 descriptor_write.dstBinding = 0;
12895 descriptor_write.descriptorCount = 1;
12896 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12897 descriptor_write.pImageInfo = &image_info;
12898
12899 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12900
12901 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012902 char const *vsSource =
12903 "#version 450\n"
12904 "\n"
12905 "out gl_PerVertex { \n"
12906 " vec4 gl_Position;\n"
12907 "};\n"
12908 "void main(){\n"
12909 " gl_Position = vec4(1);\n"
12910 "}\n";
12911 char const *fsSource =
12912 "#version 450\n"
12913 "\n"
12914 "layout(set=0, binding=0) uniform sampler2D s;\n"
12915 "layout(location=0) out vec4 x;\n"
12916 "void main(){\n"
12917 " x = texture(s, vec2(1));\n"
12918 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12921 VkPipelineObj pipe(m_device);
12922 pipe.AddShader(&vs);
12923 pipe.AddShader(&fs);
12924 pipe.AddColorAttachment();
12925 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12926
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012928
Tony Barbour552f6c02016-12-21 14:34:07 -070012929 m_commandBuffer->BeginCommandBuffer();
12930 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012931 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012932 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12933 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12934 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012935
12936 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12937 VkRect2D scissor = {{0, 0}, {16, 16}};
12938 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12939 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12940
Tobin Ehlis209532e2016-09-07 13:52:18 -060012941 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012942 m_commandBuffer->EndRenderPass();
12943 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012944 // Submit cmd buffer then destroy sampler
12945 VkSubmitInfo submit_info = {};
12946 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12947 submit_info.commandBufferCount = 1;
12948 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12949 // Submit cmd buffer and then destroy sampler while in-flight
12950 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12951
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012952 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012953 m_errorMonitor->VerifyFound();
12954 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012955
Tobin Ehlis209532e2016-09-07 13:52:18 -060012956 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012957 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12958 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012959 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012960 vkDestroyImageView(m_device->device(), view, NULL);
12961 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12962 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12963 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12964}
12965
Mark Mueller1cd9f412016-08-25 13:23:52 -060012966TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012967 TEST_DESCRIPTION(
12968 "Call VkQueueSubmit with a semaphore that is already "
12969 "signaled but not waited on by the queue. Wait on a "
12970 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012971
12972 ASSERT_NO_FATAL_FAILURE(InitState());
12973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012975 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 -070012976 const char *invalid_fence_wait_message =
12977 " which has not been submitted on a Queue or during "
12978 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012979
Tony Barbour552f6c02016-12-21 14:34:07 -070012980 m_commandBuffer->BeginCommandBuffer();
12981 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012982
12983 VkSemaphoreCreateInfo semaphore_create_info = {};
12984 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12985 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012986 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012987 VkSubmitInfo submit_info = {};
12988 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12989 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012990 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012991 submit_info.signalSemaphoreCount = 1;
12992 submit_info.pSignalSemaphores = &semaphore;
12993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012994 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012995 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012996 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012997 m_commandBuffer->BeginCommandBuffer();
12998 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013000 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13001 m_errorMonitor->VerifyFound();
13002
Mark Mueller1cd9f412016-08-25 13:23:52 -060013003 VkFenceCreateInfo fence_create_info = {};
13004 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13005 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013006 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013009 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13010 m_errorMonitor->VerifyFound();
13011
Mark Mueller4042b652016-09-05 22:52:21 -060013012 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013013 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013014 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13015}
13016
Tobin Ehlis4af23302016-07-19 10:50:30 -060013017TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013018 TEST_DESCRIPTION(
13019 "Bind a secondary command buffer with with a framebuffer "
13020 "that does not match the framebuffer for the active "
13021 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013022 ASSERT_NO_FATAL_FAILURE(InitState());
13023 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13024
13025 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013026 VkAttachmentDescription attachment = {0,
13027 VK_FORMAT_B8G8R8A8_UNORM,
13028 VK_SAMPLE_COUNT_1_BIT,
13029 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13030 VK_ATTACHMENT_STORE_OP_STORE,
13031 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13032 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13033 VK_IMAGE_LAYOUT_UNDEFINED,
13034 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013036 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013038 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013040 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013041
13042 VkRenderPass rp;
13043 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13044 ASSERT_VK_SUCCESS(err);
13045
13046 // A compatible framebuffer.
13047 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 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 -060013049 ASSERT_TRUE(image.initialized());
13050
13051 VkImageViewCreateInfo ivci = {
13052 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13053 nullptr,
13054 0,
13055 image.handle(),
13056 VK_IMAGE_VIEW_TYPE_2D,
13057 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013058 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13059 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013060 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13061 };
13062 VkImageView view;
13063 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13064 ASSERT_VK_SUCCESS(err);
13065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013066 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013067 VkFramebuffer fb;
13068 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13069 ASSERT_VK_SUCCESS(err);
13070
13071 VkCommandBufferAllocateInfo cbai = {};
13072 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13073 cbai.commandPool = m_commandPool;
13074 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13075 cbai.commandBufferCount = 1;
13076
13077 VkCommandBuffer sec_cb;
13078 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13079 ASSERT_VK_SUCCESS(err);
13080 VkCommandBufferBeginInfo cbbi = {};
13081 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013082 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013083 cbii.renderPass = renderPass();
13084 cbii.framebuffer = fb;
13085 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13086 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013087 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 -060013088 cbbi.pInheritanceInfo = &cbii;
13089 vkBeginCommandBuffer(sec_cb, &cbbi);
13090 vkEndCommandBuffer(sec_cb);
13091
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013092 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013093 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13094 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013097 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013098 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13099 m_errorMonitor->VerifyFound();
13100 // Cleanup
13101 vkDestroyImageView(m_device->device(), view, NULL);
13102 vkDestroyRenderPass(m_device->device(), rp, NULL);
13103 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13104}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013105
13106TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013107 TEST_DESCRIPTION(
13108 "If logicOp is available on the device, set it to an "
13109 "invalid value. If logicOp is not available, attempt to "
13110 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013111 ASSERT_NO_FATAL_FAILURE(InitState());
13112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13113
13114 auto features = m_device->phy().features();
13115 // Set the expected error depending on whether or not logicOp available
13116 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13118 "If logic operations feature not "
13119 "enabled, logicOpEnable must be "
13120 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013121 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013123 }
13124 // Create a pipeline using logicOp
13125 VkResult err;
13126
13127 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13128 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13129
13130 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013131 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013132 ASSERT_VK_SUCCESS(err);
13133
13134 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13135 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13136 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013137 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013138 vp_state_ci.pViewports = &vp;
13139 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013140 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013141 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013142
13143 VkPipelineShaderStageCreateInfo shaderStages[2];
13144 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013146 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13147 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013148 shaderStages[0] = vs.GetStageCreateInfo();
13149 shaderStages[1] = fs.GetStageCreateInfo();
13150
13151 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13152 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13153
13154 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13155 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13156 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13157
13158 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13159 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013160 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013161
13162 VkPipelineColorBlendAttachmentState att = {};
13163 att.blendEnable = VK_FALSE;
13164 att.colorWriteMask = 0xf;
13165
13166 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13167 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13168 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13169 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013170 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013171 cb_ci.attachmentCount = 1;
13172 cb_ci.pAttachments = &att;
13173
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013174 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13175 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13176 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13177
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013178 VkGraphicsPipelineCreateInfo gp_ci = {};
13179 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13180 gp_ci.stageCount = 2;
13181 gp_ci.pStages = shaderStages;
13182 gp_ci.pVertexInputState = &vi_ci;
13183 gp_ci.pInputAssemblyState = &ia_ci;
13184 gp_ci.pViewportState = &vp_state_ci;
13185 gp_ci.pRasterizationState = &rs_ci;
13186 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013187 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013188 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13189 gp_ci.layout = pipeline_layout;
13190 gp_ci.renderPass = renderPass();
13191
13192 VkPipelineCacheCreateInfo pc_ci = {};
13193 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13194
13195 VkPipeline pipeline;
13196 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013197 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013198 ASSERT_VK_SUCCESS(err);
13199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013200 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013201 m_errorMonitor->VerifyFound();
13202 if (VK_SUCCESS == err) {
13203 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13204 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013205 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13206 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13207}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013208
Mike Stroyanaccf7692015-05-12 16:00:45 -060013209#if GTEST_IS_THREADSAFE
13210struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013211 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013212 VkEvent event;
13213 bool bailout;
13214};
13215
Karl Schultz6addd812016-02-02 17:17:23 -070013216extern "C" void *AddToCommandBuffer(void *arg) {
13217 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013218
Mike Stroyana6d14942016-07-13 15:10:05 -060013219 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013220 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013221 if (data->bailout) {
13222 break;
13223 }
13224 }
13225 return NULL;
13226}
13227
Karl Schultz6addd812016-02-02 17:17:23 -070013228TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013229 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013232
Mike Stroyanaccf7692015-05-12 16:00:45 -060013233 ASSERT_NO_FATAL_FAILURE(InitState());
13234 ASSERT_NO_FATAL_FAILURE(InitViewport());
13235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13236
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013237 // Calls AllocateCommandBuffers
13238 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013239
13240 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013241 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013242
13243 VkEventCreateInfo event_info;
13244 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013245 VkResult err;
13246
13247 memset(&event_info, 0, sizeof(event_info));
13248 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13249
Chia-I Wuf7458c52015-10-26 21:10:41 +080013250 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013251 ASSERT_VK_SUCCESS(err);
13252
Mike Stroyanaccf7692015-05-12 16:00:45 -060013253 err = vkResetEvent(device(), event);
13254 ASSERT_VK_SUCCESS(err);
13255
13256 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013257 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013258 data.event = event;
13259 data.bailout = false;
13260 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013261
13262 // First do some correct operations using multiple threads.
13263 // Add many entries to command buffer from another thread.
13264 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13265 // Make non-conflicting calls from this thread at the same time.
13266 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013267 uint32_t count;
13268 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013269 }
13270 test_platform_thread_join(thread, NULL);
13271
13272 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013273 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013274 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013275 // Add many entries to command buffer from this thread at the same time.
13276 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013277
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013278 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013279 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013280
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013281 m_errorMonitor->SetBailout(NULL);
13282
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013283 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013284
Chia-I Wuf7458c52015-10-26 21:10:41 +080013285 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013286}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013287#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013288
Karl Schultz6addd812016-02-02 17:17:23 -070013289TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013290 TEST_DESCRIPTION(
13291 "Test that an error is produced for a spirv module "
13292 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013295
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013296 ASSERT_NO_FATAL_FAILURE(InitState());
13297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13298
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013299 VkShaderModule module;
13300 VkShaderModuleCreateInfo moduleCreateInfo;
13301 struct icd_spv_header spv;
13302
13303 spv.magic = ICD_SPV_MAGIC;
13304 spv.version = ICD_SPV_VERSION;
13305 spv.gen_magic = 0;
13306
13307 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13308 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013309 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013310 moduleCreateInfo.codeSize = 4;
13311 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013312 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013313
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013314 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013315}
13316
Karl Schultz6addd812016-02-02 17:17:23 -070013317TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013318 TEST_DESCRIPTION(
13319 "Test that an error is produced for a spirv module "
13320 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013323
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013324 ASSERT_NO_FATAL_FAILURE(InitState());
13325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13326
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013327 VkShaderModule module;
13328 VkShaderModuleCreateInfo moduleCreateInfo;
13329 struct icd_spv_header spv;
13330
13331 spv.magic = ~ICD_SPV_MAGIC;
13332 spv.version = ICD_SPV_VERSION;
13333 spv.gen_magic = 0;
13334
13335 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13336 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013337 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013338 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13339 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013340 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013341
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013342 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013343}
13344
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013345#if 0
13346// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013347TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013349 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013350
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013351 ASSERT_NO_FATAL_FAILURE(InitState());
13352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13353
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013354 VkShaderModule module;
13355 VkShaderModuleCreateInfo moduleCreateInfo;
13356 struct icd_spv_header spv;
13357
13358 spv.magic = ICD_SPV_MAGIC;
13359 spv.version = ~ICD_SPV_VERSION;
13360 spv.gen_magic = 0;
13361
13362 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13363 moduleCreateInfo.pNext = NULL;
13364
Karl Schultz6addd812016-02-02 17:17:23 -070013365 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013366 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13367 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013368 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013369
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013370 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013371}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013372#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013373
Karl Schultz6addd812016-02-02 17:17:23 -070013374TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013375 TEST_DESCRIPTION(
13376 "Test that a warning is produced for a vertex output that "
13377 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013379
Chris Forbes9f7ff632015-05-25 11:13:08 +120013380 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013382
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013383 char const *vsSource =
13384 "#version 450\n"
13385 "\n"
13386 "layout(location=0) out float x;\n"
13387 "out gl_PerVertex {\n"
13388 " vec4 gl_Position;\n"
13389 "};\n"
13390 "void main(){\n"
13391 " gl_Position = vec4(1);\n"
13392 " x = 0;\n"
13393 "}\n";
13394 char const *fsSource =
13395 "#version 450\n"
13396 "\n"
13397 "layout(location=0) out vec4 color;\n"
13398 "void main(){\n"
13399 " color = vec4(1);\n"
13400 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013401
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013402 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13403 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013404
13405 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013406 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013407 pipe.AddShader(&vs);
13408 pipe.AddShader(&fs);
13409
Chris Forbes9f7ff632015-05-25 11:13:08 +120013410 VkDescriptorSetObj descriptorSet(m_device);
13411 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013412 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013413
Tony Barbour5781e8f2015-08-04 16:23:11 -060013414 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013415
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013416 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013417}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013418
Mark Mueller098c9cb2016-09-08 09:01:57 -060013419TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13420 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13421
13422 ASSERT_NO_FATAL_FAILURE(InitState());
13423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13424
13425 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013426 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013428 char const *vsSource =
13429 "#version 450\n"
13430 "\n"
13431 "out gl_PerVertex {\n"
13432 " vec4 gl_Position;\n"
13433 "};\n"
13434 "void main(){\n"
13435 " gl_Position = vec4(1);\n"
13436 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013437
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013438 char const *fsSource =
13439 "#version 450\n"
13440 "\n"
13441 "layout (constant_id = 0) const float r = 0.0f;\n"
13442 "layout(location = 0) out vec4 uFragColor;\n"
13443 "void main(){\n"
13444 " uFragColor = vec4(r,1,0,1);\n"
13445 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013446
13447 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13448 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13449
13450 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13451 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13452
13453 VkPipelineLayout pipeline_layout;
13454 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13455
13456 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13457 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13458 vp_state_create_info.viewportCount = 1;
13459 VkViewport viewport = {};
13460 vp_state_create_info.pViewports = &viewport;
13461 vp_state_create_info.scissorCount = 1;
13462 VkRect2D scissors = {};
13463 vp_state_create_info.pScissors = &scissors;
13464
13465 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13466
13467 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13468 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13469 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13470 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13471
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013472 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013473
13474 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13475 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13476
13477 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13478 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13479 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13480
13481 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13482 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13483 rasterization_state_create_info.pNext = nullptr;
13484 rasterization_state_create_info.lineWidth = 1.0f;
13485 rasterization_state_create_info.rasterizerDiscardEnable = true;
13486
13487 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13488 color_blend_attachment_state.blendEnable = VK_FALSE;
13489 color_blend_attachment_state.colorWriteMask = 0xf;
13490
13491 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13492 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13493 color_blend_state_create_info.attachmentCount = 1;
13494 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13495
13496 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13497 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13498 graphicspipe_create_info.stageCount = 2;
13499 graphicspipe_create_info.pStages = shader_stage_create_info;
13500 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13501 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13502 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13503 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13504 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13505 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13506 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13507 graphicspipe_create_info.layout = pipeline_layout;
13508 graphicspipe_create_info.renderPass = renderPass();
13509
13510 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13511 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13512
13513 VkPipelineCache pipelineCache;
13514 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13515
13516 // This structure maps constant ids to data locations.
13517 const VkSpecializationMapEntry entry =
13518 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013519 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013520
13521 uint32_t data = 1;
13522
13523 // Set up the info describing spec map and data
13524 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013525 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013526 };
13527 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13528
13529 VkPipeline pipeline;
13530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13531 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13532 m_errorMonitor->VerifyFound();
13533
13534 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13535 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13536}
13537
13538TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13539 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13540
13541 ASSERT_NO_FATAL_FAILURE(InitState());
13542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13543
13544 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13545
13546 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13547 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13548 descriptor_pool_type_count[0].descriptorCount = 1;
13549 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13550 descriptor_pool_type_count[1].descriptorCount = 1;
13551
13552 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13553 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13554 descriptor_pool_create_info.maxSets = 1;
13555 descriptor_pool_create_info.poolSizeCount = 2;
13556 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13557 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13558
13559 VkDescriptorPool descriptorset_pool;
13560 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13561
13562 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13563 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13564 descriptorset_layout_binding.descriptorCount = 1;
13565 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070013566 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013567
13568 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13569 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13570 descriptorset_layout_create_info.bindingCount = 1;
13571 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13572
13573 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013574 ASSERT_VK_SUCCESS(
13575 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013576
13577 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13578 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13579 descriptorset_allocate_info.descriptorSetCount = 1;
13580 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13581 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13582 VkDescriptorSet descriptorset;
13583 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13584
13585 // Challenge core_validation with a non uniform buffer type.
13586 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13587
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013588 char const *vsSource =
13589 "#version 450\n"
13590 "\n"
13591 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13592 " mat4 mvp;\n"
13593 "} ubuf;\n"
13594 "out gl_PerVertex {\n"
13595 " vec4 gl_Position;\n"
13596 "};\n"
13597 "void main(){\n"
13598 " gl_Position = ubuf.mvp * vec4(1);\n"
13599 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013600
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013601 char const *fsSource =
13602 "#version 450\n"
13603 "\n"
13604 "layout(location = 0) out vec4 uFragColor;\n"
13605 "void main(){\n"
13606 " uFragColor = vec4(0,1,0,1);\n"
13607 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013608
13609 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13610 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13611
13612 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13613 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13614 pipeline_layout_create_info.setLayoutCount = 1;
13615 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13616
13617 VkPipelineLayout pipeline_layout;
13618 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13619
13620 VkPipelineObj pipe(m_device);
13621 pipe.AddColorAttachment();
13622 pipe.AddShader(&vs);
13623 pipe.AddShader(&fs);
13624
13625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13626 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13627 m_errorMonitor->VerifyFound();
13628
13629 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13630 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13631 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13632}
13633
13634TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13635 TEST_DESCRIPTION(
13636 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13637
13638 ASSERT_NO_FATAL_FAILURE(InitState());
13639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13640
13641 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13642
13643 VkDescriptorPoolSize descriptor_pool_type_count = {};
13644 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13645 descriptor_pool_type_count.descriptorCount = 1;
13646
13647 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13648 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13649 descriptor_pool_create_info.maxSets = 1;
13650 descriptor_pool_create_info.poolSizeCount = 1;
13651 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13652 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13653
13654 VkDescriptorPool descriptorset_pool;
13655 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13656
13657 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13658 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13659 descriptorset_layout_binding.descriptorCount = 1;
13660 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13661 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070013662 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013663
13664 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13665 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13666 descriptorset_layout_create_info.bindingCount = 1;
13667 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13668
13669 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013670 ASSERT_VK_SUCCESS(
13671 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013672
13673 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13674 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13675 descriptorset_allocate_info.descriptorSetCount = 1;
13676 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13677 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13678 VkDescriptorSet descriptorset;
13679 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13680
13681 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13682
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013683 char const *vsSource =
13684 "#version 450\n"
13685 "\n"
13686 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13687 " mat4 mvp;\n"
13688 "} ubuf;\n"
13689 "out gl_PerVertex {\n"
13690 " vec4 gl_Position;\n"
13691 "};\n"
13692 "void main(){\n"
13693 " gl_Position = ubuf.mvp * vec4(1);\n"
13694 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013695
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013696 char const *fsSource =
13697 "#version 450\n"
13698 "\n"
13699 "layout(location = 0) out vec4 uFragColor;\n"
13700 "void main(){\n"
13701 " uFragColor = vec4(0,1,0,1);\n"
13702 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013703
13704 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13705 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13706
13707 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13708 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13709 pipeline_layout_create_info.setLayoutCount = 1;
13710 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13711
13712 VkPipelineLayout pipeline_layout;
13713 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13714
13715 VkPipelineObj pipe(m_device);
13716 pipe.AddColorAttachment();
13717 pipe.AddShader(&vs);
13718 pipe.AddShader(&fs);
13719
13720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13722 m_errorMonitor->VerifyFound();
13723
13724 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13725 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13726 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13727}
13728
13729TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013730 TEST_DESCRIPTION(
13731 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13732 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013733
13734 ASSERT_NO_FATAL_FAILURE(InitState());
13735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13736
13737 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013738 "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 -060013739
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013740 char const *vsSource =
13741 "#version 450\n"
13742 "\n"
13743 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13744 "out gl_PerVertex {\n"
13745 " vec4 gl_Position;\n"
13746 "};\n"
13747 "void main(){\n"
13748 " gl_Position = vec4(consts.x);\n"
13749 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013750
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013751 char const *fsSource =
13752 "#version 450\n"
13753 "\n"
13754 "layout(location = 0) out vec4 uFragColor;\n"
13755 "void main(){\n"
13756 " uFragColor = vec4(0,1,0,1);\n"
13757 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013758
13759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13761
13762 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13763 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13764
13765 // Set up a push constant range
13766 VkPushConstantRange push_constant_ranges = {};
13767 // Set to the wrong stage to challenge core_validation
13768 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13769 push_constant_ranges.size = 4;
13770
13771 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13772 pipeline_layout_create_info.pushConstantRangeCount = 1;
13773
13774 VkPipelineLayout pipeline_layout;
13775 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13776
13777 VkPipelineObj pipe(m_device);
13778 pipe.AddColorAttachment();
13779 pipe.AddShader(&vs);
13780 pipe.AddShader(&fs);
13781
13782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13783 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13784 m_errorMonitor->VerifyFound();
13785
13786 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13787}
13788
13789TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13790 TEST_DESCRIPTION(
13791 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13792
13793 ASSERT_NO_FATAL_FAILURE(InitState());
13794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13795
13796 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013797 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013798
13799 // Some awkward steps are required to test with custom device features.
13800 std::vector<const char *> device_extension_names;
13801 auto features = m_device->phy().features();
13802 // Disable support for 64 bit floats
13803 features.shaderFloat64 = false;
13804 // The sacrificial device object
13805 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13806
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013807 char const *vsSource =
13808 "#version 450\n"
13809 "\n"
13810 "out gl_PerVertex {\n"
13811 " vec4 gl_Position;\n"
13812 "};\n"
13813 "void main(){\n"
13814 " gl_Position = vec4(1);\n"
13815 "}\n";
13816 char const *fsSource =
13817 "#version 450\n"
13818 "\n"
13819 "layout(location=0) out vec4 color;\n"
13820 "void main(){\n"
13821 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13822 " color = vec4(green);\n"
13823 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013824
13825 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13826 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13827
13828 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013829
13830 VkPipelineObj pipe(&test_device);
13831 pipe.AddColorAttachment();
13832 pipe.AddShader(&vs);
13833 pipe.AddShader(&fs);
13834
13835 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13836 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13837 VkPipelineLayout pipeline_layout;
13838 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13839
13840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13841 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13842 m_errorMonitor->VerifyFound();
13843
13844 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13845}
13846
13847TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13848 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13849
13850 ASSERT_NO_FATAL_FAILURE(InitState());
13851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13852
13853 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13854
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013855 char const *vsSource =
13856 "#version 450\n"
13857 "\n"
13858 "out gl_PerVertex {\n"
13859 " vec4 gl_Position;\n"
13860 "};\n"
13861 "layout(xfb_buffer = 1) out;"
13862 "void main(){\n"
13863 " gl_Position = vec4(1);\n"
13864 "}\n";
13865 char const *fsSource =
13866 "#version 450\n"
13867 "\n"
13868 "layout(location=0) out vec4 color;\n"
13869 "void main(){\n"
13870 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13871 " color = vec4(green);\n"
13872 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013873
13874 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13875 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13876
13877 VkPipelineObj pipe(m_device);
13878 pipe.AddColorAttachment();
13879 pipe.AddShader(&vs);
13880 pipe.AddShader(&fs);
13881
13882 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13883 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13884 VkPipelineLayout pipeline_layout;
13885 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13886
13887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13888 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13889 m_errorMonitor->VerifyFound();
13890
13891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13892}
13893
Karl Schultz6addd812016-02-02 17:17:23 -070013894TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013895 TEST_DESCRIPTION(
13896 "Test that an error is produced for a fragment shader input "
13897 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013900
Chris Forbes59cb88d2015-05-25 11:13:13 +120013901 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013903
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013904 char const *vsSource =
13905 "#version 450\n"
13906 "\n"
13907 "out gl_PerVertex {\n"
13908 " vec4 gl_Position;\n"
13909 "};\n"
13910 "void main(){\n"
13911 " gl_Position = vec4(1);\n"
13912 "}\n";
13913 char const *fsSource =
13914 "#version 450\n"
13915 "\n"
13916 "layout(location=0) in float x;\n"
13917 "layout(location=0) out vec4 color;\n"
13918 "void main(){\n"
13919 " color = vec4(x);\n"
13920 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013921
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013922 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13923 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013924
13925 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013926 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013927 pipe.AddShader(&vs);
13928 pipe.AddShader(&fs);
13929
Chris Forbes59cb88d2015-05-25 11:13:13 +120013930 VkDescriptorSetObj descriptorSet(m_device);
13931 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013932 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013933
Tony Barbour5781e8f2015-08-04 16:23:11 -060013934 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013935
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013936 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013937}
13938
Karl Schultz6addd812016-02-02 17:17:23 -070013939TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013940 TEST_DESCRIPTION(
13941 "Test that an error is produced for a fragment shader input "
13942 "within an interace block, which is not present in the outputs "
13943 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013945
13946 ASSERT_NO_FATAL_FAILURE(InitState());
13947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13948
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013949 char const *vsSource =
13950 "#version 450\n"
13951 "\n"
13952 "out gl_PerVertex {\n"
13953 " vec4 gl_Position;\n"
13954 "};\n"
13955 "void main(){\n"
13956 " gl_Position = vec4(1);\n"
13957 "}\n";
13958 char const *fsSource =
13959 "#version 450\n"
13960 "\n"
13961 "in block { layout(location=0) float x; } ins;\n"
13962 "layout(location=0) out vec4 color;\n"
13963 "void main(){\n"
13964 " color = vec4(ins.x);\n"
13965 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013966
13967 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13968 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13969
13970 VkPipelineObj pipe(m_device);
13971 pipe.AddColorAttachment();
13972 pipe.AddShader(&vs);
13973 pipe.AddShader(&fs);
13974
13975 VkDescriptorSetObj descriptorSet(m_device);
13976 descriptorSet.AppendDummy();
13977 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13978
13979 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13980
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013981 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013982}
13983
Karl Schultz6addd812016-02-02 17:17:23 -070013984TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013985 TEST_DESCRIPTION(
13986 "Test that an error is produced for mismatched array sizes "
13987 "across the vertex->fragment shader interface");
13988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13989 "Type mismatch on location 0.0: 'ptr to "
13990 "output arr[2] of float32' vs 'ptr to "
13991 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013992
13993 ASSERT_NO_FATAL_FAILURE(InitState());
13994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13995
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013996 char const *vsSource =
13997 "#version 450\n"
13998 "\n"
13999 "layout(location=0) out float x[2];\n"
14000 "out gl_PerVertex {\n"
14001 " vec4 gl_Position;\n"
14002 "};\n"
14003 "void main(){\n"
14004 " x[0] = 0; x[1] = 0;\n"
14005 " gl_Position = vec4(1);\n"
14006 "}\n";
14007 char const *fsSource =
14008 "#version 450\n"
14009 "\n"
14010 "layout(location=0) in float x[1];\n"
14011 "layout(location=0) out vec4 color;\n"
14012 "void main(){\n"
14013 " color = vec4(x[0]);\n"
14014 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014015
14016 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14017 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14018
14019 VkPipelineObj pipe(m_device);
14020 pipe.AddColorAttachment();
14021 pipe.AddShader(&vs);
14022 pipe.AddShader(&fs);
14023
14024 VkDescriptorSetObj descriptorSet(m_device);
14025 descriptorSet.AppendDummy();
14026 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14027
14028 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14029
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014030 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014031}
14032
Karl Schultz6addd812016-02-02 17:17:23 -070014033TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014034 TEST_DESCRIPTION(
14035 "Test that an error is produced for mismatched types across "
14036 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014038
Chris Forbesb56af562015-05-25 11:13:17 +120014039 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014041
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014042 char const *vsSource =
14043 "#version 450\n"
14044 "\n"
14045 "layout(location=0) out int x;\n"
14046 "out gl_PerVertex {\n"
14047 " vec4 gl_Position;\n"
14048 "};\n"
14049 "void main(){\n"
14050 " x = 0;\n"
14051 " gl_Position = vec4(1);\n"
14052 "}\n";
14053 char const *fsSource =
14054 "#version 450\n"
14055 "\n"
14056 "layout(location=0) in float x;\n" /* VS writes int */
14057 "layout(location=0) out vec4 color;\n"
14058 "void main(){\n"
14059 " color = vec4(x);\n"
14060 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014061
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014062 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14063 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014064
14065 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014066 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014067 pipe.AddShader(&vs);
14068 pipe.AddShader(&fs);
14069
Chris Forbesb56af562015-05-25 11:13:17 +120014070 VkDescriptorSetObj descriptorSet(m_device);
14071 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014072 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014073
Tony Barbour5781e8f2015-08-04 16:23:11 -060014074 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014075
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014076 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014077}
14078
Karl Schultz6addd812016-02-02 17:17:23 -070014079TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014080 TEST_DESCRIPTION(
14081 "Test that an error is produced for mismatched types across "
14082 "the vertex->fragment shader interface, when the variable is contained within "
14083 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014085
14086 ASSERT_NO_FATAL_FAILURE(InitState());
14087 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14088
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014089 char const *vsSource =
14090 "#version 450\n"
14091 "\n"
14092 "out block { layout(location=0) int x; } outs;\n"
14093 "out gl_PerVertex {\n"
14094 " vec4 gl_Position;\n"
14095 "};\n"
14096 "void main(){\n"
14097 " outs.x = 0;\n"
14098 " gl_Position = vec4(1);\n"
14099 "}\n";
14100 char const *fsSource =
14101 "#version 450\n"
14102 "\n"
14103 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14104 "layout(location=0) out vec4 color;\n"
14105 "void main(){\n"
14106 " color = vec4(ins.x);\n"
14107 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014108
14109 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14110 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14111
14112 VkPipelineObj pipe(m_device);
14113 pipe.AddColorAttachment();
14114 pipe.AddShader(&vs);
14115 pipe.AddShader(&fs);
14116
14117 VkDescriptorSetObj descriptorSet(m_device);
14118 descriptorSet.AppendDummy();
14119 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14120
14121 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14122
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014123 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014124}
14125
14126TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014127 TEST_DESCRIPTION(
14128 "Test that an error is produced for location mismatches across "
14129 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14130 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014131 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 +130014132
14133 ASSERT_NO_FATAL_FAILURE(InitState());
14134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14135
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014136 char const *vsSource =
14137 "#version 450\n"
14138 "\n"
14139 "out block { layout(location=1) float x; } outs;\n"
14140 "out gl_PerVertex {\n"
14141 " vec4 gl_Position;\n"
14142 "};\n"
14143 "void main(){\n"
14144 " outs.x = 0;\n"
14145 " gl_Position = vec4(1);\n"
14146 "}\n";
14147 char const *fsSource =
14148 "#version 450\n"
14149 "\n"
14150 "in block { layout(location=0) float x; } ins;\n"
14151 "layout(location=0) out vec4 color;\n"
14152 "void main(){\n"
14153 " color = vec4(ins.x);\n"
14154 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014155
14156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14158
14159 VkPipelineObj pipe(m_device);
14160 pipe.AddColorAttachment();
14161 pipe.AddShader(&vs);
14162 pipe.AddShader(&fs);
14163
14164 VkDescriptorSetObj descriptorSet(m_device);
14165 descriptorSet.AppendDummy();
14166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14167
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014168 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14170
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014171 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014172}
14173
14174TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014175 TEST_DESCRIPTION(
14176 "Test that an error is produced for component mismatches across the "
14177 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14178 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014179 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 +130014180
14181 ASSERT_NO_FATAL_FAILURE(InitState());
14182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14183
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014184 char const *vsSource =
14185 "#version 450\n"
14186 "\n"
14187 "out block { layout(location=0, component=0) float x; } outs;\n"
14188 "out gl_PerVertex {\n"
14189 " vec4 gl_Position;\n"
14190 "};\n"
14191 "void main(){\n"
14192 " outs.x = 0;\n"
14193 " gl_Position = vec4(1);\n"
14194 "}\n";
14195 char const *fsSource =
14196 "#version 450\n"
14197 "\n"
14198 "in block { layout(location=0, component=1) float x; } ins;\n"
14199 "layout(location=0) out vec4 color;\n"
14200 "void main(){\n"
14201 " color = vec4(ins.x);\n"
14202 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014203
14204 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14205 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14206
14207 VkPipelineObj pipe(m_device);
14208 pipe.AddColorAttachment();
14209 pipe.AddShader(&vs);
14210 pipe.AddShader(&fs);
14211
14212 VkDescriptorSetObj descriptorSet(m_device);
14213 descriptorSet.AppendDummy();
14214 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14215
14216 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14217
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014218 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014219}
14220
Chris Forbes1f3b0152016-11-30 12:48:40 +130014221TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14222 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14223
14224 ASSERT_NO_FATAL_FAILURE(InitState());
14225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14226
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014227 char const *vsSource =
14228 "#version 450\n"
14229 "layout(location=0) out mediump float x;\n"
14230 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14231 char const *fsSource =
14232 "#version 450\n"
14233 "layout(location=0) in highp float x;\n"
14234 "layout(location=0) out vec4 color;\n"
14235 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014236
14237 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14238 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14239
14240 VkPipelineObj pipe(m_device);
14241 pipe.AddColorAttachment();
14242 pipe.AddShader(&vs);
14243 pipe.AddShader(&fs);
14244
14245 VkDescriptorSetObj descriptorSet(m_device);
14246 descriptorSet.AppendDummy();
14247 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14248
14249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14250
14251 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14252
14253 m_errorMonitor->VerifyFound();
14254}
14255
Chris Forbes870a39e2016-11-30 12:55:56 +130014256TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14257 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14258
14259 ASSERT_NO_FATAL_FAILURE(InitState());
14260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14261
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014262 char const *vsSource =
14263 "#version 450\n"
14264 "out block { layout(location=0) mediump float x; };\n"
14265 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14266 char const *fsSource =
14267 "#version 450\n"
14268 "in block { layout(location=0) highp float x; };\n"
14269 "layout(location=0) out vec4 color;\n"
14270 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014271
14272 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14273 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14274
14275 VkPipelineObj pipe(m_device);
14276 pipe.AddColorAttachment();
14277 pipe.AddShader(&vs);
14278 pipe.AddShader(&fs);
14279
14280 VkDescriptorSetObj descriptorSet(m_device);
14281 descriptorSet.AppendDummy();
14282 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14283
14284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14285
14286 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14287
14288 m_errorMonitor->VerifyFound();
14289}
14290
Karl Schultz6addd812016-02-02 17:17:23 -070014291TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014292 TEST_DESCRIPTION(
14293 "Test that a warning is produced for a vertex attribute which is "
14294 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014296
Chris Forbesde136e02015-05-25 11:13:28 +120014297 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014299
14300 VkVertexInputBindingDescription input_binding;
14301 memset(&input_binding, 0, sizeof(input_binding));
14302
14303 VkVertexInputAttributeDescription input_attrib;
14304 memset(&input_attrib, 0, sizeof(input_attrib));
14305 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14306
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014307 char const *vsSource =
14308 "#version 450\n"
14309 "\n"
14310 "out gl_PerVertex {\n"
14311 " vec4 gl_Position;\n"
14312 "};\n"
14313 "void main(){\n"
14314 " gl_Position = vec4(1);\n"
14315 "}\n";
14316 char const *fsSource =
14317 "#version 450\n"
14318 "\n"
14319 "layout(location=0) out vec4 color;\n"
14320 "void main(){\n"
14321 " color = vec4(1);\n"
14322 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014323
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014324 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14325 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014326
14327 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014328 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014329 pipe.AddShader(&vs);
14330 pipe.AddShader(&fs);
14331
14332 pipe.AddVertexInputBindings(&input_binding, 1);
14333 pipe.AddVertexInputAttribs(&input_attrib, 1);
14334
Chris Forbesde136e02015-05-25 11:13:28 +120014335 VkDescriptorSetObj descriptorSet(m_device);
14336 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014337 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014338
Tony Barbour5781e8f2015-08-04 16:23:11 -060014339 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014340
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014341 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014342}
14343
Karl Schultz6addd812016-02-02 17:17:23 -070014344TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014345 TEST_DESCRIPTION(
14346 "Test that a warning is produced for a location mismatch on "
14347 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014349
14350 ASSERT_NO_FATAL_FAILURE(InitState());
14351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14352
14353 VkVertexInputBindingDescription input_binding;
14354 memset(&input_binding, 0, sizeof(input_binding));
14355
14356 VkVertexInputAttributeDescription input_attrib;
14357 memset(&input_attrib, 0, sizeof(input_attrib));
14358 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14359
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014360 char const *vsSource =
14361 "#version 450\n"
14362 "\n"
14363 "layout(location=1) in float x;\n"
14364 "out gl_PerVertex {\n"
14365 " vec4 gl_Position;\n"
14366 "};\n"
14367 "void main(){\n"
14368 " gl_Position = vec4(x);\n"
14369 "}\n";
14370 char const *fsSource =
14371 "#version 450\n"
14372 "\n"
14373 "layout(location=0) out vec4 color;\n"
14374 "void main(){\n"
14375 " color = vec4(1);\n"
14376 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014377
14378 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14379 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14380
14381 VkPipelineObj pipe(m_device);
14382 pipe.AddColorAttachment();
14383 pipe.AddShader(&vs);
14384 pipe.AddShader(&fs);
14385
14386 pipe.AddVertexInputBindings(&input_binding, 1);
14387 pipe.AddVertexInputAttribs(&input_attrib, 1);
14388
14389 VkDescriptorSetObj descriptorSet(m_device);
14390 descriptorSet.AppendDummy();
14391 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14392
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014393 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014394 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14395
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014396 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014397}
14398
Karl Schultz6addd812016-02-02 17:17:23 -070014399TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014400 TEST_DESCRIPTION(
14401 "Test that an error is produced for a vertex shader input which is not "
14402 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14404 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014405
Chris Forbes62e8e502015-05-25 11:13:29 +120014406 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014408
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014409 char const *vsSource =
14410 "#version 450\n"
14411 "\n"
14412 "layout(location=0) in vec4 x;\n" /* not provided */
14413 "out gl_PerVertex {\n"
14414 " vec4 gl_Position;\n"
14415 "};\n"
14416 "void main(){\n"
14417 " gl_Position = x;\n"
14418 "}\n";
14419 char const *fsSource =
14420 "#version 450\n"
14421 "\n"
14422 "layout(location=0) out vec4 color;\n"
14423 "void main(){\n"
14424 " color = vec4(1);\n"
14425 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014426
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014427 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14428 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014429
14430 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014431 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014432 pipe.AddShader(&vs);
14433 pipe.AddShader(&fs);
14434
Chris Forbes62e8e502015-05-25 11:13:29 +120014435 VkDescriptorSetObj descriptorSet(m_device);
14436 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014437 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014438
Tony Barbour5781e8f2015-08-04 16:23:11 -060014439 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014440
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014441 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014442}
14443
Karl Schultz6addd812016-02-02 17:17:23 -070014444TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014445 TEST_DESCRIPTION(
14446 "Test that an error is produced for a mismatch between the "
14447 "fundamental type (float/int/uint) of an attribute and the "
14448 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014449 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 -060014450
Chris Forbesc97d98e2015-05-25 11:13:31 +120014451 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014453
14454 VkVertexInputBindingDescription input_binding;
14455 memset(&input_binding, 0, sizeof(input_binding));
14456
14457 VkVertexInputAttributeDescription input_attrib;
14458 memset(&input_attrib, 0, sizeof(input_attrib));
14459 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14460
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014461 char const *vsSource =
14462 "#version 450\n"
14463 "\n"
14464 "layout(location=0) in int x;\n" /* attrib provided float */
14465 "out gl_PerVertex {\n"
14466 " vec4 gl_Position;\n"
14467 "};\n"
14468 "void main(){\n"
14469 " gl_Position = vec4(x);\n"
14470 "}\n";
14471 char const *fsSource =
14472 "#version 450\n"
14473 "\n"
14474 "layout(location=0) out vec4 color;\n"
14475 "void main(){\n"
14476 " color = vec4(1);\n"
14477 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014478
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014479 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14480 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014481
14482 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014483 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014484 pipe.AddShader(&vs);
14485 pipe.AddShader(&fs);
14486
14487 pipe.AddVertexInputBindings(&input_binding, 1);
14488 pipe.AddVertexInputAttribs(&input_attrib, 1);
14489
Chris Forbesc97d98e2015-05-25 11:13:31 +120014490 VkDescriptorSetObj descriptorSet(m_device);
14491 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014492 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014493
Tony Barbour5781e8f2015-08-04 16:23:11 -060014494 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014495
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014496 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014497}
14498
Chris Forbesc68b43c2016-04-06 11:18:47 +120014499TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014500 TEST_DESCRIPTION(
14501 "Test that an error is produced for a pipeline containing multiple "
14502 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14504 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014505
14506 ASSERT_NO_FATAL_FAILURE(InitState());
14507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14508
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014509 char const *vsSource =
14510 "#version 450\n"
14511 "\n"
14512 "out gl_PerVertex {\n"
14513 " vec4 gl_Position;\n"
14514 "};\n"
14515 "void main(){\n"
14516 " gl_Position = vec4(1);\n"
14517 "}\n";
14518 char const *fsSource =
14519 "#version 450\n"
14520 "\n"
14521 "layout(location=0) out vec4 color;\n"
14522 "void main(){\n"
14523 " color = vec4(1);\n"
14524 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014525
14526 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14527 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14528
14529 VkPipelineObj pipe(m_device);
14530 pipe.AddColorAttachment();
14531 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014532 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014533 pipe.AddShader(&fs);
14534
14535 VkDescriptorSetObj descriptorSet(m_device);
14536 descriptorSet.AppendDummy();
14537 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14538
14539 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14540
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014541 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014542}
14543
Chris Forbes82ff92a2016-09-09 10:50:24 +120014544TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014546
14547 ASSERT_NO_FATAL_FAILURE(InitState());
14548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14549
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014550 char const *vsSource =
14551 "#version 450\n"
14552 "out gl_PerVertex {\n"
14553 " vec4 gl_Position;\n"
14554 "};\n"
14555 "void main(){\n"
14556 " gl_Position = vec4(0);\n"
14557 "}\n";
14558 char const *fsSource =
14559 "#version 450\n"
14560 "\n"
14561 "layout(location=0) out vec4 color;\n"
14562 "void main(){\n"
14563 " color = vec4(1);\n"
14564 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014565
14566 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14567 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14568
14569 VkPipelineObj pipe(m_device);
14570 pipe.AddColorAttachment();
14571 pipe.AddShader(&vs);
14572 pipe.AddShader(&fs);
14573
14574 VkDescriptorSetObj descriptorSet(m_device);
14575 descriptorSet.AppendDummy();
14576 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14577
14578 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14579
14580 m_errorMonitor->VerifyFound();
14581}
14582
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014583TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14585 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14586 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014587
14588 ASSERT_NO_FATAL_FAILURE(InitState());
14589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14590
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014591 char const *vsSource =
14592 "#version 450\n"
14593 "void main(){ gl_Position = vec4(0); }\n";
14594 char const *fsSource =
14595 "#version 450\n"
14596 "\n"
14597 "layout(location=0) out vec4 color;\n"
14598 "void main(){\n"
14599 " color = vec4(1);\n"
14600 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014601
14602 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14603 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14604
14605 VkPipelineObj pipe(m_device);
14606 pipe.AddColorAttachment();
14607 pipe.AddShader(&vs);
14608 pipe.AddShader(&fs);
14609
14610 VkDescriptorSetObj descriptorSet(m_device);
14611 descriptorSet.AppendDummy();
14612 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14613
14614 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014615 {
14616 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14617 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14618 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014619 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014620 {
14621 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14622 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14623 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014624 },
14625 };
14626 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014627 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014628 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014629 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14630 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014631 VkRenderPass rp;
14632 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14633 ASSERT_VK_SUCCESS(err);
14634
14635 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14636
14637 m_errorMonitor->VerifyFound();
14638
14639 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14640}
14641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014642TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014643 TEST_DESCRIPTION(
14644 "Test that an error is produced for a variable output from "
14645 "the TCS without the patch decoration, but consumed in the TES "
14646 "with the decoration.");
14647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14648 "is per-vertex in tessellation control shader stage "
14649 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014650
14651 ASSERT_NO_FATAL_FAILURE(InitState());
14652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14653
Chris Forbesc1e852d2016-04-04 19:26:42 +120014654 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014655 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014656 return;
14657 }
14658
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014659 char const *vsSource =
14660 "#version 450\n"
14661 "void main(){}\n";
14662 char const *tcsSource =
14663 "#version 450\n"
14664 "layout(location=0) out int x[];\n"
14665 "layout(vertices=3) out;\n"
14666 "void main(){\n"
14667 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14668 " gl_TessLevelInner[0] = 1;\n"
14669 " x[gl_InvocationID] = gl_InvocationID;\n"
14670 "}\n";
14671 char const *tesSource =
14672 "#version 450\n"
14673 "layout(triangles, equal_spacing, cw) in;\n"
14674 "layout(location=0) patch in int x;\n"
14675 "out gl_PerVertex { vec4 gl_Position; };\n"
14676 "void main(){\n"
14677 " gl_Position.xyz = gl_TessCoord;\n"
14678 " gl_Position.w = x;\n"
14679 "}\n";
14680 char const *fsSource =
14681 "#version 450\n"
14682 "layout(location=0) out vec4 color;\n"
14683 "void main(){\n"
14684 " color = vec4(1);\n"
14685 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014686
14687 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14688 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14689 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14690 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014692 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14693 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014694
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014695 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014696
14697 VkPipelineObj pipe(m_device);
14698 pipe.SetInputAssembly(&iasci);
14699 pipe.SetTessellation(&tsci);
14700 pipe.AddColorAttachment();
14701 pipe.AddShader(&vs);
14702 pipe.AddShader(&tcs);
14703 pipe.AddShader(&tes);
14704 pipe.AddShader(&fs);
14705
14706 VkDescriptorSetObj descriptorSet(m_device);
14707 descriptorSet.AppendDummy();
14708 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14709
14710 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14711
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014712 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014713}
14714
Karl Schultz6addd812016-02-02 17:17:23 -070014715TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014716 TEST_DESCRIPTION(
14717 "Test that an error is produced for a vertex attribute setup where multiple "
14718 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14720 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014721
Chris Forbes280ba2c2015-06-12 11:16:41 +120014722 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014724
14725 /* Two binding descriptions for binding 0 */
14726 VkVertexInputBindingDescription input_bindings[2];
14727 memset(input_bindings, 0, sizeof(input_bindings));
14728
14729 VkVertexInputAttributeDescription input_attrib;
14730 memset(&input_attrib, 0, sizeof(input_attrib));
14731 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14732
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014733 char const *vsSource =
14734 "#version 450\n"
14735 "\n"
14736 "layout(location=0) in float x;\n" /* attrib provided float */
14737 "out gl_PerVertex {\n"
14738 " vec4 gl_Position;\n"
14739 "};\n"
14740 "void main(){\n"
14741 " gl_Position = vec4(x);\n"
14742 "}\n";
14743 char const *fsSource =
14744 "#version 450\n"
14745 "\n"
14746 "layout(location=0) out vec4 color;\n"
14747 "void main(){\n"
14748 " color = vec4(1);\n"
14749 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014750
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014751 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14752 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014753
14754 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014755 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014756 pipe.AddShader(&vs);
14757 pipe.AddShader(&fs);
14758
14759 pipe.AddVertexInputBindings(input_bindings, 2);
14760 pipe.AddVertexInputAttribs(&input_attrib, 1);
14761
Chris Forbes280ba2c2015-06-12 11:16:41 +120014762 VkDescriptorSetObj descriptorSet(m_device);
14763 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014764 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014765
Tony Barbour5781e8f2015-08-04 16:23:11 -060014766 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014767
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014768 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014769}
Chris Forbes8f68b562015-05-25 11:13:32 +120014770
Karl Schultz6addd812016-02-02 17:17:23 -070014771TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014772 TEST_DESCRIPTION(
14773 "Test that an error is produced for a fragment shader which does not "
14774 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014776
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014777 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +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 "void main(){\n"
14792 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014793
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014794 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14795 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014796
14797 VkPipelineObj pipe(m_device);
14798 pipe.AddShader(&vs);
14799 pipe.AddShader(&fs);
14800
Chia-I Wu08accc62015-07-07 11:50:03 +080014801 /* set up CB 0, not written */
14802 pipe.AddColorAttachment();
14803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014804
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014805 VkDescriptorSetObj descriptorSet(m_device);
14806 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014807 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014808
Tony Barbour5781e8f2015-08-04 16:23:11 -060014809 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014810
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014811 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014812}
14813
Karl Schultz6addd812016-02-02 17:17:23 -070014814TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014815 TEST_DESCRIPTION(
14816 "Test that a warning is produced for a fragment shader which provides a spurious "
14817 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014819 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014820
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014821 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014822
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014823 char const *vsSource =
14824 "#version 450\n"
14825 "\n"
14826 "out gl_PerVertex {\n"
14827 " vec4 gl_Position;\n"
14828 "};\n"
14829 "void main(){\n"
14830 " gl_Position = vec4(1);\n"
14831 "}\n";
14832 char const *fsSource =
14833 "#version 450\n"
14834 "\n"
14835 "layout(location=0) out vec4 x;\n"
14836 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14837 "void main(){\n"
14838 " x = vec4(1);\n"
14839 " y = vec4(1);\n"
14840 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014841
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014842 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14843 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014844
14845 VkPipelineObj pipe(m_device);
14846 pipe.AddShader(&vs);
14847 pipe.AddShader(&fs);
14848
Chia-I Wu08accc62015-07-07 11:50:03 +080014849 /* set up CB 0, not written */
14850 pipe.AddColorAttachment();
14851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014852 /* FS writes CB 1, but we don't configure it */
14853
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014854 VkDescriptorSetObj descriptorSet(m_device);
14855 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014856 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014857
Tony Barbour5781e8f2015-08-04 16:23:11 -060014858 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014859
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014860 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014861}
14862
Karl Schultz6addd812016-02-02 17:17:23 -070014863TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014864 TEST_DESCRIPTION(
14865 "Test that an error is produced for a mismatch between the fundamental "
14866 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014868
Chris Forbesa36d69e2015-05-25 11:13:44 +120014869 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014870
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014871 char const *vsSource =
14872 "#version 450\n"
14873 "\n"
14874 "out gl_PerVertex {\n"
14875 " vec4 gl_Position;\n"
14876 "};\n"
14877 "void main(){\n"
14878 " gl_Position = vec4(1);\n"
14879 "}\n";
14880 char const *fsSource =
14881 "#version 450\n"
14882 "\n"
14883 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14884 "void main(){\n"
14885 " x = ivec4(1);\n"
14886 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014887
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014888 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14889 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014890
14891 VkPipelineObj pipe(m_device);
14892 pipe.AddShader(&vs);
14893 pipe.AddShader(&fs);
14894
Chia-I Wu08accc62015-07-07 11:50:03 +080014895 /* set up CB 0; type is UNORM by default */
14896 pipe.AddColorAttachment();
14897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014898
Chris Forbesa36d69e2015-05-25 11:13:44 +120014899 VkDescriptorSetObj descriptorSet(m_device);
14900 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014901 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014902
Tony Barbour5781e8f2015-08-04 16:23:11 -060014903 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014904
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014905 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014906}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014907
Karl Schultz6addd812016-02-02 17:17:23 -070014908TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014909 TEST_DESCRIPTION(
14910 "Test that an error is produced for a shader consuming a uniform "
14911 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014913
Chris Forbes556c76c2015-08-14 12:04:59 +120014914 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014915
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014916 char const *vsSource =
14917 "#version 450\n"
14918 "\n"
14919 "out gl_PerVertex {\n"
14920 " vec4 gl_Position;\n"
14921 "};\n"
14922 "void main(){\n"
14923 " gl_Position = vec4(1);\n"
14924 "}\n";
14925 char const *fsSource =
14926 "#version 450\n"
14927 "\n"
14928 "layout(location=0) out vec4 x;\n"
14929 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14930 "void main(){\n"
14931 " x = vec4(bar.y);\n"
14932 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014933
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014934 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14935 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014936
Chris Forbes556c76c2015-08-14 12:04:59 +120014937 VkPipelineObj pipe(m_device);
14938 pipe.AddShader(&vs);
14939 pipe.AddShader(&fs);
14940
14941 /* set up CB 0; type is UNORM by default */
14942 pipe.AddColorAttachment();
14943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14944
14945 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014946 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014947
14948 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14949
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014950 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014951}
14952
Chris Forbes5c59e902016-02-26 16:56:09 +130014953TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014954 TEST_DESCRIPTION(
14955 "Test that an error is produced for a shader consuming push constants "
14956 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014958
14959 ASSERT_NO_FATAL_FAILURE(InitState());
14960
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014961 char const *vsSource =
14962 "#version 450\n"
14963 "\n"
14964 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14965 "out gl_PerVertex {\n"
14966 " vec4 gl_Position;\n"
14967 "};\n"
14968 "void main(){\n"
14969 " gl_Position = vec4(consts.x);\n"
14970 "}\n";
14971 char const *fsSource =
14972 "#version 450\n"
14973 "\n"
14974 "layout(location=0) out vec4 x;\n"
14975 "void main(){\n"
14976 " x = vec4(1);\n"
14977 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014978
14979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14981
14982 VkPipelineObj pipe(m_device);
14983 pipe.AddShader(&vs);
14984 pipe.AddShader(&fs);
14985
14986 /* set up CB 0; type is UNORM by default */
14987 pipe.AddColorAttachment();
14988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14989
14990 VkDescriptorSetObj descriptorSet(m_device);
14991 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14992
14993 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14994
14995 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014996 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014997}
14998
Chris Forbes3fb17902016-08-22 14:57:55 +120014999TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015000 TEST_DESCRIPTION(
15001 "Test that an error is produced for a shader consuming an input attachment "
15002 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15004 "consumes input attachment index 0 but not provided in subpass");
15005
15006 ASSERT_NO_FATAL_FAILURE(InitState());
15007
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015008 char const *vsSource =
15009 "#version 450\n"
15010 "\n"
15011 "out gl_PerVertex {\n"
15012 " vec4 gl_Position;\n"
15013 "};\n"
15014 "void main(){\n"
15015 " gl_Position = vec4(1);\n"
15016 "}\n";
15017 char const *fsSource =
15018 "#version 450\n"
15019 "\n"
15020 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15021 "layout(location=0) out vec4 color;\n"
15022 "void main() {\n"
15023 " color = subpassLoad(x);\n"
15024 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015025
15026 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15027 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15028
15029 VkPipelineObj pipe(m_device);
15030 pipe.AddShader(&vs);
15031 pipe.AddShader(&fs);
15032 pipe.AddColorAttachment();
15033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015035 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15036 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015037 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015038 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015039 ASSERT_VK_SUCCESS(err);
15040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015042 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015043 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015044 ASSERT_VK_SUCCESS(err);
15045
15046 // error here.
15047 pipe.CreateVKPipeline(pl, renderPass());
15048
15049 m_errorMonitor->VerifyFound();
15050
15051 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15052 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15053}
15054
Chris Forbes5a9a0472016-08-22 16:02:09 +120015055TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015056 TEST_DESCRIPTION(
15057 "Test that an error is produced for a shader consuming an input attachment "
15058 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15060 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15061
15062 ASSERT_NO_FATAL_FAILURE(InitState());
15063
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015064 char const *vsSource =
15065 "#version 450\n"
15066 "\n"
15067 "out gl_PerVertex {\n"
15068 " vec4 gl_Position;\n"
15069 "};\n"
15070 "void main(){\n"
15071 " gl_Position = vec4(1);\n"
15072 "}\n";
15073 char const *fsSource =
15074 "#version 450\n"
15075 "\n"
15076 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15077 "layout(location=0) out vec4 color;\n"
15078 "void main() {\n"
15079 " color = subpassLoad(x);\n"
15080 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015081
15082 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15083 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15084
15085 VkPipelineObj pipe(m_device);
15086 pipe.AddShader(&vs);
15087 pipe.AddShader(&fs);
15088 pipe.AddColorAttachment();
15089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015091 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15092 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015093 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015094 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015095 ASSERT_VK_SUCCESS(err);
15096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015097 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015098 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015100 ASSERT_VK_SUCCESS(err);
15101
15102 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015103 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15104 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15105 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15106 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15107 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 +120015108 };
15109 VkAttachmentReference color = {
15110 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15111 };
15112 VkAttachmentReference input = {
15113 1, VK_IMAGE_LAYOUT_GENERAL,
15114 };
15115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015116 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015118 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015119 VkRenderPass rp;
15120 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15121 ASSERT_VK_SUCCESS(err);
15122
15123 // error here.
15124 pipe.CreateVKPipeline(pl, rp);
15125
15126 m_errorMonitor->VerifyFound();
15127
15128 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15129 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15130 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15131}
15132
Chris Forbes541f7b02016-08-22 15:30:27 +120015133TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015134 TEST_DESCRIPTION(
15135 "Test that an error is produced for a shader consuming an input attachment "
15136 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015138 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015139
15140 ASSERT_NO_FATAL_FAILURE(InitState());
15141
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015142 char const *vsSource =
15143 "#version 450\n"
15144 "\n"
15145 "out gl_PerVertex {\n"
15146 " vec4 gl_Position;\n"
15147 "};\n"
15148 "void main(){\n"
15149 " gl_Position = vec4(1);\n"
15150 "}\n";
15151 char const *fsSource =
15152 "#version 450\n"
15153 "\n"
15154 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15155 "layout(location=0) out vec4 color;\n"
15156 "void main() {\n"
15157 " color = subpassLoad(xs[0]);\n"
15158 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015159
15160 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15161 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15162
15163 VkPipelineObj pipe(m_device);
15164 pipe.AddShader(&vs);
15165 pipe.AddShader(&fs);
15166 pipe.AddColorAttachment();
15167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015169 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15170 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015171 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015172 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015173 ASSERT_VK_SUCCESS(err);
15174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015176 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015177 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015178 ASSERT_VK_SUCCESS(err);
15179
15180 // error here.
15181 pipe.CreateVKPipeline(pl, renderPass());
15182
15183 m_errorMonitor->VerifyFound();
15184
15185 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15186 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15187}
15188
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015189TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015190 TEST_DESCRIPTION(
15191 "Test that an error is produced for a compute pipeline consuming a "
15192 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015194
15195 ASSERT_NO_FATAL_FAILURE(InitState());
15196
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015197 char const *csSource =
15198 "#version 450\n"
15199 "\n"
15200 "layout(local_size_x=1) in;\n"
15201 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15202 "void main(){\n"
15203 " x = vec4(1);\n"
15204 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015205
15206 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15207
15208 VkDescriptorSetObj descriptorSet(m_device);
15209 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015211 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15212 nullptr,
15213 0,
15214 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15215 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15216 descriptorSet.GetPipelineLayout(),
15217 VK_NULL_HANDLE,
15218 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015219
15220 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015221 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015222
15223 m_errorMonitor->VerifyFound();
15224
15225 if (err == VK_SUCCESS) {
15226 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15227 }
15228}
15229
Chris Forbes22a9b092016-07-19 14:34:05 +120015230TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015231 TEST_DESCRIPTION(
15232 "Test that an error is produced for a pipeline consuming a "
15233 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15235 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015236
15237 ASSERT_NO_FATAL_FAILURE(InitState());
15238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015239 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15240 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015241 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015242 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015243 ASSERT_VK_SUCCESS(err);
15244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015245 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015246 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015247 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015248 ASSERT_VK_SUCCESS(err);
15249
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015250 char const *csSource =
15251 "#version 450\n"
15252 "\n"
15253 "layout(local_size_x=1) in;\n"
15254 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15255 "void main() {\n"
15256 " x.x = 1.0f;\n"
15257 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015258 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015260 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15261 nullptr,
15262 0,
15263 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15264 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15265 pl,
15266 VK_NULL_HANDLE,
15267 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015268
15269 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015270 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015271
15272 m_errorMonitor->VerifyFound();
15273
15274 if (err == VK_SUCCESS) {
15275 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15276 }
15277
15278 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15279 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15280}
15281
Chris Forbes50020592016-07-27 13:52:41 +120015282TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015283 TEST_DESCRIPTION(
15284 "Test that an error is produced when an image view type "
15285 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 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 +120015288
15289 ASSERT_NO_FATAL_FAILURE(InitState());
15290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15291
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015292 char const *vsSource =
15293 "#version 450\n"
15294 "\n"
15295 "out gl_PerVertex { vec4 gl_Position; };\n"
15296 "void main() { gl_Position = vec4(0); }\n";
15297 char const *fsSource =
15298 "#version 450\n"
15299 "\n"
15300 "layout(set=0, binding=0) uniform sampler3D s;\n"
15301 "layout(location=0) out vec4 color;\n"
15302 "void main() {\n"
15303 " color = texture(s, vec3(0));\n"
15304 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015305 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15306 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15307
15308 VkPipelineObj pipe(m_device);
15309 pipe.AddShader(&vs);
15310 pipe.AddShader(&fs);
15311 pipe.AddColorAttachment();
15312
15313 VkTextureObj texture(m_device, nullptr);
15314 VkSamplerObj sampler(m_device);
15315
15316 VkDescriptorSetObj descriptorSet(m_device);
15317 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15318 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15319
15320 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15321 ASSERT_VK_SUCCESS(err);
15322
Tony Barbour552f6c02016-12-21 14:34:07 -070015323 m_commandBuffer->BeginCommandBuffer();
15324 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015325
15326 m_commandBuffer->BindPipeline(pipe);
15327 m_commandBuffer->BindDescriptorSet(descriptorSet);
15328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015329 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015330 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015331 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015332 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15333
15334 // error produced here.
15335 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15336
15337 m_errorMonitor->VerifyFound();
15338
Tony Barbour552f6c02016-12-21 14:34:07 -070015339 m_commandBuffer->EndRenderPass();
15340 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015341}
15342
Chris Forbes5533bfc2016-07-27 14:12:34 +120015343TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015344 TEST_DESCRIPTION(
15345 "Test that an error is produced when a multisampled images "
15346 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015349
15350 ASSERT_NO_FATAL_FAILURE(InitState());
15351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15352
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015353 char const *vsSource =
15354 "#version 450\n"
15355 "\n"
15356 "out gl_PerVertex { vec4 gl_Position; };\n"
15357 "void main() { gl_Position = vec4(0); }\n";
15358 char const *fsSource =
15359 "#version 450\n"
15360 "\n"
15361 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15362 "layout(location=0) out vec4 color;\n"
15363 "void main() {\n"
15364 " color = texelFetch(s, ivec2(0), 0);\n"
15365 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015366 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15367 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15368
15369 VkPipelineObj pipe(m_device);
15370 pipe.AddShader(&vs);
15371 pipe.AddShader(&fs);
15372 pipe.AddColorAttachment();
15373
15374 VkTextureObj texture(m_device, nullptr);
15375 VkSamplerObj sampler(m_device);
15376
15377 VkDescriptorSetObj descriptorSet(m_device);
15378 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15379 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15380
15381 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15382 ASSERT_VK_SUCCESS(err);
15383
Tony Barbour552f6c02016-12-21 14:34:07 -070015384 m_commandBuffer->BeginCommandBuffer();
15385 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015386
15387 m_commandBuffer->BindPipeline(pipe);
15388 m_commandBuffer->BindDescriptorSet(descriptorSet);
15389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015390 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015391 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015392 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015393 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15394
15395 // error produced here.
15396 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15397
15398 m_errorMonitor->VerifyFound();
15399
Tony Barbour552f6c02016-12-21 14:34:07 -070015400 m_commandBuffer->EndRenderPass();
15401 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015402}
15403
Mark Youngc48c4c12016-04-11 14:26:49 -060015404TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015406
15407 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015408
15409 // Create an image
15410 VkImage image;
15411
Karl Schultz6addd812016-02-02 17:17:23 -070015412 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15413 const int32_t tex_width = 32;
15414 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015415
15416 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015417 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15418 image_create_info.pNext = NULL;
15419 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15420 image_create_info.format = tex_format;
15421 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015422 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015423 image_create_info.extent.depth = 1;
15424 image_create_info.mipLevels = 1;
15425 image_create_info.arrayLayers = 1;
15426 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15427 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15428 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15429 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015430
15431 // Introduce error by sending down a bogus width extent
15432 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015433 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015434
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015435 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015436}
15437
Mark Youngc48c4c12016-04-11 14:26:49 -060015438TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015440
15441 ASSERT_NO_FATAL_FAILURE(InitState());
15442
15443 // Create an image
15444 VkImage image;
15445
15446 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15447 const int32_t tex_width = 32;
15448 const int32_t tex_height = 32;
15449
15450 VkImageCreateInfo image_create_info = {};
15451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15452 image_create_info.pNext = NULL;
15453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15454 image_create_info.format = tex_format;
15455 image_create_info.extent.width = tex_width;
15456 image_create_info.extent.height = tex_height;
15457 image_create_info.extent.depth = 1;
15458 image_create_info.mipLevels = 1;
15459 image_create_info.arrayLayers = 1;
15460 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15461 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15462 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15463 image_create_info.flags = 0;
15464
15465 // Introduce error by sending down a bogus width extent
15466 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015467 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015468 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15469
15470 m_errorMonitor->VerifyFound();
15471}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015472
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015473TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015474 TEST_DESCRIPTION(
15475 "Create a render pass with an attachment description "
15476 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015477
15478 ASSERT_NO_FATAL_FAILURE(InitState());
15479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15480
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015482
15483 VkAttachmentReference color_attach = {};
15484 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15485 color_attach.attachment = 0;
15486 VkSubpassDescription subpass = {};
15487 subpass.colorAttachmentCount = 1;
15488 subpass.pColorAttachments = &color_attach;
15489
15490 VkRenderPassCreateInfo rpci = {};
15491 rpci.subpassCount = 1;
15492 rpci.pSubpasses = &subpass;
15493 rpci.attachmentCount = 1;
15494 VkAttachmentDescription attach_desc = {};
15495 attach_desc.format = VK_FORMAT_UNDEFINED;
15496 rpci.pAttachments = &attach_desc;
15497 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15498 VkRenderPass rp;
15499 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15500
15501 m_errorMonitor->VerifyFound();
15502
15503 if (result == VK_SUCCESS) {
15504 vkDestroyRenderPass(m_device->device(), rp, NULL);
15505 }
15506}
15507
Karl Schultz6addd812016-02-02 17:17:23 -070015508TEST_F(VkLayerTest, InvalidImageView) {
15509 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015510
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015512
Tobin Ehliscde08892015-09-22 10:11:37 -060015513 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015514
Mike Stroyana3082432015-09-25 13:39:21 -060015515 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015516 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015517
Karl Schultz6addd812016-02-02 17:17:23 -070015518 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15519 const int32_t tex_width = 32;
15520 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015521
15522 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15524 image_create_info.pNext = NULL;
15525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15526 image_create_info.format = tex_format;
15527 image_create_info.extent.width = tex_width;
15528 image_create_info.extent.height = tex_height;
15529 image_create_info.extent.depth = 1;
15530 image_create_info.mipLevels = 1;
15531 image_create_info.arrayLayers = 1;
15532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15533 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15535 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015536
Chia-I Wuf7458c52015-10-26 21:10:41 +080015537 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015538 ASSERT_VK_SUCCESS(err);
15539
15540 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015541 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015542 image_view_create_info.image = image;
15543 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15544 image_view_create_info.format = tex_format;
15545 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015546 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015547 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015548 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015549
15550 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015551 m_errorMonitor->SetUnexpectedError(
15552 "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 -060015553 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015554
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015555 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015556 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015557}
Mike Stroyana3082432015-09-25 13:39:21 -060015558
Mark Youngd339ba32016-05-30 13:28:35 -060015559TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15560 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015562 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015563
15564 ASSERT_NO_FATAL_FAILURE(InitState());
15565
15566 // Create an image and try to create a view with no memory backing the image
15567 VkImage image;
15568
15569 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15570 const int32_t tex_width = 32;
15571 const int32_t tex_height = 32;
15572
15573 VkImageCreateInfo image_create_info = {};
15574 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15575 image_create_info.pNext = NULL;
15576 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15577 image_create_info.format = tex_format;
15578 image_create_info.extent.width = tex_width;
15579 image_create_info.extent.height = tex_height;
15580 image_create_info.extent.depth = 1;
15581 image_create_info.mipLevels = 1;
15582 image_create_info.arrayLayers = 1;
15583 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15584 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15585 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15586 image_create_info.flags = 0;
15587
15588 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15589 ASSERT_VK_SUCCESS(err);
15590
15591 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015592 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015593 image_view_create_info.image = image;
15594 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15595 image_view_create_info.format = tex_format;
15596 image_view_create_info.subresourceRange.layerCount = 1;
15597 image_view_create_info.subresourceRange.baseMipLevel = 0;
15598 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015599 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015600
15601 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015602 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015603
15604 m_errorMonitor->VerifyFound();
15605 vkDestroyImage(m_device->device(), image, NULL);
15606 // If last error is success, it still created the view, so delete it.
15607 if (err == VK_SUCCESS) {
15608 vkDestroyImageView(m_device->device(), view, NULL);
15609 }
Mark Youngd339ba32016-05-30 13:28:35 -060015610}
15611
Karl Schultz6addd812016-02-02 17:17:23 -070015612TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015613 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015615
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015616 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015617
Karl Schultz6addd812016-02-02 17:17:23 -070015618 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015619 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015620 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015621 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015622
15623 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015624 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015625 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015626 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15627 image_view_create_info.format = tex_format;
15628 image_view_create_info.subresourceRange.baseMipLevel = 0;
15629 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015630 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015631 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015632 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015633
15634 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015635 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015636
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015637 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015638}
15639
Mike Weiblena1e13f42017-02-09 21:25:59 -070015640TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15641 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15642
15643 ASSERT_NO_FATAL_FAILURE(InitState());
15644 VkSubresourceLayout subres_layout = {};
15645
15646 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15647 {
15648 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15649 VkImageObj img(m_device);
15650 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15651 ASSERT_TRUE(img.initialized());
15652
15653 VkImageSubresource subres = {};
15654 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15655 subres.mipLevel = 0;
15656 subres.arrayLayer = 0;
15657
15658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15659 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15660 m_errorMonitor->VerifyFound();
15661 }
15662
15663 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15664 {
15665 VkImageObj img(m_device);
15666 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15667 ASSERT_TRUE(img.initialized());
15668
15669 VkImageSubresource subres = {};
15670 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15671 subres.mipLevel = 0;
15672 subres.arrayLayer = 0;
15673
15674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15676 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15677 m_errorMonitor->VerifyFound();
15678 }
15679
15680 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15681 {
15682 VkImageObj img(m_device);
15683 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15684 ASSERT_TRUE(img.initialized());
15685
15686 VkImageSubresource subres = {};
15687 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15688 subres.mipLevel = 1; // ERROR: triggers VU 00739
15689 subres.arrayLayer = 0;
15690
15691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15692 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15693 m_errorMonitor->VerifyFound();
15694 }
15695
15696 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15697 {
15698 VkImageObj img(m_device);
15699 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15700 ASSERT_TRUE(img.initialized());
15701
15702 VkImageSubresource subres = {};
15703 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15704 subres.mipLevel = 0;
15705 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15706
15707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15708 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15709 m_errorMonitor->VerifyFound();
15710 }
15711}
15712
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015713TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015714 VkResult err;
15715 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015716
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015718
Mike Stroyana3082432015-09-25 13:39:21 -060015719 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015720
15721 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015722 VkImage srcImage;
15723 VkImage dstImage;
15724 VkDeviceMemory srcMem;
15725 VkDeviceMemory destMem;
15726 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015727
15728 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015729 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15730 image_create_info.pNext = NULL;
15731 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15732 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15733 image_create_info.extent.width = 32;
15734 image_create_info.extent.height = 32;
15735 image_create_info.extent.depth = 1;
15736 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015737 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015738 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15739 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15740 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15741 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015743 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015744 ASSERT_VK_SUCCESS(err);
15745
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015746 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015747 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015748 ASSERT_VK_SUCCESS(err);
15749
15750 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015751 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015752 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15753 memAlloc.pNext = NULL;
15754 memAlloc.allocationSize = 0;
15755 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015756
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015757 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015758 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015759 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015760 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015761 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015762 ASSERT_VK_SUCCESS(err);
15763
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015764 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015765 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015766 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015767 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015768 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015769 ASSERT_VK_SUCCESS(err);
15770
15771 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15772 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015773 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015774 ASSERT_VK_SUCCESS(err);
15775
Tony Barbour552f6c02016-12-21 14:34:07 -070015776 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015777 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015778 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015779 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015780 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015781 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015782 copyRegion.srcOffset.x = 0;
15783 copyRegion.srcOffset.y = 0;
15784 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015785 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015786 copyRegion.dstSubresource.mipLevel = 0;
15787 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015788 // Introduce failure by forcing the dst layerCount to differ from src
15789 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015790 copyRegion.dstOffset.x = 0;
15791 copyRegion.dstOffset.y = 0;
15792 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015793 copyRegion.extent.width = 1;
15794 copyRegion.extent.height = 1;
15795 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015796 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015797 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015798
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015799 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015800
Chia-I Wuf7458c52015-10-26 21:10:41 +080015801 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015802 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015803 vkFreeMemory(m_device->device(), srcMem, NULL);
15804 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015805}
15806
Tony Barbourd6673642016-05-05 14:46:39 -060015807TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015808 TEST_DESCRIPTION("Creating images with unsuported formats ");
15809
15810 ASSERT_NO_FATAL_FAILURE(InitState());
15811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15812 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015813 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 -060015814 VK_IMAGE_TILING_OPTIMAL, 0);
15815 ASSERT_TRUE(image.initialized());
15816
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015817 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015818 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015819 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015820 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15821 image_create_info.format = VK_FORMAT_UNDEFINED;
15822 image_create_info.extent.width = 32;
15823 image_create_info.extent.height = 32;
15824 image_create_info.extent.depth = 1;
15825 image_create_info.mipLevels = 1;
15826 image_create_info.arrayLayers = 1;
15827 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15828 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15829 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15832 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015833
15834 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015835 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15836 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15837 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15838 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015839 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15840 m_errorMonitor->VerifyFound();
15841
Tony Barbourd6673642016-05-05 14:46:39 -060015842 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015843 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015844 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15845 VkFormat format = static_cast<VkFormat>(f);
15846 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015847 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015848 unsupported = format;
15849 break;
15850 }
15851 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015852
Tony Barbourd6673642016-05-05 14:46:39 -060015853 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015854 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015856
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015857 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15858 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15859 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15860 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15861 m_errorMonitor->SetUnexpectedError(
15862 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15863 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15864 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015865 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015866 m_errorMonitor->VerifyFound();
15867 }
15868}
15869
15870TEST_F(VkLayerTest, ImageLayerViewTests) {
15871 VkResult ret;
15872 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15873
15874 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070015875 auto depth_format = find_depth_stencil_format(m_device);
15876 if (!depth_format) {
15877 return;
15878 }
Tony Barbourd6673642016-05-05 14:46:39 -060015879
15880 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015881 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 -060015882 VK_IMAGE_TILING_OPTIMAL, 0);
15883 ASSERT_TRUE(image.initialized());
15884
15885 VkImageView imgView;
15886 VkImageViewCreateInfo imgViewInfo = {};
15887 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15888 imgViewInfo.image = image.handle();
15889 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15890 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15891 imgViewInfo.subresourceRange.layerCount = 1;
15892 imgViewInfo.subresourceRange.baseMipLevel = 0;
15893 imgViewInfo.subresourceRange.levelCount = 1;
15894 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15895
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015897 // View can't have baseMipLevel >= image's mipLevels - Expect
15898 // VIEW_CREATE_ERROR
15899 imgViewInfo.subresourceRange.baseMipLevel = 1;
15900 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15901 m_errorMonitor->VerifyFound();
15902 imgViewInfo.subresourceRange.baseMipLevel = 0;
15903
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015905 // View can't have baseArrayLayer >= image's arraySize - Expect
15906 // VIEW_CREATE_ERROR
15907 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15908 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15909 m_errorMonitor->VerifyFound();
15910 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15911
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015913 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15914 imgViewInfo.subresourceRange.levelCount = 0;
15915 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15916 m_errorMonitor->VerifyFound();
15917 imgViewInfo.subresourceRange.levelCount = 1;
15918
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015919 m_errorMonitor->SetDesiredFailureMsg(
15920 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15921 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015922 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15923 imgViewInfo.subresourceRange.layerCount = 0;
15924 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15925 m_errorMonitor->VerifyFound();
15926 imgViewInfo.subresourceRange.layerCount = 1;
15927
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15929 "Formats MUST be IDENTICAL unless "
15930 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15931 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015932 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070015933 imgViewInfo.format = depth_format;
Tony Barbourd6673642016-05-05 14:46:39 -060015934 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15935 m_errorMonitor->VerifyFound();
15936 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15937
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015939 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15940 // VIEW_CREATE_ERROR
15941 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15942 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15943 m_errorMonitor->VerifyFound();
15944 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15945
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015947 // TODO: Update framework to easily passing mutable flag into ImageObj init
15948 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015949 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15950 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15951 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015952 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15953 // VIEW_CREATE_ERROR
15954 VkImageCreateInfo mutImgInfo = image.create_info();
15955 VkImage mutImage;
15956 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015957 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015958 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15959 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15960 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15961 ASSERT_VK_SUCCESS(ret);
15962 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015963 m_errorMonitor->SetUnexpectedError(
15964 "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 -060015965 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15966 m_errorMonitor->VerifyFound();
15967 imgViewInfo.image = image.handle();
15968 vkDestroyImage(m_device->handle(), mutImage, NULL);
15969}
15970
Dave Houlton75967fc2017-03-06 17:21:16 -070015971TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
15972 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
15973
15974 ASSERT_NO_FATAL_FAILURE(InitState());
15975
15976 VkPhysicalDeviceFeatures device_features;
15977 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
15978 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
15979 if (device_features.textureCompressionBC) {
15980 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
15981 } else if (device_features.textureCompressionETC2) {
15982 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
15983 } else if (device_features.textureCompressionASTC_LDR) {
15984 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
15985 } else {
15986 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
15987 return;
15988 }
15989
15990 VkImageCreateInfo ci;
15991 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15992 ci.pNext = NULL;
15993 ci.flags = 0;
15994 ci.imageType = VK_IMAGE_TYPE_2D;
15995 ci.format = compressed_format;
15996 ci.extent = {32, 32, 1};
15997 ci.mipLevels = 6;
15998 ci.arrayLayers = 1;
15999 ci.samples = VK_SAMPLE_COUNT_1_BIT;
16000 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
16001 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16002 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16003 ci.queueFamilyIndexCount = 0;
16004 ci.pQueueFamilyIndices = NULL;
16005 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16006
16007 VkImageObj image(m_device);
16008 image.init(&ci);
16009 ASSERT_TRUE(image.initialized());
16010
16011 VkImageObj odd_image(m_device);
16012 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16013 odd_image.init(&ci);
16014 ASSERT_TRUE(odd_image.initialized());
16015
16016 // Allocate buffers
16017 VkMemoryPropertyFlags reqs = 0;
16018 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16019 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16020 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16021 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16022 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16023
16024 VkBufferImageCopy region = {};
16025 region.bufferRowLength = 0;
16026 region.bufferImageHeight = 0;
16027 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16028 region.imageSubresource.layerCount = 1;
16029 region.imageOffset = {0, 0, 0};
16030 region.bufferOffset = 0;
16031
16032 // start recording
16033 m_commandBuffer->BeginCommandBuffer();
16034
16035 // Mip level copies that work - 5 levels
16036 m_errorMonitor->ExpectSuccess();
16037
16038 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
16039 region.imageExtent = {32, 32, 1};
16040 region.imageSubresource.mipLevel = 0;
16041 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
16042 &region);
16043 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16044 &region);
16045
16046 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
16047 region.imageExtent = {8, 8, 1};
16048 region.imageSubresource.mipLevel = 2;
16049 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
16050 &region);
16051 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16052 &region);
16053
16054 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
16055 region.imageExtent = {4, 4, 1};
16056 region.imageSubresource.mipLevel = 3;
16057 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16058 &region);
16059 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16060 &region);
16061
16062 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
16063 region.imageExtent = {2, 2, 1};
16064 region.imageSubresource.mipLevel = 4;
16065 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16066 &region);
16067 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16068 &region);
16069
16070 region.imageExtent = {1, 1, 1};
16071 region.imageSubresource.mipLevel = 5;
16072 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16073 &region);
16074 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16075 &region);
16076 m_errorMonitor->VerifyNotFound();
16077
16078 // Buffer must accomodate a full compressed block, regardless of texel count
16079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16080 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
16081 &region);
16082 m_errorMonitor->VerifyFound();
16083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
16084 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16085 &region);
16086 m_errorMonitor->VerifyFound();
16087
16088 // Copy width < compressed block size, but not the full mip width
16089 region.imageExtent = {1, 2, 1};
16090 region.imageSubresource.mipLevel = 4;
16091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16092 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16093 &region);
16094 m_errorMonitor->VerifyFound();
16095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16096 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16097 &region);
16098 m_errorMonitor->VerifyFound();
16099
16100 // Copy height < compressed block size but not the full mip height
16101 region.imageExtent = {2, 1, 1};
16102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16103 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16104 &region);
16105 m_errorMonitor->VerifyFound();
16106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16107 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16108 &region);
16109 m_errorMonitor->VerifyFound();
16110
16111 // Offsets must be multiple of compressed block size
16112 region.imageOffset = {1, 1, 0};
16113 region.imageExtent = {1, 1, 1};
16114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16115 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16116 &region);
16117 m_errorMonitor->VerifyFound();
16118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16119 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16120 &region);
16121 m_errorMonitor->VerifyFound();
16122
16123 // Offset + extent width = mip width - should succeed
16124 region.imageOffset = {4, 4, 0};
16125 region.imageExtent = {3, 4, 1};
16126 region.imageSubresource.mipLevel = 2;
16127 m_errorMonitor->ExpectSuccess();
16128 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16129 &region);
16130 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16131 &region);
16132 m_errorMonitor->VerifyNotFound();
16133
16134 // Offset + extent width > mip width, but still within the final compressed block - should succeed
16135 region.imageExtent = {4, 4, 1};
16136 m_errorMonitor->ExpectSuccess();
16137 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16138 &region);
16139 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16140 &region);
16141 m_errorMonitor->VerifyNotFound();
16142
16143 // Offset + extent width < mip width and not a multiple of block width - should fail
16144 region.imageExtent = {3, 3, 1};
16145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16146 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16147 &region);
16148 m_errorMonitor->VerifyFound();
16149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16150 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16151 &region);
16152 m_errorMonitor->VerifyFound();
16153}
16154
Dave Houlton59a20702017-02-02 17:26:23 -070016155TEST_F(VkLayerTest, ImageBufferCopyTests) {
16156 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
16157
16158 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016159 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
16160 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
16161 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
16162 return;
16163 }
Dave Houlton584d51e2017-02-16 12:52:54 -070016164
16165 // Bail if any dimension of transfer granularity is 0.
16166 auto index = m_device->graphics_queue_node_index_;
16167 auto queue_family_properties = m_device->phy().queue_properties();
16168 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
16169 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
16170 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
16171 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
16172 return;
16173 }
16174
Dave Houlton59a20702017-02-02 17:26:23 -070016175 VkImageObj image_64k(m_device); // 128^2 texels, 64k
16176 VkImageObj image_16k(m_device); // 64^2 texels, 16k
16177 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070016178 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
16179 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
16180 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
16181 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
16182
Dave Houlton59a20702017-02-02 17:26:23 -070016183 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
16184 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16185 VK_IMAGE_TILING_OPTIMAL, 0);
16186 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16187 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16188 VK_IMAGE_TILING_OPTIMAL, 0);
16189 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16190 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016191 ASSERT_TRUE(image_64k.initialized());
16192 ASSERT_TRUE(image_16k.initialized());
16193 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016194
Dave Houltonf3229d52017-02-21 15:59:08 -070016195 // Verify all needed Depth/Stencil formats are supported
16196 bool missing_ds_support = false;
16197 VkFormatProperties props = {0, 0, 0};
16198 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16199 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16200 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16201 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16202 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16203 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16204 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16205 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16206
16207 if (!missing_ds_support) {
16208 ds_image_4D_1S.init(
16209 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16210 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16211 VK_IMAGE_TILING_OPTIMAL, 0);
16212 ASSERT_TRUE(ds_image_4D_1S.initialized());
16213
16214 ds_image_3D_1S.init(
16215 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16216 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16217 VK_IMAGE_TILING_OPTIMAL, 0);
16218 ASSERT_TRUE(ds_image_3D_1S.initialized());
16219
16220 ds_image_2D.init(
16221 256, 256, VK_FORMAT_D16_UNORM,
16222 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16223 VK_IMAGE_TILING_OPTIMAL, 0);
16224 ASSERT_TRUE(ds_image_2D.initialized());
16225
16226 ds_image_1S.init(
16227 256, 256, VK_FORMAT_S8_UINT,
16228 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16229 VK_IMAGE_TILING_OPTIMAL, 0);
16230 ASSERT_TRUE(ds_image_1S.initialized());
16231 }
16232
16233 // Allocate buffers
16234 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016235 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016236 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16237 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16238 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16239 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016240
16241 VkBufferImageCopy region = {};
16242 region.bufferRowLength = 0;
16243 region.bufferImageHeight = 0;
16244 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16245 region.imageSubresource.layerCount = 1;
16246 region.imageOffset = {0, 0, 0};
16247 region.imageExtent = {64, 64, 1};
16248 region.bufferOffset = 0;
16249
16250 // attempt copies before putting command buffer in recording state
16251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16252 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16253 &region);
16254 m_errorMonitor->VerifyFound();
16255
16256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16257 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16258 &region);
16259 m_errorMonitor->VerifyFound();
16260
16261 // start recording
16262 m_commandBuffer->BeginCommandBuffer();
16263
16264 // successful copies
16265 m_errorMonitor->ExpectSuccess();
16266 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16267 &region);
16268 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16269 &region);
16270 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16271 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16272 &region);
16273 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16274 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16275 &region);
16276 region.imageOffset.x = 0;
16277 region.imageExtent.height = 64;
16278 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16279 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16280 &region);
16281 m_errorMonitor->VerifyNotFound();
16282
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016283 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070016284 region.imageExtent = {65, 64, 1};
16285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16286 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16287 &region);
16288 m_errorMonitor->VerifyFound();
16289
16290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16291 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16292 &region);
16293 m_errorMonitor->VerifyFound();
16294
16295 // image/buffer too small (offset) on copy to image
16296 region.imageExtent = {64, 64, 1};
16297 region.imageOffset = {0, 4, 0};
16298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16299 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16300 &region);
16301 m_errorMonitor->VerifyFound();
16302
16303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16304 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16305 &region);
16306 m_errorMonitor->VerifyFound();
16307
16308 // image/buffer too small on copy to buffer
16309 region.imageExtent = {64, 64, 1};
16310 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016311 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16313 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16314 &region);
16315 m_errorMonitor->VerifyFound();
16316
16317 region.imageExtent = {64, 65, 1};
16318 region.bufferOffset = 0;
16319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16320 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16321 &region);
16322 m_errorMonitor->VerifyFound();
16323
16324 // buffer size ok but rowlength causes loose packing
16325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16326 region.imageExtent = {64, 64, 1};
16327 region.bufferRowLength = 68;
16328 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16329 &region);
16330 m_errorMonitor->VerifyFound();
16331
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016332 // An extent with zero area should produce a warning, but no error
16333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
16334 region.imageExtent.width = 0;
16335 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16336 &region);
16337 m_errorMonitor->VerifyFound();
16338
Dave Houlton59a20702017-02-02 17:26:23 -070016339 // aspect bits
16340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16341 region.imageExtent = {64, 64, 1};
16342 region.bufferRowLength = 0;
16343 region.bufferImageHeight = 0;
16344 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16345 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16346 buffer_16k.handle(), 1, &region);
16347 m_errorMonitor->VerifyFound();
16348
16349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16350 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16351 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16352 &region);
16353 m_errorMonitor->VerifyFound();
16354
16355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16356 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16357 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16358 buffer_16k.handle(), 1, &region);
16359 m_errorMonitor->VerifyFound();
16360
Dave Houltonf3229d52017-02-21 15:59:08 -070016361 // Test Depth/Stencil copies
16362 if (missing_ds_support) {
16363 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16364 } else {
16365 VkBufferImageCopy ds_region = {};
16366 ds_region.bufferOffset = 0;
16367 ds_region.bufferRowLength = 0;
16368 ds_region.bufferImageHeight = 0;
16369 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16370 ds_region.imageSubresource.mipLevel = 0;
16371 ds_region.imageSubresource.baseArrayLayer = 0;
16372 ds_region.imageSubresource.layerCount = 1;
16373 ds_region.imageOffset = {0, 0, 0};
16374 ds_region.imageExtent = {256, 256, 1};
16375
16376 // Depth copies that should succeed
16377 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16378 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16379 buffer_256k.handle(), 1, &ds_region);
16380 m_errorMonitor->VerifyNotFound();
16381
16382 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16383 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16384 buffer_256k.handle(), 1, &ds_region);
16385 m_errorMonitor->VerifyNotFound();
16386
16387 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16388 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16389 buffer_128k.handle(), 1, &ds_region);
16390 m_errorMonitor->VerifyNotFound();
16391
16392 // Depth copies that should fail
16393 ds_region.bufferOffset = 4;
16394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16395 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16396 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16397 buffer_256k.handle(), 1, &ds_region);
16398 m_errorMonitor->VerifyFound();
16399
16400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16401 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16402 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16403 buffer_256k.handle(), 1, &ds_region);
16404 m_errorMonitor->VerifyFound();
16405
16406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16407 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16408 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16409 buffer_128k.handle(), 1, &ds_region);
16410 m_errorMonitor->VerifyFound();
16411
16412 // Stencil copies that should succeed
16413 ds_region.bufferOffset = 0;
16414 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16415 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16416 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16417 buffer_64k.handle(), 1, &ds_region);
16418 m_errorMonitor->VerifyNotFound();
16419
16420 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16421 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16422 buffer_64k.handle(), 1, &ds_region);
16423 m_errorMonitor->VerifyNotFound();
16424
16425 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16426 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16427 buffer_64k.handle(), 1, &ds_region);
16428 m_errorMonitor->VerifyNotFound();
16429
16430 // Stencil copies that should fail
16431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16432 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16433 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16434 buffer_16k.handle(), 1, &ds_region);
16435 m_errorMonitor->VerifyFound();
16436
16437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16438 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16439 ds_region.bufferRowLength = 260;
16440 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16441 buffer_64k.handle(), 1, &ds_region);
16442 m_errorMonitor->VerifyFound();
16443
16444 ds_region.bufferRowLength = 0;
16445 ds_region.bufferOffset = 4;
16446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16447 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16448 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16449 buffer_64k.handle(), 1, &ds_region);
16450 m_errorMonitor->VerifyFound();
16451 }
16452
Dave Houlton584d51e2017-02-16 12:52:54 -070016453 // Test compressed formats, if supported
16454 VkPhysicalDeviceFeatures device_features;
16455 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016456 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16457 device_features.textureCompressionASTC_LDR)) {
16458 printf(" No compressed formats supported - block compression tests skipped.\n");
16459 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070016460 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16461 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070016462 if (device_features.textureCompressionBC) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016463 image_16k_4x4comp.init(128, 128, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016464 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16465 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016466 } else if (device_features.textureCompressionETC2) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016467 image_16k_4x4comp.init(128, 128, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton584d51e2017-02-16 12:52:54 -070016468 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016469 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16470 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016471 } else {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016472 image_16k_4x4comp.init(128, 128, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16473 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016474 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16475 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016476 }
16477 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016478
Dave Houlton584d51e2017-02-16 12:52:54 -070016479 // Just fits
16480 m_errorMonitor->ExpectSuccess();
16481 region.imageExtent = {128, 128, 1};
16482 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16483 buffer_16k.handle(), 1, &region);
16484 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016485
Dave Houlton584d51e2017-02-16 12:52:54 -070016486 // with offset, too big for buffer
16487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16488 region.bufferOffset = 16;
16489 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16490 buffer_16k.handle(), 1, &region);
16491 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016492 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016493
Dave Houlton67e9b532017-03-02 17:00:10 -070016494 // extents that are not a multiple of compressed block size
16495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16496 region.imageExtent.width = 66;
16497 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16498 buffer_16k.handle(), 1, &region);
16499 m_errorMonitor->VerifyFound();
16500 region.imageExtent.width = 128;
16501
16502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016503 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070016504 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16505 buffer_16k.handle(), 1, &region);
16506 m_errorMonitor->VerifyFound();
16507 region.imageExtent.height = 128;
16508
16509 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
16510
16511 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
16512 m_errorMonitor->ExpectSuccess();
16513 region.imageExtent.width = 66;
16514 region.imageOffset.x = 64;
16515 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16516 buffer_16k.handle(), 1, &region);
16517 region.imageExtent.width = 16;
16518 region.imageOffset.x = 0;
16519 region.imageExtent.height = 2;
16520 region.imageOffset.y = 128;
16521 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016522 buffer_16k.handle(), 1, &region);
16523 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016524 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016525
Dave Houlton584d51e2017-02-16 12:52:54 -070016526 // buffer offset must be a multiple of texel block size (16)
16527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16529 region.imageExtent = {64, 64, 1};
16530 region.bufferOffset = 24;
16531 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16532 buffer_16k.handle(), 1, &region);
16533 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016534
Dave Houlton584d51e2017-02-16 12:52:54 -070016535 // rowlength not a multiple of block width (4)
16536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16537 region.bufferOffset = 0;
16538 region.bufferRowLength = 130;
16539 region.bufferImageHeight = 0;
16540 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16541 buffer_64k.handle(), 1, &region);
16542 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016543
Dave Houlton584d51e2017-02-16 12:52:54 -070016544 // imageheight not a multiple of block height (4)
16545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16546 region.bufferRowLength = 0;
16547 region.bufferImageHeight = 130;
16548 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16549 buffer_64k.handle(), 1, &region);
16550 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070016551 }
Dave Houlton59a20702017-02-02 17:26:23 -070016552}
16553
Tony Barbourd6673642016-05-05 14:46:39 -060016554TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016555 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016556
16557 ASSERT_NO_FATAL_FAILURE(InitState());
16558
Rene Lindsay135204f2016-12-22 17:11:09 -070016559 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016560 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016561 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 -070016562 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016563 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016564 vk_testing::Buffer buffer;
16565 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016566 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016567 VkBufferImageCopy region = {};
16568 region.bufferRowLength = 128;
16569 region.bufferImageHeight = 128;
16570 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16571 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016572 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016573 region.imageExtent.height = 4;
16574 region.imageExtent.width = 4;
16575 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016576
16577 VkImageObj image2(m_device);
16578 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 -070016579 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016580 ASSERT_TRUE(image2.initialized());
16581 vk_testing::Buffer buffer2;
16582 VkMemoryPropertyFlags reqs2 = 0;
16583 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16584 VkBufferImageCopy region2 = {};
16585 region2.bufferRowLength = 128;
16586 region2.bufferImageHeight = 128;
16587 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16588 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16589 region2.imageSubresource.layerCount = 1;
16590 region2.imageExtent.height = 4;
16591 region2.imageExtent.width = 4;
16592 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016593 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016594
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016595 // Image must have offset.z of 0 and extent.depth of 1
16596 // Introduce failure by setting imageExtent.depth to 0
16597 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016599 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016600 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016601 m_errorMonitor->VerifyFound();
16602
16603 region.imageExtent.depth = 1;
16604
16605 // Image must have offset.z of 0 and extent.depth of 1
16606 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016607 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016608 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016611 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016612 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016613 m_errorMonitor->VerifyFound();
16614
16615 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016616 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16617 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016618 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016620 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16621 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016622 m_errorMonitor->VerifyFound();
16623
16624 // BufferOffset must be a multiple of 4
16625 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016626 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016628 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16629 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016630 m_errorMonitor->VerifyFound();
16631
16632 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16633 region.bufferOffset = 0;
16634 region.imageExtent.height = 128;
16635 region.imageExtent.width = 128;
16636 // Introduce failure by setting bufferRowLength > 0 but less than width
16637 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016639 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16640 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016641 m_errorMonitor->VerifyFound();
16642
16643 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16644 region.bufferRowLength = 128;
16645 // Introduce failure by setting bufferRowHeight > 0 but less than height
16646 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016648 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16649 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016650 m_errorMonitor->VerifyFound();
16651
16652 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016653 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016654 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16655 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016656 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016657 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16658 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016659 VkImageBlit blitRegion = {};
16660 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16661 blitRegion.srcSubresource.baseArrayLayer = 0;
16662 blitRegion.srcSubresource.layerCount = 1;
16663 blitRegion.srcSubresource.mipLevel = 0;
16664 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16665 blitRegion.dstSubresource.baseArrayLayer = 0;
16666 blitRegion.dstSubresource.layerCount = 1;
16667 blitRegion.dstSubresource.mipLevel = 0;
16668
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016669 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016671 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016672 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16673 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016674 m_errorMonitor->VerifyFound();
16675
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016677 VkImageMemoryBarrier img_barrier;
16678 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16679 img_barrier.pNext = NULL;
16680 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16681 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16682 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16683 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16684 img_barrier.image = image.handle();
16685 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16686 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16687 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16688 img_barrier.subresourceRange.baseArrayLayer = 0;
16689 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016690 img_barrier.subresourceRange.layerCount = 0;
16691 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016692 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16693 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016694 m_errorMonitor->VerifyFound();
16695 img_barrier.subresourceRange.layerCount = 1;
16696}
16697
16698TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016699 TEST_DESCRIPTION("Exceed the limits of image format ");
16700
Cody Northropc31a84f2016-08-22 10:41:47 -060016701 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016703 VkImageCreateInfo image_create_info = {};
16704 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16705 image_create_info.pNext = NULL;
16706 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16707 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16708 image_create_info.extent.width = 32;
16709 image_create_info.extent.height = 32;
16710 image_create_info.extent.depth = 1;
16711 image_create_info.mipLevels = 1;
16712 image_create_info.arrayLayers = 1;
16713 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16714 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16715 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16716 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16717 image_create_info.flags = 0;
16718
16719 VkImage nullImg;
16720 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016721 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16722 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016723 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016724 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16725 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16726 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016727 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016728
Tony Barbour0907e362017-03-09 15:05:30 -070016729 uint32_t maxDim =
16730 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
16731 // If max mip levels exceeds image extents, skip the max mip levels test
16732 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
16733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
16734 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16735 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16736 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16737 m_errorMonitor->VerifyFound();
16738 image_create_info.mipLevels = 1;
16739 }
Tony Barbourd6673642016-05-05 14:46:39 -060016740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016742 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16743 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16744 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16745 m_errorMonitor->VerifyFound();
16746 image_create_info.arrayLayers = 1;
16747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016749 int samples = imgFmtProps.sampleCounts >> 1;
16750 image_create_info.samples = (VkSampleCountFlagBits)samples;
16751 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16752 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16753 m_errorMonitor->VerifyFound();
16754 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16755
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16757 "pCreateInfo->initialLayout, must be "
16758 "VK_IMAGE_LAYOUT_UNDEFINED or "
16759 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016760 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16761 // Expect INVALID_LAYOUT
16762 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16763 m_errorMonitor->VerifyFound();
16764 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16765}
16766
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016767TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016768 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016770
16771 ASSERT_NO_FATAL_FAILURE(InitState());
16772
16773 VkImageObj src_image(m_device);
16774 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16775 VkImageObj dst_image(m_device);
16776 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16777
Tony Barbour552f6c02016-12-21 14:34:07 -070016778 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016779 VkImageCopy copy_region;
16780 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16781 copy_region.srcSubresource.mipLevel = 0;
16782 copy_region.srcSubresource.baseArrayLayer = 0;
16783 copy_region.srcSubresource.layerCount = 0;
16784 copy_region.srcOffset.x = 0;
16785 copy_region.srcOffset.y = 0;
16786 copy_region.srcOffset.z = 0;
16787 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16788 copy_region.dstSubresource.mipLevel = 0;
16789 copy_region.dstSubresource.baseArrayLayer = 0;
16790 copy_region.dstSubresource.layerCount = 0;
16791 copy_region.dstOffset.x = 0;
16792 copy_region.dstOffset.y = 0;
16793 copy_region.dstOffset.z = 0;
16794 copy_region.extent.width = 64;
16795 copy_region.extent.height = 64;
16796 copy_region.extent.depth = 1;
16797 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16798 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016799 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016800
16801 m_errorMonitor->VerifyFound();
16802}
16803
16804TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016805 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016807
16808 ASSERT_NO_FATAL_FAILURE(InitState());
16809
16810 VkImageObj src_image(m_device);
16811 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16812 VkImageObj dst_image(m_device);
16813 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16814
Tony Barbour552f6c02016-12-21 14:34:07 -070016815 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016816 VkImageCopy copy_region;
16817 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16818 copy_region.srcSubresource.mipLevel = 0;
16819 copy_region.srcSubresource.baseArrayLayer = 0;
16820 copy_region.srcSubresource.layerCount = 0;
16821 copy_region.srcOffset.x = 0;
16822 copy_region.srcOffset.y = 0;
16823 copy_region.srcOffset.z = 0;
16824 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16825 copy_region.dstSubresource.mipLevel = 0;
16826 copy_region.dstSubresource.baseArrayLayer = 0;
16827 copy_region.dstSubresource.layerCount = 0;
16828 copy_region.dstOffset.x = 0;
16829 copy_region.dstOffset.y = 0;
16830 copy_region.dstOffset.z = 0;
16831 copy_region.extent.width = 64;
16832 copy_region.extent.height = 64;
16833 copy_region.extent.depth = 1;
16834 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16835 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016836 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016837
16838 m_errorMonitor->VerifyFound();
16839}
16840
Karl Schultz6addd812016-02-02 17:17:23 -070016841TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016842 VkResult err;
16843 bool pass;
16844
16845 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016847
16848 ASSERT_NO_FATAL_FAILURE(InitState());
16849
16850 // Create two images of different types and try to copy between them
16851 VkImage srcImage;
16852 VkImage dstImage;
16853 VkDeviceMemory srcMem;
16854 VkDeviceMemory destMem;
16855 VkMemoryRequirements memReqs;
16856
16857 VkImageCreateInfo image_create_info = {};
16858 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16859 image_create_info.pNext = NULL;
16860 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16861 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16862 image_create_info.extent.width = 32;
16863 image_create_info.extent.height = 32;
16864 image_create_info.extent.depth = 1;
16865 image_create_info.mipLevels = 1;
16866 image_create_info.arrayLayers = 1;
16867 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16868 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16869 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16870 image_create_info.flags = 0;
16871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016872 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016873 ASSERT_VK_SUCCESS(err);
16874
16875 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16876 // Introduce failure by creating second image with a different-sized format.
16877 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016879 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016880 ASSERT_VK_SUCCESS(err);
16881
16882 // Allocate memory
16883 VkMemoryAllocateInfo memAlloc = {};
16884 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16885 memAlloc.pNext = NULL;
16886 memAlloc.allocationSize = 0;
16887 memAlloc.memoryTypeIndex = 0;
16888
16889 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16890 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016891 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016892 ASSERT_TRUE(pass);
16893 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16894 ASSERT_VK_SUCCESS(err);
16895
16896 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16897 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016898 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016899 ASSERT_TRUE(pass);
16900 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16901 ASSERT_VK_SUCCESS(err);
16902
16903 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16904 ASSERT_VK_SUCCESS(err);
16905 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16906 ASSERT_VK_SUCCESS(err);
16907
Tony Barbour552f6c02016-12-21 14:34:07 -070016908 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016909 VkImageCopy copyRegion;
16910 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16911 copyRegion.srcSubresource.mipLevel = 0;
16912 copyRegion.srcSubresource.baseArrayLayer = 0;
16913 copyRegion.srcSubresource.layerCount = 0;
16914 copyRegion.srcOffset.x = 0;
16915 copyRegion.srcOffset.y = 0;
16916 copyRegion.srcOffset.z = 0;
16917 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16918 copyRegion.dstSubresource.mipLevel = 0;
16919 copyRegion.dstSubresource.baseArrayLayer = 0;
16920 copyRegion.dstSubresource.layerCount = 0;
16921 copyRegion.dstOffset.x = 0;
16922 copyRegion.dstOffset.y = 0;
16923 copyRegion.dstOffset.z = 0;
16924 copyRegion.extent.width = 1;
16925 copyRegion.extent.height = 1;
16926 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016927 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016928 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016929
16930 m_errorMonitor->VerifyFound();
16931
16932 vkDestroyImage(m_device->device(), srcImage, NULL);
16933 vkDestroyImage(m_device->device(), dstImage, NULL);
16934 vkFreeMemory(m_device->device(), srcMem, NULL);
16935 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016936}
16937
Karl Schultz6addd812016-02-02 17:17:23 -070016938TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16939 VkResult err;
16940 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016941
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016942 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16944 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016945
Mike Stroyana3082432015-09-25 13:39:21 -060016946 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016947 auto depth_format = find_depth_stencil_format(m_device);
16948 if (!depth_format) {
16949 return;
16950 }
Mike Stroyana3082432015-09-25 13:39:21 -060016951
16952 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016953 VkImage srcImage;
16954 VkImage dstImage;
16955 VkDeviceMemory srcMem;
16956 VkDeviceMemory destMem;
16957 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016958
16959 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016960 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16961 image_create_info.pNext = NULL;
16962 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16963 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16964 image_create_info.extent.width = 32;
16965 image_create_info.extent.height = 32;
16966 image_create_info.extent.depth = 1;
16967 image_create_info.mipLevels = 1;
16968 image_create_info.arrayLayers = 1;
16969 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16970 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16971 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16972 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016974 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016975 ASSERT_VK_SUCCESS(err);
16976
Karl Schultzbdb75952016-04-19 11:36:49 -060016977 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16978
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016979 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016980 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070016981 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016982 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016984 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016985 ASSERT_VK_SUCCESS(err);
16986
16987 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016988 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016989 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16990 memAlloc.pNext = NULL;
16991 memAlloc.allocationSize = 0;
16992 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016993
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016994 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016995 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016996 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016997 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016998 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016999 ASSERT_VK_SUCCESS(err);
17000
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017001 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017002 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017003 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017004 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017005 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017006 ASSERT_VK_SUCCESS(err);
17007
17008 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17009 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017010 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017011 ASSERT_VK_SUCCESS(err);
17012
Tony Barbour552f6c02016-12-21 14:34:07 -070017013 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017014 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017015 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017016 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017017 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017018 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017019 copyRegion.srcOffset.x = 0;
17020 copyRegion.srcOffset.y = 0;
17021 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017022 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017023 copyRegion.dstSubresource.mipLevel = 0;
17024 copyRegion.dstSubresource.baseArrayLayer = 0;
17025 copyRegion.dstSubresource.layerCount = 0;
17026 copyRegion.dstOffset.x = 0;
17027 copyRegion.dstOffset.y = 0;
17028 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017029 copyRegion.extent.width = 1;
17030 copyRegion.extent.height = 1;
17031 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017032 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017033 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017034
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017035 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017036
Chia-I Wuf7458c52015-10-26 21:10:41 +080017037 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017038 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017039 vkFreeMemory(m_device->device(), srcMem, NULL);
17040 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017041}
17042
Karl Schultz6addd812016-02-02 17:17:23 -070017043TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
17044 VkResult err;
17045 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17048 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017049
Mike Stroyana3082432015-09-25 13:39:21 -060017050 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017051
17052 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017053 VkImage srcImage;
17054 VkImage dstImage;
17055 VkDeviceMemory srcMem;
17056 VkDeviceMemory destMem;
17057 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017058
17059 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017060 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17061 image_create_info.pNext = NULL;
17062 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17063 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17064 image_create_info.extent.width = 32;
17065 image_create_info.extent.height = 1;
17066 image_create_info.extent.depth = 1;
17067 image_create_info.mipLevels = 1;
17068 image_create_info.arrayLayers = 1;
17069 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17070 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17071 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17072 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017074 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017075 ASSERT_VK_SUCCESS(err);
17076
Karl Schultz6addd812016-02-02 17:17:23 -070017077 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017079 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017080 ASSERT_VK_SUCCESS(err);
17081
17082 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017083 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017084 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17085 memAlloc.pNext = NULL;
17086 memAlloc.allocationSize = 0;
17087 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017088
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017089 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017090 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017091 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017092 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017093 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017094 ASSERT_VK_SUCCESS(err);
17095
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017096 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017097 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017098 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017099 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017100 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017101 ASSERT_VK_SUCCESS(err);
17102
17103 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17104 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017105 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017106 ASSERT_VK_SUCCESS(err);
17107
Tony Barbour552f6c02016-12-21 14:34:07 -070017108 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017109 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017110 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17111 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017112 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017113 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017114 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017115 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017116 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017117 resolveRegion.srcOffset.x = 0;
17118 resolveRegion.srcOffset.y = 0;
17119 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017120 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017121 resolveRegion.dstSubresource.mipLevel = 0;
17122 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017123 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017124 resolveRegion.dstOffset.x = 0;
17125 resolveRegion.dstOffset.y = 0;
17126 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017127 resolveRegion.extent.width = 1;
17128 resolveRegion.extent.height = 1;
17129 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017130 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017131 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017132
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017133 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017134
Chia-I Wuf7458c52015-10-26 21:10:41 +080017135 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017136 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017137 vkFreeMemory(m_device->device(), srcMem, NULL);
17138 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017139}
17140
Karl Schultz6addd812016-02-02 17:17:23 -070017141TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
17142 VkResult err;
17143 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017144
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17146 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017147
Mike Stroyana3082432015-09-25 13:39:21 -060017148 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017149
Chris Forbesa7530692016-05-08 12:35:39 +120017150 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017151 VkImage srcImage;
17152 VkImage dstImage;
17153 VkDeviceMemory srcMem;
17154 VkDeviceMemory destMem;
17155 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017156
17157 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017158 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17159 image_create_info.pNext = NULL;
17160 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17161 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17162 image_create_info.extent.width = 32;
17163 image_create_info.extent.height = 1;
17164 image_create_info.extent.depth = 1;
17165 image_create_info.mipLevels = 1;
17166 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017167 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017168 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17169 // Note: Some implementations expect color attachment usage for any
17170 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017171 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017172 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017174 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017175 ASSERT_VK_SUCCESS(err);
17176
Karl Schultz6addd812016-02-02 17:17:23 -070017177 // Note: Some implementations expect color attachment usage for any
17178 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017179 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017181 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017182 ASSERT_VK_SUCCESS(err);
17183
17184 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017185 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017186 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17187 memAlloc.pNext = NULL;
17188 memAlloc.allocationSize = 0;
17189 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017190
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017191 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017192 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017193 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017194 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017195 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017196 ASSERT_VK_SUCCESS(err);
17197
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017198 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017199 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017200 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017201 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017202 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017203 ASSERT_VK_SUCCESS(err);
17204
17205 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17206 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017207 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017208 ASSERT_VK_SUCCESS(err);
17209
Tony Barbour552f6c02016-12-21 14:34:07 -070017210 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017211 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017212 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17213 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017214 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017215 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017216 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017217 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017218 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017219 resolveRegion.srcOffset.x = 0;
17220 resolveRegion.srcOffset.y = 0;
17221 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017222 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017223 resolveRegion.dstSubresource.mipLevel = 0;
17224 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017225 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017226 resolveRegion.dstOffset.x = 0;
17227 resolveRegion.dstOffset.y = 0;
17228 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017229 resolveRegion.extent.width = 1;
17230 resolveRegion.extent.height = 1;
17231 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017232 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017233 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017235 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017236
Chia-I Wuf7458c52015-10-26 21:10:41 +080017237 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017238 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017239 vkFreeMemory(m_device->device(), srcMem, NULL);
17240 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017241}
17242
Karl Schultz6addd812016-02-02 17:17:23 -070017243TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17244 VkResult err;
17245 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017246
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017248 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017249
Mike Stroyana3082432015-09-25 13:39:21 -060017250 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017251
17252 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017253 VkImage srcImage;
17254 VkImage dstImage;
17255 VkDeviceMemory srcMem;
17256 VkDeviceMemory destMem;
17257 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017258
17259 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017260 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17261 image_create_info.pNext = NULL;
17262 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17263 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17264 image_create_info.extent.width = 32;
17265 image_create_info.extent.height = 1;
17266 image_create_info.extent.depth = 1;
17267 image_create_info.mipLevels = 1;
17268 image_create_info.arrayLayers = 1;
17269 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17270 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17271 // Note: Some implementations expect color attachment usage for any
17272 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017273 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017274 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017276 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017277 ASSERT_VK_SUCCESS(err);
17278
Karl Schultz6addd812016-02-02 17:17:23 -070017279 // Set format to something other than source image
17280 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17281 // Note: Some implementations expect color attachment usage for any
17282 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017283 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017284 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017286 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017287 ASSERT_VK_SUCCESS(err);
17288
17289 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017290 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017291 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17292 memAlloc.pNext = NULL;
17293 memAlloc.allocationSize = 0;
17294 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017295
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017296 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017297 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017298 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017299 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017300 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017301 ASSERT_VK_SUCCESS(err);
17302
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017303 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017304 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017305 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017306 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017307 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017308 ASSERT_VK_SUCCESS(err);
17309
17310 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17311 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017312 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017313 ASSERT_VK_SUCCESS(err);
17314
Tony Barbour552f6c02016-12-21 14:34:07 -070017315 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017316 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017317 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17318 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017319 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017320 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017321 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017322 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017323 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017324 resolveRegion.srcOffset.x = 0;
17325 resolveRegion.srcOffset.y = 0;
17326 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017327 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017328 resolveRegion.dstSubresource.mipLevel = 0;
17329 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017330 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017331 resolveRegion.dstOffset.x = 0;
17332 resolveRegion.dstOffset.y = 0;
17333 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017334 resolveRegion.extent.width = 1;
17335 resolveRegion.extent.height = 1;
17336 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017337 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017338 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017339
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017340 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017341
Chia-I Wuf7458c52015-10-26 21:10:41 +080017342 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017343 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017344 vkFreeMemory(m_device->device(), srcMem, NULL);
17345 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017346}
17347
Karl Schultz6addd812016-02-02 17:17:23 -070017348TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17349 VkResult err;
17350 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017351
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017353 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017354
Mike Stroyana3082432015-09-25 13:39:21 -060017355 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017356
17357 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017358 VkImage srcImage;
17359 VkImage dstImage;
17360 VkDeviceMemory srcMem;
17361 VkDeviceMemory destMem;
17362 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017363
17364 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017365 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17366 image_create_info.pNext = NULL;
17367 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17368 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17369 image_create_info.extent.width = 32;
17370 image_create_info.extent.height = 1;
17371 image_create_info.extent.depth = 1;
17372 image_create_info.mipLevels = 1;
17373 image_create_info.arrayLayers = 1;
17374 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17375 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17376 // Note: Some implementations expect color attachment usage for any
17377 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017378 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017379 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017381 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017382 ASSERT_VK_SUCCESS(err);
17383
Karl Schultz6addd812016-02-02 17:17:23 -070017384 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17385 // Note: Some implementations expect color attachment usage for any
17386 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017387 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017388 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017390 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017391 ASSERT_VK_SUCCESS(err);
17392
17393 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017394 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017395 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17396 memAlloc.pNext = NULL;
17397 memAlloc.allocationSize = 0;
17398 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017399
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017400 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017401 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017402 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017403 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017404 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017405 ASSERT_VK_SUCCESS(err);
17406
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017407 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017408 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017409 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017410 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017411 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017412 ASSERT_VK_SUCCESS(err);
17413
17414 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17415 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017416 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017417 ASSERT_VK_SUCCESS(err);
17418
Tony Barbour552f6c02016-12-21 14:34:07 -070017419 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017420 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017421 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17422 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017423 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017424 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017425 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017426 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017427 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017428 resolveRegion.srcOffset.x = 0;
17429 resolveRegion.srcOffset.y = 0;
17430 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017431 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017432 resolveRegion.dstSubresource.mipLevel = 0;
17433 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017434 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017435 resolveRegion.dstOffset.x = 0;
17436 resolveRegion.dstOffset.y = 0;
17437 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017438 resolveRegion.extent.width = 1;
17439 resolveRegion.extent.height = 1;
17440 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017441 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017442 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017443
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017444 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017445
Chia-I Wuf7458c52015-10-26 21:10:41 +080017446 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017447 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017448 vkFreeMemory(m_device->device(), srcMem, NULL);
17449 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017450}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017451
Karl Schultz6addd812016-02-02 17:17:23 -070017452TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017453 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017454 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17455 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017456 // The image format check comes 2nd in validation so we trigger it first,
17457 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017458 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017459
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17461 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017462
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017463 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017464 auto depth_format = find_depth_stencil_format(m_device);
17465 if (!depth_format) {
17466 return;
17467 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017468
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017469 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017470 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17471 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017472
17473 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017474 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17475 ds_pool_ci.pNext = NULL;
17476 ds_pool_ci.maxSets = 1;
17477 ds_pool_ci.poolSizeCount = 1;
17478 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017479
17480 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017481 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017482 ASSERT_VK_SUCCESS(err);
17483
17484 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017485 dsl_binding.binding = 0;
17486 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17487 dsl_binding.descriptorCount = 1;
17488 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17489 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017490
17491 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017492 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17493 ds_layout_ci.pNext = NULL;
17494 ds_layout_ci.bindingCount = 1;
17495 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017496 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017497 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017498 ASSERT_VK_SUCCESS(err);
17499
17500 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017501 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017502 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017503 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017504 alloc_info.descriptorPool = ds_pool;
17505 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017506 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017507 ASSERT_VK_SUCCESS(err);
17508
Karl Schultz6addd812016-02-02 17:17:23 -070017509 VkImage image_bad;
17510 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017511 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070017512 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017513 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017514 const int32_t tex_width = 32;
17515 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017516
17517 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017518 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17519 image_create_info.pNext = NULL;
17520 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17521 image_create_info.format = tex_format_bad;
17522 image_create_info.extent.width = tex_width;
17523 image_create_info.extent.height = tex_height;
17524 image_create_info.extent.depth = 1;
17525 image_create_info.mipLevels = 1;
17526 image_create_info.arrayLayers = 1;
17527 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17528 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017529 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017530 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017531
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017532 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017533 ASSERT_VK_SUCCESS(err);
17534 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017535 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17536 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017537 ASSERT_VK_SUCCESS(err);
17538
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017539 // ---Bind image memory---
17540 VkMemoryRequirements img_mem_reqs;
17541 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17542 VkMemoryAllocateInfo image_alloc_info = {};
17543 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17544 image_alloc_info.pNext = NULL;
17545 image_alloc_info.memoryTypeIndex = 0;
17546 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017547 bool pass =
17548 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 -070017549 ASSERT_TRUE(pass);
17550 VkDeviceMemory mem;
17551 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17552 ASSERT_VK_SUCCESS(err);
17553 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17554 ASSERT_VK_SUCCESS(err);
17555 // -----------------------
17556
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017557 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017558 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017559 image_view_create_info.image = image_bad;
17560 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17561 image_view_create_info.format = tex_format_bad;
17562 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17563 image_view_create_info.subresourceRange.baseMipLevel = 0;
17564 image_view_create_info.subresourceRange.layerCount = 1;
17565 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017566 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017567
17568 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017569 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017570
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017571 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017572
Chia-I Wuf7458c52015-10-26 21:10:41 +080017573 vkDestroyImage(m_device->device(), image_bad, NULL);
17574 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017577
17578 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017579}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017580
17581TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017582 TEST_DESCRIPTION(
17583 "Call ClearColorImage w/ a depth|stencil image and "
17584 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017585
17586 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017587 auto depth_format = find_depth_stencil_format(m_device);
17588 if (!depth_format) {
17589 return;
17590 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17592
Tony Barbour552f6c02016-12-21 14:34:07 -070017593 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017594
17595 // Color image
17596 VkClearColorValue clear_color;
17597 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17598 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17599 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17600 const int32_t img_width = 32;
17601 const int32_t img_height = 32;
17602 VkImageCreateInfo image_create_info = {};
17603 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17604 image_create_info.pNext = NULL;
17605 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17606 image_create_info.format = color_format;
17607 image_create_info.extent.width = img_width;
17608 image_create_info.extent.height = img_height;
17609 image_create_info.extent.depth = 1;
17610 image_create_info.mipLevels = 1;
17611 image_create_info.arrayLayers = 1;
17612 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17613 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17614 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17615
17616 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017617 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017619 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017620
17621 // Depth/Stencil image
17622 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017623 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017624 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17625 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070017626 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017627 ds_image_create_info.extent.width = 64;
17628 ds_image_create_info.extent.height = 64;
17629 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017630 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 -060017631
17632 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017633 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017635 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 -060017636
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017638
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017639 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017640 &color_range);
17641
17642 m_errorMonitor->VerifyFound();
17643
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17645 "vkCmdClearColorImage called with "
17646 "image created without "
17647 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017648
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017649 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017650 &color_range);
17651
17652 m_errorMonitor->VerifyFound();
17653
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017654 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17656 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017657
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017658 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17659 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017660
17661 m_errorMonitor->VerifyFound();
17662}
Tobin Ehliscde08892015-09-22 10:11:37 -060017663
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017664// WSI Enabled Tests
17665//
Chris Forbes09368e42016-10-13 11:59:22 +130017666#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017667TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17668
17669#if defined(VK_USE_PLATFORM_XCB_KHR)
17670 VkSurfaceKHR surface = VK_NULL_HANDLE;
17671
17672 VkResult err;
17673 bool pass;
17674 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17675 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17676 // uint32_t swapchain_image_count = 0;
17677 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17678 // uint32_t image_index = 0;
17679 // VkPresentInfoKHR present_info = {};
17680
17681 ASSERT_NO_FATAL_FAILURE(InitState());
17682
17683 // Use the create function from one of the VK_KHR_*_surface extension in
17684 // order to create a surface, testing all known errors in the process,
17685 // before successfully creating a surface:
17686 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17688 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17689 pass = (err != VK_SUCCESS);
17690 ASSERT_TRUE(pass);
17691 m_errorMonitor->VerifyFound();
17692
17693 // Next, try to create a surface with the wrong
17694 // VkXcbSurfaceCreateInfoKHR::sType:
17695 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17696 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17698 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17699 pass = (err != VK_SUCCESS);
17700 ASSERT_TRUE(pass);
17701 m_errorMonitor->VerifyFound();
17702
17703 // Create a native window, and then correctly create a surface:
17704 xcb_connection_t *connection;
17705 xcb_screen_t *screen;
17706 xcb_window_t xcb_window;
17707 xcb_intern_atom_reply_t *atom_wm_delete_window;
17708
17709 const xcb_setup_t *setup;
17710 xcb_screen_iterator_t iter;
17711 int scr;
17712 uint32_t value_mask, value_list[32];
17713 int width = 1;
17714 int height = 1;
17715
17716 connection = xcb_connect(NULL, &scr);
17717 ASSERT_TRUE(connection != NULL);
17718 setup = xcb_get_setup(connection);
17719 iter = xcb_setup_roots_iterator(setup);
17720 while (scr-- > 0)
17721 xcb_screen_next(&iter);
17722 screen = iter.data;
17723
17724 xcb_window = xcb_generate_id(connection);
17725
17726 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17727 value_list[0] = screen->black_pixel;
17728 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17729
17730 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17731 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17732
17733 /* Magic code that will send notification when window is destroyed */
17734 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17735 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17736
17737 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17738 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17739 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17740 free(reply);
17741
17742 xcb_map_window(connection, xcb_window);
17743
17744 // Force the x/y coordinates to 100,100 results are identical in consecutive
17745 // runs
17746 const uint32_t coords[] = { 100, 100 };
17747 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17748
17749 // Finally, try to correctly create a surface:
17750 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17751 xcb_create_info.pNext = NULL;
17752 xcb_create_info.flags = 0;
17753 xcb_create_info.connection = connection;
17754 xcb_create_info.window = xcb_window;
17755 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17756 pass = (err == VK_SUCCESS);
17757 ASSERT_TRUE(pass);
17758
17759 // Check if surface supports presentation:
17760
17761 // 1st, do so without having queried the queue families:
17762 VkBool32 supported = false;
17763 // TODO: Get the following error to come out:
17764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17765 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17766 "function");
17767 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17768 pass = (err != VK_SUCCESS);
17769 // ASSERT_TRUE(pass);
17770 // m_errorMonitor->VerifyFound();
17771
17772 // Next, query a queue family index that's too large:
17773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17774 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17775 pass = (err != VK_SUCCESS);
17776 ASSERT_TRUE(pass);
17777 m_errorMonitor->VerifyFound();
17778
17779 // Finally, do so correctly:
17780 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17781 // SUPPORTED
17782 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17783 pass = (err == VK_SUCCESS);
17784 ASSERT_TRUE(pass);
17785
17786 // Before proceeding, try to create a swapchain without having called
17787 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17788 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17789 swapchain_create_info.pNext = NULL;
17790 swapchain_create_info.flags = 0;
17791 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17792 swapchain_create_info.surface = surface;
17793 swapchain_create_info.imageArrayLayers = 1;
17794 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17795 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17797 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17798 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17799 pass = (err != VK_SUCCESS);
17800 ASSERT_TRUE(pass);
17801 m_errorMonitor->VerifyFound();
17802
17803 // Get the surface capabilities:
17804 VkSurfaceCapabilitiesKHR surface_capabilities;
17805
17806 // Do so correctly (only error logged by this entrypoint is if the
17807 // extension isn't enabled):
17808 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17809 pass = (err == VK_SUCCESS);
17810 ASSERT_TRUE(pass);
17811
17812 // Get the surface formats:
17813 uint32_t surface_format_count;
17814
17815 // First, try without a pointer to surface_format_count:
17816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17817 "specified as NULL");
17818 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17819 pass = (err == VK_SUCCESS);
17820 ASSERT_TRUE(pass);
17821 m_errorMonitor->VerifyFound();
17822
17823 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17824 // correctly done a 1st try (to get the count):
17825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17826 surface_format_count = 0;
17827 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17828 pass = (err == VK_SUCCESS);
17829 ASSERT_TRUE(pass);
17830 m_errorMonitor->VerifyFound();
17831
17832 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17833 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17834 pass = (err == VK_SUCCESS);
17835 ASSERT_TRUE(pass);
17836
17837 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17838 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17839
17840 // Next, do a 2nd try with surface_format_count being set too high:
17841 surface_format_count += 5;
17842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17843 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17844 pass = (err == VK_SUCCESS);
17845 ASSERT_TRUE(pass);
17846 m_errorMonitor->VerifyFound();
17847
17848 // Finally, do a correct 1st and 2nd try:
17849 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17850 pass = (err == VK_SUCCESS);
17851 ASSERT_TRUE(pass);
17852 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17853 pass = (err == VK_SUCCESS);
17854 ASSERT_TRUE(pass);
17855
17856 // Get the surface present modes:
17857 uint32_t surface_present_mode_count;
17858
17859 // First, try without a pointer to surface_format_count:
17860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17861 "specified as NULL");
17862
17863 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17864 pass = (err == VK_SUCCESS);
17865 ASSERT_TRUE(pass);
17866 m_errorMonitor->VerifyFound();
17867
17868 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17869 // correctly done a 1st try (to get the count):
17870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17871 surface_present_mode_count = 0;
17872 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17873 (VkPresentModeKHR *)&surface_present_mode_count);
17874 pass = (err == VK_SUCCESS);
17875 ASSERT_TRUE(pass);
17876 m_errorMonitor->VerifyFound();
17877
17878 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17879 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17880 pass = (err == VK_SUCCESS);
17881 ASSERT_TRUE(pass);
17882
17883 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17884 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17885
17886 // Next, do a 2nd try with surface_format_count being set too high:
17887 surface_present_mode_count += 5;
17888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17889 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17890 pass = (err == VK_SUCCESS);
17891 ASSERT_TRUE(pass);
17892 m_errorMonitor->VerifyFound();
17893
17894 // Finally, do a correct 1st and 2nd try:
17895 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17896 pass = (err == VK_SUCCESS);
17897 ASSERT_TRUE(pass);
17898 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17899 pass = (err == VK_SUCCESS);
17900 ASSERT_TRUE(pass);
17901
17902 // Create a swapchain:
17903
17904 // First, try without a pointer to swapchain_create_info:
17905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17906 "specified as NULL");
17907
17908 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17909 pass = (err != VK_SUCCESS);
17910 ASSERT_TRUE(pass);
17911 m_errorMonitor->VerifyFound();
17912
17913 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17914 // sType:
17915 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17917
17918 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17919 pass = (err != VK_SUCCESS);
17920 ASSERT_TRUE(pass);
17921 m_errorMonitor->VerifyFound();
17922
17923 // Next, call with a NULL swapchain pointer:
17924 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17925 swapchain_create_info.pNext = NULL;
17926 swapchain_create_info.flags = 0;
17927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17928 "specified as NULL");
17929
17930 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17931 pass = (err != VK_SUCCESS);
17932 ASSERT_TRUE(pass);
17933 m_errorMonitor->VerifyFound();
17934
17935 // TODO: Enhance swapchain layer so that
17936 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17937
17938 // Next, call with a queue family index that's too large:
17939 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17940 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17941 swapchain_create_info.queueFamilyIndexCount = 2;
17942 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17944 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17945 pass = (err != VK_SUCCESS);
17946 ASSERT_TRUE(pass);
17947 m_errorMonitor->VerifyFound();
17948
17949 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17950 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17951 swapchain_create_info.queueFamilyIndexCount = 1;
17952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17953 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17954 "pCreateInfo->pQueueFamilyIndices).");
17955 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17956 pass = (err != VK_SUCCESS);
17957 ASSERT_TRUE(pass);
17958 m_errorMonitor->VerifyFound();
17959
17960 // Next, call with an invalid imageSharingMode:
17961 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17962 swapchain_create_info.queueFamilyIndexCount = 1;
17963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17964 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17965 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17966 pass = (err != VK_SUCCESS);
17967 ASSERT_TRUE(pass);
17968 m_errorMonitor->VerifyFound();
17969 // Fix for the future:
17970 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17971 // SUPPORTED
17972 swapchain_create_info.queueFamilyIndexCount = 0;
17973 queueFamilyIndex[0] = 0;
17974 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17975
17976 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17977 // Get the images from a swapchain:
17978 // Acquire an image from a swapchain:
17979 // Present an image to a swapchain:
17980 // Destroy the swapchain:
17981
17982 // TODOs:
17983 //
17984 // - Try destroying the device without first destroying the swapchain
17985 //
17986 // - Try destroying the device without first destroying the surface
17987 //
17988 // - Try destroying the surface without first destroying the swapchain
17989
17990 // Destroy the surface:
17991 vkDestroySurfaceKHR(instance(), surface, NULL);
17992
17993 // Tear down the window:
17994 xcb_destroy_window(connection, xcb_window);
17995 xcb_disconnect(connection);
17996
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017997#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017998 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017999#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018000}
Chris Forbes09368e42016-10-13 11:59:22 +130018001#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018002
18003//
18004// POSITIVE VALIDATION TESTS
18005//
18006// These tests do not expect to encounter ANY validation errors pass only if this is true
18007
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070018008TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
18009 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
18010 ASSERT_NO_FATAL_FAILURE(InitState());
18011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18012
18013 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18014 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18015 command_buffer_allocate_info.commandPool = m_commandPool;
18016 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18017 command_buffer_allocate_info.commandBufferCount = 1;
18018
18019 VkCommandBuffer secondary_command_buffer;
18020 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18021 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18022 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18023 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18024 command_buffer_inheritance_info.renderPass = m_renderPass;
18025 command_buffer_inheritance_info.framebuffer = m_framebuffer;
18026
18027 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18028 command_buffer_begin_info.flags =
18029 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
18030 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18031
18032 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18033 VkClearAttachment color_attachment;
18034 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18035 color_attachment.clearValue.color.float32[0] = 0;
18036 color_attachment.clearValue.color.float32[1] = 0;
18037 color_attachment.clearValue.color.float32[2] = 0;
18038 color_attachment.clearValue.color.float32[3] = 0;
18039 color_attachment.colorAttachment = 0;
18040 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
18041 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
18042}
18043
Tobin Ehlise0006882016-11-03 10:14:28 -060018044TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018045 TEST_DESCRIPTION(
18046 "Perform an image layout transition in a secondary command buffer followed "
18047 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060018048 VkResult err;
18049 m_errorMonitor->ExpectSuccess();
18050 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070018051 auto depth_format = find_depth_stencil_format(m_device);
18052 if (!depth_format) {
18053 return;
18054 }
Tobin Ehlise0006882016-11-03 10:14:28 -060018055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18056 // Allocate a secondary and primary cmd buffer
18057 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18058 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18059 command_buffer_allocate_info.commandPool = m_commandPool;
18060 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18061 command_buffer_allocate_info.commandBufferCount = 1;
18062
18063 VkCommandBuffer secondary_command_buffer;
18064 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18065 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18066 VkCommandBuffer primary_command_buffer;
18067 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
18068 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18069 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18070 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18071 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18072 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
18073 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18074
18075 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18076 ASSERT_VK_SUCCESS(err);
18077 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070018078 image.init(128, 128, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlise0006882016-11-03 10:14:28 -060018079 ASSERT_TRUE(image.initialized());
18080 VkImageMemoryBarrier img_barrier = {};
18081 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18082 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18083 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18084 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18085 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18086 img_barrier.image = image.handle();
18087 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18088 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18089 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18090 img_barrier.subresourceRange.baseArrayLayer = 0;
18091 img_barrier.subresourceRange.baseMipLevel = 0;
18092 img_barrier.subresourceRange.layerCount = 1;
18093 img_barrier.subresourceRange.levelCount = 1;
18094 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
18095 0, nullptr, 1, &img_barrier);
18096 err = vkEndCommandBuffer(secondary_command_buffer);
18097 ASSERT_VK_SUCCESS(err);
18098
18099 // Now update primary cmd buffer to execute secondary and transitions image
18100 command_buffer_begin_info.pInheritanceInfo = nullptr;
18101 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
18102 ASSERT_VK_SUCCESS(err);
18103 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
18104 VkImageMemoryBarrier img_barrier2 = {};
18105 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18106 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18107 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18108 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18109 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18110 img_barrier2.image = image.handle();
18111 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18112 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18113 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18114 img_barrier2.subresourceRange.baseArrayLayer = 0;
18115 img_barrier2.subresourceRange.baseMipLevel = 0;
18116 img_barrier2.subresourceRange.layerCount = 1;
18117 img_barrier2.subresourceRange.levelCount = 1;
18118 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
18119 nullptr, 1, &img_barrier2);
18120 err = vkEndCommandBuffer(primary_command_buffer);
18121 ASSERT_VK_SUCCESS(err);
18122 VkSubmitInfo submit_info = {};
18123 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18124 submit_info.commandBufferCount = 1;
18125 submit_info.pCommandBuffers = &primary_command_buffer;
18126 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18127 ASSERT_VK_SUCCESS(err);
18128 m_errorMonitor->VerifyNotFound();
18129 err = vkDeviceWaitIdle(m_device->device());
18130 ASSERT_VK_SUCCESS(err);
18131 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
18132 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
18133}
18134
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018135// This is a positive test. No failures are expected.
18136TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018137 TEST_DESCRIPTION(
18138 "Ensure that the vkUpdateDescriptorSets validation code "
18139 "is ignoring VkWriteDescriptorSet members that are not "
18140 "related to the descriptor type specified by "
18141 "VkWriteDescriptorSet::descriptorType. Correct "
18142 "validation behavior will result in the test running to "
18143 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018144
18145 const uintptr_t invalid_ptr = 0xcdcdcdcd;
18146
18147 ASSERT_NO_FATAL_FAILURE(InitState());
18148
18149 // Image Case
18150 {
18151 m_errorMonitor->ExpectSuccess();
18152
18153 VkImage image;
18154 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
18155 const int32_t tex_width = 32;
18156 const int32_t tex_height = 32;
18157 VkImageCreateInfo image_create_info = {};
18158 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18159 image_create_info.pNext = NULL;
18160 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18161 image_create_info.format = tex_format;
18162 image_create_info.extent.width = tex_width;
18163 image_create_info.extent.height = tex_height;
18164 image_create_info.extent.depth = 1;
18165 image_create_info.mipLevels = 1;
18166 image_create_info.arrayLayers = 1;
18167 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18168 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18169 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18170 image_create_info.flags = 0;
18171 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18172 ASSERT_VK_SUCCESS(err);
18173
18174 VkMemoryRequirements memory_reqs;
18175 VkDeviceMemory image_memory;
18176 bool pass;
18177 VkMemoryAllocateInfo memory_info = {};
18178 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18179 memory_info.pNext = NULL;
18180 memory_info.allocationSize = 0;
18181 memory_info.memoryTypeIndex = 0;
18182 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18183 memory_info.allocationSize = memory_reqs.size;
18184 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18185 ASSERT_TRUE(pass);
18186 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
18187 ASSERT_VK_SUCCESS(err);
18188 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
18189 ASSERT_VK_SUCCESS(err);
18190
18191 VkImageViewCreateInfo image_view_create_info = {};
18192 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18193 image_view_create_info.image = image;
18194 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18195 image_view_create_info.format = tex_format;
18196 image_view_create_info.subresourceRange.layerCount = 1;
18197 image_view_create_info.subresourceRange.baseMipLevel = 0;
18198 image_view_create_info.subresourceRange.levelCount = 1;
18199 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18200
18201 VkImageView view;
18202 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
18203 ASSERT_VK_SUCCESS(err);
18204
18205 VkDescriptorPoolSize ds_type_count = {};
18206 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18207 ds_type_count.descriptorCount = 1;
18208
18209 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18210 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18211 ds_pool_ci.pNext = NULL;
18212 ds_pool_ci.maxSets = 1;
18213 ds_pool_ci.poolSizeCount = 1;
18214 ds_pool_ci.pPoolSizes = &ds_type_count;
18215
18216 VkDescriptorPool ds_pool;
18217 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18218 ASSERT_VK_SUCCESS(err);
18219
18220 VkDescriptorSetLayoutBinding dsl_binding = {};
18221 dsl_binding.binding = 0;
18222 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18223 dsl_binding.descriptorCount = 1;
18224 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18225 dsl_binding.pImmutableSamplers = NULL;
18226
18227 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18228 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18229 ds_layout_ci.pNext = NULL;
18230 ds_layout_ci.bindingCount = 1;
18231 ds_layout_ci.pBindings = &dsl_binding;
18232 VkDescriptorSetLayout ds_layout;
18233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18234 ASSERT_VK_SUCCESS(err);
18235
18236 VkDescriptorSet descriptor_set;
18237 VkDescriptorSetAllocateInfo alloc_info = {};
18238 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18239 alloc_info.descriptorSetCount = 1;
18240 alloc_info.descriptorPool = ds_pool;
18241 alloc_info.pSetLayouts = &ds_layout;
18242 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18243 ASSERT_VK_SUCCESS(err);
18244
18245 VkDescriptorImageInfo image_info = {};
18246 image_info.imageView = view;
18247 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18248
18249 VkWriteDescriptorSet descriptor_write;
18250 memset(&descriptor_write, 0, sizeof(descriptor_write));
18251 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18252 descriptor_write.dstSet = descriptor_set;
18253 descriptor_write.dstBinding = 0;
18254 descriptor_write.descriptorCount = 1;
18255 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18256 descriptor_write.pImageInfo = &image_info;
18257
18258 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18259 // be
18260 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18261 // This will most likely produce a crash if the parameter_validation
18262 // layer
18263 // does not correctly ignore pBufferInfo.
18264 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18265 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18266
18267 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18268
18269 m_errorMonitor->VerifyNotFound();
18270
18271 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18272 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18273 vkDestroyImageView(m_device->device(), view, NULL);
18274 vkDestroyImage(m_device->device(), image, NULL);
18275 vkFreeMemory(m_device->device(), image_memory, NULL);
18276 }
18277
18278 // Buffer Case
18279 {
18280 m_errorMonitor->ExpectSuccess();
18281
18282 VkBuffer buffer;
18283 uint32_t queue_family_index = 0;
18284 VkBufferCreateInfo buffer_create_info = {};
18285 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18286 buffer_create_info.size = 1024;
18287 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18288 buffer_create_info.queueFamilyIndexCount = 1;
18289 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18290
18291 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18292 ASSERT_VK_SUCCESS(err);
18293
18294 VkMemoryRequirements memory_reqs;
18295 VkDeviceMemory buffer_memory;
18296 bool pass;
18297 VkMemoryAllocateInfo memory_info = {};
18298 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18299 memory_info.pNext = NULL;
18300 memory_info.allocationSize = 0;
18301 memory_info.memoryTypeIndex = 0;
18302
18303 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18304 memory_info.allocationSize = memory_reqs.size;
18305 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18306 ASSERT_TRUE(pass);
18307
18308 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18309 ASSERT_VK_SUCCESS(err);
18310 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18311 ASSERT_VK_SUCCESS(err);
18312
18313 VkDescriptorPoolSize ds_type_count = {};
18314 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18315 ds_type_count.descriptorCount = 1;
18316
18317 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18318 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18319 ds_pool_ci.pNext = NULL;
18320 ds_pool_ci.maxSets = 1;
18321 ds_pool_ci.poolSizeCount = 1;
18322 ds_pool_ci.pPoolSizes = &ds_type_count;
18323
18324 VkDescriptorPool ds_pool;
18325 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18326 ASSERT_VK_SUCCESS(err);
18327
18328 VkDescriptorSetLayoutBinding dsl_binding = {};
18329 dsl_binding.binding = 0;
18330 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18331 dsl_binding.descriptorCount = 1;
18332 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18333 dsl_binding.pImmutableSamplers = NULL;
18334
18335 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18336 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18337 ds_layout_ci.pNext = NULL;
18338 ds_layout_ci.bindingCount = 1;
18339 ds_layout_ci.pBindings = &dsl_binding;
18340 VkDescriptorSetLayout ds_layout;
18341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18342 ASSERT_VK_SUCCESS(err);
18343
18344 VkDescriptorSet descriptor_set;
18345 VkDescriptorSetAllocateInfo alloc_info = {};
18346 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18347 alloc_info.descriptorSetCount = 1;
18348 alloc_info.descriptorPool = ds_pool;
18349 alloc_info.pSetLayouts = &ds_layout;
18350 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18351 ASSERT_VK_SUCCESS(err);
18352
18353 VkDescriptorBufferInfo buffer_info = {};
18354 buffer_info.buffer = buffer;
18355 buffer_info.offset = 0;
18356 buffer_info.range = 1024;
18357
18358 VkWriteDescriptorSet descriptor_write;
18359 memset(&descriptor_write, 0, sizeof(descriptor_write));
18360 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18361 descriptor_write.dstSet = descriptor_set;
18362 descriptor_write.dstBinding = 0;
18363 descriptor_write.descriptorCount = 1;
18364 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18365 descriptor_write.pBufferInfo = &buffer_info;
18366
18367 // Set pImageInfo and pTexelBufferView to invalid values, which should
18368 // be
18369 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18370 // This will most likely produce a crash if the parameter_validation
18371 // layer
18372 // does not correctly ignore pImageInfo.
18373 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18374 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18375
18376 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18377
18378 m_errorMonitor->VerifyNotFound();
18379
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018380 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18382 vkDestroyBuffer(m_device->device(), buffer, NULL);
18383 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18384 }
18385
18386 // Texel Buffer Case
18387 {
18388 m_errorMonitor->ExpectSuccess();
18389
18390 VkBuffer buffer;
18391 uint32_t queue_family_index = 0;
18392 VkBufferCreateInfo buffer_create_info = {};
18393 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18394 buffer_create_info.size = 1024;
18395 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18396 buffer_create_info.queueFamilyIndexCount = 1;
18397 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18398
18399 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18400 ASSERT_VK_SUCCESS(err);
18401
18402 VkMemoryRequirements memory_reqs;
18403 VkDeviceMemory buffer_memory;
18404 bool pass;
18405 VkMemoryAllocateInfo memory_info = {};
18406 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18407 memory_info.pNext = NULL;
18408 memory_info.allocationSize = 0;
18409 memory_info.memoryTypeIndex = 0;
18410
18411 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18412 memory_info.allocationSize = memory_reqs.size;
18413 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18414 ASSERT_TRUE(pass);
18415
18416 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18417 ASSERT_VK_SUCCESS(err);
18418 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18419 ASSERT_VK_SUCCESS(err);
18420
18421 VkBufferViewCreateInfo buff_view_ci = {};
18422 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18423 buff_view_ci.buffer = buffer;
18424 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18425 buff_view_ci.range = VK_WHOLE_SIZE;
18426 VkBufferView buffer_view;
18427 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18428
18429 VkDescriptorPoolSize ds_type_count = {};
18430 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18431 ds_type_count.descriptorCount = 1;
18432
18433 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18434 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18435 ds_pool_ci.pNext = NULL;
18436 ds_pool_ci.maxSets = 1;
18437 ds_pool_ci.poolSizeCount = 1;
18438 ds_pool_ci.pPoolSizes = &ds_type_count;
18439
18440 VkDescriptorPool ds_pool;
18441 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18442 ASSERT_VK_SUCCESS(err);
18443
18444 VkDescriptorSetLayoutBinding dsl_binding = {};
18445 dsl_binding.binding = 0;
18446 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18447 dsl_binding.descriptorCount = 1;
18448 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18449 dsl_binding.pImmutableSamplers = NULL;
18450
18451 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18452 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18453 ds_layout_ci.pNext = NULL;
18454 ds_layout_ci.bindingCount = 1;
18455 ds_layout_ci.pBindings = &dsl_binding;
18456 VkDescriptorSetLayout ds_layout;
18457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18458 ASSERT_VK_SUCCESS(err);
18459
18460 VkDescriptorSet descriptor_set;
18461 VkDescriptorSetAllocateInfo alloc_info = {};
18462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18463 alloc_info.descriptorSetCount = 1;
18464 alloc_info.descriptorPool = ds_pool;
18465 alloc_info.pSetLayouts = &ds_layout;
18466 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18467 ASSERT_VK_SUCCESS(err);
18468
18469 VkWriteDescriptorSet descriptor_write;
18470 memset(&descriptor_write, 0, sizeof(descriptor_write));
18471 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18472 descriptor_write.dstSet = descriptor_set;
18473 descriptor_write.dstBinding = 0;
18474 descriptor_write.descriptorCount = 1;
18475 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18476 descriptor_write.pTexelBufferView = &buffer_view;
18477
18478 // Set pImageInfo and pBufferInfo to invalid values, which should be
18479 // ignored for descriptorType ==
18480 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18481 // This will most likely produce a crash if the parameter_validation
18482 // layer
18483 // does not correctly ignore pImageInfo and pBufferInfo.
18484 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18485 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18486
18487 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18488
18489 m_errorMonitor->VerifyNotFound();
18490
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018491 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18492 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18493 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18494 vkDestroyBuffer(m_device->device(), buffer, NULL);
18495 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18496 }
18497}
18498
Tobin Ehlisf7428442016-10-25 07:58:24 -060018499TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18500 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18501
18502 ASSERT_NO_FATAL_FAILURE(InitState());
18503 // Create layout where two binding #s are "1"
18504 static const uint32_t NUM_BINDINGS = 3;
18505 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18506 dsl_binding[0].binding = 1;
18507 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18508 dsl_binding[0].descriptorCount = 1;
18509 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18510 dsl_binding[0].pImmutableSamplers = NULL;
18511 dsl_binding[1].binding = 0;
18512 dsl_binding[1].descriptorCount = 1;
18513 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18514 dsl_binding[1].descriptorCount = 1;
18515 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18516 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018517 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018518 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18519 dsl_binding[2].descriptorCount = 1;
18520 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18521 dsl_binding[2].pImmutableSamplers = NULL;
18522
18523 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18524 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18525 ds_layout_ci.pNext = NULL;
18526 ds_layout_ci.bindingCount = NUM_BINDINGS;
18527 ds_layout_ci.pBindings = dsl_binding;
18528 VkDescriptorSetLayout ds_layout;
18529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18530 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18531 m_errorMonitor->VerifyFound();
18532}
18533
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018534TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018535 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18536
18537 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018538
Tony Barbour552f6c02016-12-21 14:34:07 -070018539 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018540
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018541 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18542
18543 {
18544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18545 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18546 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18547 m_errorMonitor->VerifyFound();
18548 }
18549
18550 {
18551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18552 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18553 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18554 m_errorMonitor->VerifyFound();
18555 }
18556
18557 {
18558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18559 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18560 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18561 m_errorMonitor->VerifyFound();
18562 }
18563
18564 {
18565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18566 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18567 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18568 m_errorMonitor->VerifyFound();
18569 }
18570
18571 {
18572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18573 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18574 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18575 m_errorMonitor->VerifyFound();
18576 }
18577
18578 {
18579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18580 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18581 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18582 m_errorMonitor->VerifyFound();
18583 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018584
18585 {
18586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18587 VkRect2D scissor = {{-1, 0}, {16, 16}};
18588 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18589 m_errorMonitor->VerifyFound();
18590 }
18591
18592 {
18593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18594 VkRect2D scissor = {{0, -2}, {16, 16}};
18595 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18596 m_errorMonitor->VerifyFound();
18597 }
18598
18599 {
18600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18601 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18602 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18603 m_errorMonitor->VerifyFound();
18604 }
18605
18606 {
18607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18608 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18609 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18610 m_errorMonitor->VerifyFound();
18611 }
18612
Tony Barbour552f6c02016-12-21 14:34:07 -070018613 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018614}
18615
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018616// This is a positive test. No failures are expected.
18617TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18618 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18619 VkResult err;
18620
18621 ASSERT_NO_FATAL_FAILURE(InitState());
18622 m_errorMonitor->ExpectSuccess();
18623 VkDescriptorPoolSize ds_type_count = {};
18624 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18625 ds_type_count.descriptorCount = 2;
18626
18627 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18628 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18629 ds_pool_ci.pNext = NULL;
18630 ds_pool_ci.maxSets = 1;
18631 ds_pool_ci.poolSizeCount = 1;
18632 ds_pool_ci.pPoolSizes = &ds_type_count;
18633
18634 VkDescriptorPool ds_pool;
18635 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18636 ASSERT_VK_SUCCESS(err);
18637
18638 // Create layout with two uniform buffer descriptors w/ empty binding between them
18639 static const uint32_t NUM_BINDINGS = 3;
18640 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18641 dsl_binding[0].binding = 0;
18642 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18643 dsl_binding[0].descriptorCount = 1;
18644 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18645 dsl_binding[0].pImmutableSamplers = NULL;
18646 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018647 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018648 dsl_binding[2].binding = 2;
18649 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18650 dsl_binding[2].descriptorCount = 1;
18651 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18652 dsl_binding[2].pImmutableSamplers = NULL;
18653
18654 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18655 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18656 ds_layout_ci.pNext = NULL;
18657 ds_layout_ci.bindingCount = NUM_BINDINGS;
18658 ds_layout_ci.pBindings = dsl_binding;
18659 VkDescriptorSetLayout ds_layout;
18660 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18661 ASSERT_VK_SUCCESS(err);
18662
18663 VkDescriptorSet descriptor_set = {};
18664 VkDescriptorSetAllocateInfo alloc_info = {};
18665 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18666 alloc_info.descriptorSetCount = 1;
18667 alloc_info.descriptorPool = ds_pool;
18668 alloc_info.pSetLayouts = &ds_layout;
18669 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18670 ASSERT_VK_SUCCESS(err);
18671
18672 // Create a buffer to be used for update
18673 VkBufferCreateInfo buff_ci = {};
18674 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18675 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18676 buff_ci.size = 256;
18677 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18678 VkBuffer buffer;
18679 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18680 ASSERT_VK_SUCCESS(err);
18681 // Have to bind memory to buffer before descriptor update
18682 VkMemoryAllocateInfo mem_alloc = {};
18683 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18684 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018685 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018686 mem_alloc.memoryTypeIndex = 0;
18687
18688 VkMemoryRequirements mem_reqs;
18689 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18690 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18691 if (!pass) {
18692 vkDestroyBuffer(m_device->device(), buffer, NULL);
18693 return;
18694 }
18695
18696 VkDeviceMemory mem;
18697 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18698 ASSERT_VK_SUCCESS(err);
18699 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18700 ASSERT_VK_SUCCESS(err);
18701
18702 // Only update the descriptor at binding 2
18703 VkDescriptorBufferInfo buff_info = {};
18704 buff_info.buffer = buffer;
18705 buff_info.offset = 0;
18706 buff_info.range = VK_WHOLE_SIZE;
18707 VkWriteDescriptorSet descriptor_write = {};
18708 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18709 descriptor_write.dstBinding = 2;
18710 descriptor_write.descriptorCount = 1;
18711 descriptor_write.pTexelBufferView = nullptr;
18712 descriptor_write.pBufferInfo = &buff_info;
18713 descriptor_write.pImageInfo = nullptr;
18714 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18715 descriptor_write.dstSet = descriptor_set;
18716
18717 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18718
18719 m_errorMonitor->VerifyNotFound();
18720 // Cleanup
18721 vkFreeMemory(m_device->device(), mem, NULL);
18722 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18723 vkDestroyBuffer(m_device->device(), buffer, NULL);
18724 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18725}
18726
18727// This is a positive test. No failures are expected.
18728TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18729 VkResult err;
18730 bool pass;
18731
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018732 TEST_DESCRIPTION(
18733 "Create a buffer, allocate memory, bind memory, destroy "
18734 "the buffer, create an image, and bind the same memory to "
18735 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018736
18737 m_errorMonitor->ExpectSuccess();
18738
18739 ASSERT_NO_FATAL_FAILURE(InitState());
18740
18741 VkBuffer buffer;
18742 VkImage image;
18743 VkDeviceMemory mem;
18744 VkMemoryRequirements mem_reqs;
18745
18746 VkBufferCreateInfo buf_info = {};
18747 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18748 buf_info.pNext = NULL;
18749 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18750 buf_info.size = 256;
18751 buf_info.queueFamilyIndexCount = 0;
18752 buf_info.pQueueFamilyIndices = NULL;
18753 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18754 buf_info.flags = 0;
18755 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18756 ASSERT_VK_SUCCESS(err);
18757
18758 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18759
18760 VkMemoryAllocateInfo alloc_info = {};
18761 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18762 alloc_info.pNext = NULL;
18763 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018764
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018765 // Ensure memory is big enough for both bindings
18766 alloc_info.allocationSize = 0x10000;
18767
18768 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18769 if (!pass) {
18770 vkDestroyBuffer(m_device->device(), buffer, NULL);
18771 return;
18772 }
18773
18774 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18775 ASSERT_VK_SUCCESS(err);
18776
18777 uint8_t *pData;
18778 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18779 ASSERT_VK_SUCCESS(err);
18780
18781 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18782
18783 vkUnmapMemory(m_device->device(), mem);
18784
18785 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18786 ASSERT_VK_SUCCESS(err);
18787
18788 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18789 // memory. In fact, it was never used by the GPU.
18790 // Just be be sure, wait for idle.
18791 vkDestroyBuffer(m_device->device(), buffer, NULL);
18792 vkDeviceWaitIdle(m_device->device());
18793
Tobin Ehlis6a005702016-12-28 15:25:56 -070018794 // Use optimal as some platforms report linear support but then fail image creation
18795 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18796 VkImageFormatProperties image_format_properties;
18797 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18798 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18799 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018800 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018801 vkFreeMemory(m_device->device(), mem, NULL);
18802 return;
18803 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018804 VkImageCreateInfo image_create_info = {};
18805 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18806 image_create_info.pNext = NULL;
18807 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18808 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18809 image_create_info.extent.width = 64;
18810 image_create_info.extent.height = 64;
18811 image_create_info.extent.depth = 1;
18812 image_create_info.mipLevels = 1;
18813 image_create_info.arrayLayers = 1;
18814 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018815 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018816 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18817 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18818 image_create_info.queueFamilyIndexCount = 0;
18819 image_create_info.pQueueFamilyIndices = NULL;
18820 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18821 image_create_info.flags = 0;
18822
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018823 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018824 * to be textures or it will be the staging image if they are not.
18825 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018826 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18827 ASSERT_VK_SUCCESS(err);
18828
18829 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18830
Tobin Ehlis6a005702016-12-28 15:25:56 -070018831 VkMemoryAllocateInfo mem_alloc = {};
18832 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18833 mem_alloc.pNext = NULL;
18834 mem_alloc.allocationSize = 0;
18835 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018836 mem_alloc.allocationSize = mem_reqs.size;
18837
18838 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18839 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018840 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018841 vkDestroyImage(m_device->device(), image, NULL);
18842 return;
18843 }
18844
18845 // VALIDATION FAILURE:
18846 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18847 ASSERT_VK_SUCCESS(err);
18848
18849 m_errorMonitor->VerifyNotFound();
18850
18851 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018852 vkDestroyImage(m_device->device(), image, NULL);
18853}
18854
Tony Barbourab713912017-02-02 14:17:35 -070018855// This is a positive test. No failures are expected.
18856TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18857 VkResult err;
18858
18859 TEST_DESCRIPTION(
18860 "Call all applicable destroy and free routines with NULL"
18861 "handles, expecting no validation errors");
18862
18863 m_errorMonitor->ExpectSuccess();
18864
18865 ASSERT_NO_FATAL_FAILURE(InitState());
18866 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18867 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18868 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18869 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18870 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18871 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18872 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18873 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18874 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18875 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18876 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18877 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18878 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18879 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18880 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18881 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18882 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18883 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18884 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18885 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18886
18887 VkCommandPool command_pool;
18888 VkCommandPoolCreateInfo pool_create_info{};
18889 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18890 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18891 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18892 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18893 VkCommandBuffer command_buffers[3] = {};
18894 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18895 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18896 command_buffer_allocate_info.commandPool = command_pool;
18897 command_buffer_allocate_info.commandBufferCount = 1;
18898 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18899 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18900 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18901 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18902
18903 VkDescriptorPoolSize ds_type_count = {};
18904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18905 ds_type_count.descriptorCount = 1;
18906
18907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18909 ds_pool_ci.pNext = NULL;
18910 ds_pool_ci.maxSets = 1;
18911 ds_pool_ci.poolSizeCount = 1;
18912 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18913 ds_pool_ci.pPoolSizes = &ds_type_count;
18914
18915 VkDescriptorPool ds_pool;
18916 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18917 ASSERT_VK_SUCCESS(err);
18918
18919 VkDescriptorSetLayoutBinding dsl_binding = {};
18920 dsl_binding.binding = 2;
18921 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18922 dsl_binding.descriptorCount = 1;
18923 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18924 dsl_binding.pImmutableSamplers = NULL;
18925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18926 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18927 ds_layout_ci.pNext = NULL;
18928 ds_layout_ci.bindingCount = 1;
18929 ds_layout_ci.pBindings = &dsl_binding;
18930 VkDescriptorSetLayout ds_layout;
18931 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18932 ASSERT_VK_SUCCESS(err);
18933
18934 VkDescriptorSet descriptor_sets[3] = {};
18935 VkDescriptorSetAllocateInfo alloc_info = {};
18936 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18937 alloc_info.descriptorSetCount = 1;
18938 alloc_info.descriptorPool = ds_pool;
18939 alloc_info.pSetLayouts = &ds_layout;
18940 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18941 ASSERT_VK_SUCCESS(err);
18942 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18943 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18944 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18945
18946 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18947
18948 m_errorMonitor->VerifyNotFound();
18949}
18950
Tony Barbour626994c2017-02-08 15:29:37 -070018951TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018952 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018953
18954 m_errorMonitor->ExpectSuccess();
18955
18956 ASSERT_NO_FATAL_FAILURE(InitState());
18957 VkCommandBuffer cmd_bufs[4];
18958 VkCommandBufferAllocateInfo alloc_info;
18959 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18960 alloc_info.pNext = NULL;
18961 alloc_info.commandBufferCount = 4;
18962 alloc_info.commandPool = m_commandPool;
18963 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18964 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18965 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -070018966 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
18967 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
18968 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070018969 ASSERT_TRUE(image.initialized());
18970 VkCommandBufferBeginInfo cb_binfo;
18971 cb_binfo.pNext = NULL;
18972 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18973 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18974 cb_binfo.flags = 0;
18975 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18976 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18977 VkImageMemoryBarrier img_barrier = {};
18978 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18979 img_barrier.pNext = NULL;
18980 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18981 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18982 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18983 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18984 img_barrier.image = image.handle();
18985 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18986 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18987 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18988 img_barrier.subresourceRange.baseArrayLayer = 0;
18989 img_barrier.subresourceRange.baseMipLevel = 0;
18990 img_barrier.subresourceRange.layerCount = 1;
18991 img_barrier.subresourceRange.levelCount = 1;
18992 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18993 &img_barrier);
18994 vkEndCommandBuffer(cmd_bufs[0]);
18995 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18996 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18997 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18998 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18999 &img_barrier);
19000 vkEndCommandBuffer(cmd_bufs[1]);
19001 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
19002 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19003 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19004 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19005 &img_barrier);
19006 vkEndCommandBuffer(cmd_bufs[2]);
19007 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
19008 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19009 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19010 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19011 &img_barrier);
19012 vkEndCommandBuffer(cmd_bufs[3]);
19013
19014 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
19015 VkSemaphore semaphore1, semaphore2;
19016 VkSemaphoreCreateInfo semaphore_create_info{};
19017 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19018 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
19019 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
19020 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
19021 VkSubmitInfo submit_info[3];
19022 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19023 submit_info[0].pNext = nullptr;
19024 submit_info[0].commandBufferCount = 1;
19025 submit_info[0].pCommandBuffers = &cmd_bufs[0];
19026 submit_info[0].signalSemaphoreCount = 1;
19027 submit_info[0].pSignalSemaphores = &semaphore1;
19028 submit_info[0].waitSemaphoreCount = 0;
19029 submit_info[0].pWaitDstStageMask = nullptr;
19030 submit_info[0].pWaitDstStageMask = flags;
19031 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19032 submit_info[1].pNext = nullptr;
19033 submit_info[1].commandBufferCount = 1;
19034 submit_info[1].pCommandBuffers = &cmd_bufs[1];
19035 submit_info[1].waitSemaphoreCount = 1;
19036 submit_info[1].pWaitSemaphores = &semaphore1;
19037 submit_info[1].signalSemaphoreCount = 1;
19038 submit_info[1].pSignalSemaphores = &semaphore2;
19039 submit_info[1].pWaitDstStageMask = flags;
19040 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19041 submit_info[2].pNext = nullptr;
19042 submit_info[2].commandBufferCount = 2;
19043 submit_info[2].pCommandBuffers = &cmd_bufs[2];
19044 submit_info[2].waitSemaphoreCount = 1;
19045 submit_info[2].pWaitSemaphores = &semaphore2;
19046 submit_info[2].signalSemaphoreCount = 0;
19047 submit_info[2].pSignalSemaphores = nullptr;
19048 submit_info[2].pWaitDstStageMask = flags;
19049 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
19050 vkQueueWaitIdle(m_device->m_queue);
19051
19052 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
19053 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
19054 m_errorMonitor->VerifyNotFound();
19055}
19056
Tobin Ehlis953e8392016-11-17 10:54:13 -070019057TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
19058 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
19059 // We previously had a bug where dynamic offset of inactive bindings was still being used
19060 VkResult err;
19061 m_errorMonitor->ExpectSuccess();
19062
19063 ASSERT_NO_FATAL_FAILURE(InitState());
19064 ASSERT_NO_FATAL_FAILURE(InitViewport());
19065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19066
19067 VkDescriptorPoolSize ds_type_count = {};
19068 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19069 ds_type_count.descriptorCount = 3;
19070
19071 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19072 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19073 ds_pool_ci.pNext = NULL;
19074 ds_pool_ci.maxSets = 1;
19075 ds_pool_ci.poolSizeCount = 1;
19076 ds_pool_ci.pPoolSizes = &ds_type_count;
19077
19078 VkDescriptorPool ds_pool;
19079 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19080 ASSERT_VK_SUCCESS(err);
19081
19082 const uint32_t BINDING_COUNT = 3;
19083 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019084 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019085 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19086 dsl_binding[0].descriptorCount = 1;
19087 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19088 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019089 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019090 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19091 dsl_binding[1].descriptorCount = 1;
19092 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19093 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019094 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019095 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19096 dsl_binding[2].descriptorCount = 1;
19097 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19098 dsl_binding[2].pImmutableSamplers = NULL;
19099
19100 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19101 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19102 ds_layout_ci.pNext = NULL;
19103 ds_layout_ci.bindingCount = BINDING_COUNT;
19104 ds_layout_ci.pBindings = dsl_binding;
19105 VkDescriptorSetLayout ds_layout;
19106 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19107 ASSERT_VK_SUCCESS(err);
19108
19109 VkDescriptorSet descriptor_set;
19110 VkDescriptorSetAllocateInfo alloc_info = {};
19111 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19112 alloc_info.descriptorSetCount = 1;
19113 alloc_info.descriptorPool = ds_pool;
19114 alloc_info.pSetLayouts = &ds_layout;
19115 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19116 ASSERT_VK_SUCCESS(err);
19117
19118 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19119 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19120 pipeline_layout_ci.pNext = NULL;
19121 pipeline_layout_ci.setLayoutCount = 1;
19122 pipeline_layout_ci.pSetLayouts = &ds_layout;
19123
19124 VkPipelineLayout pipeline_layout;
19125 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19126 ASSERT_VK_SUCCESS(err);
19127
19128 // Create two buffers to update the descriptors with
19129 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
19130 uint32_t qfi = 0;
19131 VkBufferCreateInfo buffCI = {};
19132 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19133 buffCI.size = 2048;
19134 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19135 buffCI.queueFamilyIndexCount = 1;
19136 buffCI.pQueueFamilyIndices = &qfi;
19137
19138 VkBuffer dyub1;
19139 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
19140 ASSERT_VK_SUCCESS(err);
19141 // buffer2
19142 buffCI.size = 1024;
19143 VkBuffer dyub2;
19144 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
19145 ASSERT_VK_SUCCESS(err);
19146 // Allocate memory and bind to buffers
19147 VkMemoryAllocateInfo mem_alloc[2] = {};
19148 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19149 mem_alloc[0].pNext = NULL;
19150 mem_alloc[0].memoryTypeIndex = 0;
19151 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19152 mem_alloc[1].pNext = NULL;
19153 mem_alloc[1].memoryTypeIndex = 0;
19154
19155 VkMemoryRequirements mem_reqs1;
19156 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
19157 VkMemoryRequirements mem_reqs2;
19158 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
19159 mem_alloc[0].allocationSize = mem_reqs1.size;
19160 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
19161 mem_alloc[1].allocationSize = mem_reqs2.size;
19162 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
19163 if (!pass) {
19164 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19165 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19166 return;
19167 }
19168
19169 VkDeviceMemory mem1;
19170 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
19171 ASSERT_VK_SUCCESS(err);
19172 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
19173 ASSERT_VK_SUCCESS(err);
19174 VkDeviceMemory mem2;
19175 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
19176 ASSERT_VK_SUCCESS(err);
19177 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
19178 ASSERT_VK_SUCCESS(err);
19179 // Update descriptors
19180 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
19181 buff_info[0].buffer = dyub1;
19182 buff_info[0].offset = 0;
19183 buff_info[0].range = 256;
19184 buff_info[1].buffer = dyub1;
19185 buff_info[1].offset = 256;
19186 buff_info[1].range = 512;
19187 buff_info[2].buffer = dyub2;
19188 buff_info[2].offset = 0;
19189 buff_info[2].range = 512;
19190
19191 VkWriteDescriptorSet descriptor_write;
19192 memset(&descriptor_write, 0, sizeof(descriptor_write));
19193 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19194 descriptor_write.dstSet = descriptor_set;
19195 descriptor_write.dstBinding = 0;
19196 descriptor_write.descriptorCount = BINDING_COUNT;
19197 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19198 descriptor_write.pBufferInfo = buff_info;
19199
19200 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19201
Tony Barbour552f6c02016-12-21 14:34:07 -070019202 m_commandBuffer->BeginCommandBuffer();
19203 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070019204
19205 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019206 char const *vsSource =
19207 "#version 450\n"
19208 "\n"
19209 "out gl_PerVertex { \n"
19210 " vec4 gl_Position;\n"
19211 "};\n"
19212 "void main(){\n"
19213 " gl_Position = vec4(1);\n"
19214 "}\n";
19215 char const *fsSource =
19216 "#version 450\n"
19217 "\n"
19218 "layout(location=0) out vec4 x;\n"
19219 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
19220 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
19221 "void main(){\n"
19222 " x = vec4(bar1.y) + vec4(bar2.y);\n"
19223 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070019224 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19225 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19226 VkPipelineObj pipe(m_device);
19227 pipe.SetViewport(m_viewports);
19228 pipe.SetScissor(m_scissors);
19229 pipe.AddShader(&vs);
19230 pipe.AddShader(&fs);
19231 pipe.AddColorAttachment();
19232 pipe.CreateVKPipeline(pipeline_layout, renderPass());
19233
19234 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
19235 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
19236 // we used to have a bug in this case.
19237 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
19238 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19239 &descriptor_set, BINDING_COUNT, dyn_off);
19240 Draw(1, 0, 0, 0);
19241 m_errorMonitor->VerifyNotFound();
19242
19243 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19244 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19245 vkFreeMemory(m_device->device(), mem1, NULL);
19246 vkFreeMemory(m_device->device(), mem2, NULL);
19247
19248 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19249 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19250 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19251}
19252
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019253TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019254 TEST_DESCRIPTION(
19255 "Ensure that validations handling of non-coherent memory "
19256 "mapping while using VK_WHOLE_SIZE does not cause access "
19257 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019258 VkResult err;
19259 uint8_t *pData;
19260 ASSERT_NO_FATAL_FAILURE(InitState());
19261
19262 VkDeviceMemory mem;
19263 VkMemoryRequirements mem_reqs;
19264 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019265 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019266 VkMemoryAllocateInfo alloc_info = {};
19267 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19268 alloc_info.pNext = NULL;
19269 alloc_info.memoryTypeIndex = 0;
19270
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019271 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019272 alloc_info.allocationSize = allocation_size;
19273
19274 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19275 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 -070019276 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019277 if (!pass) {
19278 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019279 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19280 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019281 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019282 pass = m_device->phy().set_memory_type(
19283 mem_reqs.memoryTypeBits, &alloc_info,
19284 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19285 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019286 if (!pass) {
19287 return;
19288 }
19289 }
19290 }
19291
19292 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19293 ASSERT_VK_SUCCESS(err);
19294
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019295 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019296 m_errorMonitor->ExpectSuccess();
19297 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19298 ASSERT_VK_SUCCESS(err);
19299 VkMappedMemoryRange mmr = {};
19300 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19301 mmr.memory = mem;
19302 mmr.offset = 0;
19303 mmr.size = VK_WHOLE_SIZE;
19304 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19305 ASSERT_VK_SUCCESS(err);
19306 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19307 ASSERT_VK_SUCCESS(err);
19308 m_errorMonitor->VerifyNotFound();
19309 vkUnmapMemory(m_device->device(), mem);
19310
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019311 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019312 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019313 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019314 ASSERT_VK_SUCCESS(err);
19315 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19316 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019317 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019318 mmr.size = VK_WHOLE_SIZE;
19319 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19320 ASSERT_VK_SUCCESS(err);
19321 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19322 ASSERT_VK_SUCCESS(err);
19323 m_errorMonitor->VerifyNotFound();
19324 vkUnmapMemory(m_device->device(), mem);
19325
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019326 // Map with offset and size
19327 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019328 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019329 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019330 ASSERT_VK_SUCCESS(err);
19331 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19332 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019333 mmr.offset = 4 * atom_size;
19334 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019335 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19336 ASSERT_VK_SUCCESS(err);
19337 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19338 ASSERT_VK_SUCCESS(err);
19339 m_errorMonitor->VerifyNotFound();
19340 vkUnmapMemory(m_device->device(), mem);
19341
19342 // Map without offset and flush WHOLE_SIZE with two separate offsets
19343 m_errorMonitor->ExpectSuccess();
19344 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19345 ASSERT_VK_SUCCESS(err);
19346 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19347 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019348 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019349 mmr.size = VK_WHOLE_SIZE;
19350 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19351 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019352 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019353 mmr.size = VK_WHOLE_SIZE;
19354 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19355 ASSERT_VK_SUCCESS(err);
19356 m_errorMonitor->VerifyNotFound();
19357 vkUnmapMemory(m_device->device(), mem);
19358
19359 vkFreeMemory(m_device->device(), mem, NULL);
19360}
19361
19362// This is a positive test. We used to expect error in this case but spec now allows it
19363TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19364 m_errorMonitor->ExpectSuccess();
19365 vk_testing::Fence testFence;
19366 VkFenceCreateInfo fenceInfo = {};
19367 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19368 fenceInfo.pNext = NULL;
19369
19370 ASSERT_NO_FATAL_FAILURE(InitState());
19371 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019372 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019373 VkResult result = vkResetFences(m_device->device(), 1, fences);
19374 ASSERT_VK_SUCCESS(result);
19375
19376 m_errorMonitor->VerifyNotFound();
19377}
19378
19379TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19380 m_errorMonitor->ExpectSuccess();
19381
19382 ASSERT_NO_FATAL_FAILURE(InitState());
19383 VkResult err;
19384
19385 // Record (empty!) command buffer that can be submitted multiple times
19386 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019387 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19388 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019389 m_commandBuffer->BeginCommandBuffer(&cbbi);
19390 m_commandBuffer->EndCommandBuffer();
19391
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019392 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019393 VkFence fence;
19394 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19395 ASSERT_VK_SUCCESS(err);
19396
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019397 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019398 VkSemaphore s1, s2;
19399 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19400 ASSERT_VK_SUCCESS(err);
19401 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19402 ASSERT_VK_SUCCESS(err);
19403
19404 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019405 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019406 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19407 ASSERT_VK_SUCCESS(err);
19408
19409 // Submit CB again, signaling s2.
19410 si.pSignalSemaphores = &s2;
19411 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19412 ASSERT_VK_SUCCESS(err);
19413
19414 // Wait for fence.
19415 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19416 ASSERT_VK_SUCCESS(err);
19417
19418 // CB is still in flight from second submission, but semaphore s1 is no
19419 // longer in flight. delete it.
19420 vkDestroySemaphore(m_device->device(), s1, nullptr);
19421
19422 m_errorMonitor->VerifyNotFound();
19423
19424 // Force device idle and clean up remaining objects
19425 vkDeviceWaitIdle(m_device->device());
19426 vkDestroySemaphore(m_device->device(), s2, nullptr);
19427 vkDestroyFence(m_device->device(), fence, nullptr);
19428}
19429
19430TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19431 m_errorMonitor->ExpectSuccess();
19432
19433 ASSERT_NO_FATAL_FAILURE(InitState());
19434 VkResult err;
19435
19436 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019437 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019438 VkFence f1;
19439 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19440 ASSERT_VK_SUCCESS(err);
19441
19442 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019443 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019444 VkFence f2;
19445 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19446 ASSERT_VK_SUCCESS(err);
19447
19448 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019449 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019450 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19451
19452 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019453 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019454 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19455
19456 // Should have both retired!
19457 vkDestroyFence(m_device->device(), f1, nullptr);
19458 vkDestroyFence(m_device->device(), f2, nullptr);
19459
19460 m_errorMonitor->VerifyNotFound();
19461}
19462
19463TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019464 TEST_DESCRIPTION(
19465 "Verify that creating an image view from an image with valid usage "
19466 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019467
19468 ASSERT_NO_FATAL_FAILURE(InitState());
19469
19470 m_errorMonitor->ExpectSuccess();
19471 // Verify that we can create a view with usage INPUT_ATTACHMENT
19472 VkImageObj image(m_device);
19473 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19474 ASSERT_TRUE(image.initialized());
19475 VkImageView imageView;
19476 VkImageViewCreateInfo ivci = {};
19477 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19478 ivci.image = image.handle();
19479 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19480 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19481 ivci.subresourceRange.layerCount = 1;
19482 ivci.subresourceRange.baseMipLevel = 0;
19483 ivci.subresourceRange.levelCount = 1;
19484 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19485
19486 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19487 m_errorMonitor->VerifyNotFound();
19488 vkDestroyImageView(m_device->device(), imageView, NULL);
19489}
19490
19491// This is a positive test. No failures are expected.
19492TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019493 TEST_DESCRIPTION(
19494 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19495 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019496
19497 ASSERT_NO_FATAL_FAILURE(InitState());
19498
19499 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019500 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019501
19502 m_errorMonitor->ExpectSuccess();
19503
19504 VkImage image;
19505 VkImageCreateInfo image_create_info = {};
19506 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19507 image_create_info.pNext = NULL;
19508 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19509 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19510 image_create_info.extent.width = 64;
19511 image_create_info.extent.height = 64;
19512 image_create_info.extent.depth = 1;
19513 image_create_info.mipLevels = 1;
19514 image_create_info.arrayLayers = 1;
19515 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19516 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19517 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19518 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19519 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19520 ASSERT_VK_SUCCESS(err);
19521
19522 VkMemoryRequirements memory_reqs;
19523 VkDeviceMemory memory_one, memory_two;
19524 bool pass;
19525 VkMemoryAllocateInfo memory_info = {};
19526 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19527 memory_info.pNext = NULL;
19528 memory_info.allocationSize = 0;
19529 memory_info.memoryTypeIndex = 0;
19530 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19531 // Find an image big enough to allow sparse mapping of 2 memory regions
19532 // Increase the image size until it is at least twice the
19533 // size of the required alignment, to ensure we can bind both
19534 // allocated memory blocks to the image on aligned offsets.
19535 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19536 vkDestroyImage(m_device->device(), image, nullptr);
19537 image_create_info.extent.width *= 2;
19538 image_create_info.extent.height *= 2;
19539 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19540 ASSERT_VK_SUCCESS(err);
19541 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19542 }
19543 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19544 // at the end of the first
19545 memory_info.allocationSize = memory_reqs.alignment;
19546 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19547 ASSERT_TRUE(pass);
19548 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19549 ASSERT_VK_SUCCESS(err);
19550 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19551 ASSERT_VK_SUCCESS(err);
19552 VkSparseMemoryBind binds[2];
19553 binds[0].flags = 0;
19554 binds[0].memory = memory_one;
19555 binds[0].memoryOffset = 0;
19556 binds[0].resourceOffset = 0;
19557 binds[0].size = memory_info.allocationSize;
19558 binds[1].flags = 0;
19559 binds[1].memory = memory_two;
19560 binds[1].memoryOffset = 0;
19561 binds[1].resourceOffset = memory_info.allocationSize;
19562 binds[1].size = memory_info.allocationSize;
19563
19564 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19565 opaqueBindInfo.image = image;
19566 opaqueBindInfo.bindCount = 2;
19567 opaqueBindInfo.pBinds = binds;
19568
19569 VkFence fence = VK_NULL_HANDLE;
19570 VkBindSparseInfo bindSparseInfo = {};
19571 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19572 bindSparseInfo.imageOpaqueBindCount = 1;
19573 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19574
19575 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19576 vkQueueWaitIdle(m_device->m_queue);
19577 vkDestroyImage(m_device->device(), image, NULL);
19578 vkFreeMemory(m_device->device(), memory_one, NULL);
19579 vkFreeMemory(m_device->device(), memory_two, NULL);
19580 m_errorMonitor->VerifyNotFound();
19581}
19582
19583TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019584 TEST_DESCRIPTION(
19585 "Ensure that CmdBeginRenderPass with an attachment's "
19586 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19587 "the command buffer has prior knowledge of that "
19588 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019589
19590 m_errorMonitor->ExpectSuccess();
19591
19592 ASSERT_NO_FATAL_FAILURE(InitState());
19593
19594 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019595 VkAttachmentDescription attachment = {0,
19596 VK_FORMAT_R8G8B8A8_UNORM,
19597 VK_SAMPLE_COUNT_1_BIT,
19598 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19599 VK_ATTACHMENT_STORE_OP_STORE,
19600 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19601 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19602 VK_IMAGE_LAYOUT_UNDEFINED,
19603 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019604
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019605 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019606
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019607 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019608
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019609 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019610
19611 VkRenderPass rp;
19612 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19613 ASSERT_VK_SUCCESS(err);
19614
19615 // A compatible framebuffer.
19616 VkImageObj image(m_device);
19617 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19618 ASSERT_TRUE(image.initialized());
19619
19620 VkImageViewCreateInfo ivci = {
19621 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19622 nullptr,
19623 0,
19624 image.handle(),
19625 VK_IMAGE_VIEW_TYPE_2D,
19626 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019627 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19628 VK_COMPONENT_SWIZZLE_IDENTITY},
19629 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019630 };
19631 VkImageView view;
19632 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19633 ASSERT_VK_SUCCESS(err);
19634
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019635 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019636 VkFramebuffer fb;
19637 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19638 ASSERT_VK_SUCCESS(err);
19639
19640 // Record a single command buffer which uses this renderpass twice. The
19641 // bug is triggered at the beginning of the second renderpass, when the
19642 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019643 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 -070019644 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019645 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19646 vkCmdEndRenderPass(m_commandBuffer->handle());
19647 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19648
19649 m_errorMonitor->VerifyNotFound();
19650
19651 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019652 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019653
19654 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19655 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19656 vkDestroyImageView(m_device->device(), view, nullptr);
19657}
19658
19659TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019660 TEST_DESCRIPTION(
19661 "This test should pass. Create a Framebuffer and "
19662 "command buffer, bind them together, then destroy "
19663 "command pool and framebuffer and verify there are no "
19664 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019665
19666 m_errorMonitor->ExpectSuccess();
19667
19668 ASSERT_NO_FATAL_FAILURE(InitState());
19669
19670 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019671 VkAttachmentDescription attachment = {0,
19672 VK_FORMAT_R8G8B8A8_UNORM,
19673 VK_SAMPLE_COUNT_1_BIT,
19674 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19675 VK_ATTACHMENT_STORE_OP_STORE,
19676 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19677 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19678 VK_IMAGE_LAYOUT_UNDEFINED,
19679 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019680
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019681 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019682
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019683 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019684
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019685 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019686
19687 VkRenderPass rp;
19688 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19689 ASSERT_VK_SUCCESS(err);
19690
19691 // A compatible framebuffer.
19692 VkImageObj image(m_device);
19693 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19694 ASSERT_TRUE(image.initialized());
19695
19696 VkImageViewCreateInfo ivci = {
19697 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19698 nullptr,
19699 0,
19700 image.handle(),
19701 VK_IMAGE_VIEW_TYPE_2D,
19702 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019703 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19704 VK_COMPONENT_SWIZZLE_IDENTITY},
19705 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019706 };
19707 VkImageView view;
19708 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19709 ASSERT_VK_SUCCESS(err);
19710
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019711 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019712 VkFramebuffer fb;
19713 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19714 ASSERT_VK_SUCCESS(err);
19715
19716 // Explicitly create a command buffer to bind the FB to so that we can then
19717 // destroy the command pool in order to implicitly free command buffer
19718 VkCommandPool command_pool;
19719 VkCommandPoolCreateInfo pool_create_info{};
19720 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19721 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19722 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19723 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19724
19725 VkCommandBuffer command_buffer;
19726 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19727 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19728 command_buffer_allocate_info.commandPool = command_pool;
19729 command_buffer_allocate_info.commandBufferCount = 1;
19730 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19731 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19732
19733 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019734 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 -060019735 VkCommandBufferBeginInfo begin_info{};
19736 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19737 vkBeginCommandBuffer(command_buffer, &begin_info);
19738
19739 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19740 vkCmdEndRenderPass(command_buffer);
19741 vkEndCommandBuffer(command_buffer);
19742 vkDestroyImageView(m_device->device(), view, nullptr);
19743 // Destroy command pool to implicitly free command buffer
19744 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19745 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19746 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19747 m_errorMonitor->VerifyNotFound();
19748}
19749
19750TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019751 TEST_DESCRIPTION(
19752 "Ensure that CmdBeginRenderPass applies the layout "
19753 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019754
19755 m_errorMonitor->ExpectSuccess();
19756
19757 ASSERT_NO_FATAL_FAILURE(InitState());
19758
19759 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019760 VkAttachmentDescription attachment = {0,
19761 VK_FORMAT_R8G8B8A8_UNORM,
19762 VK_SAMPLE_COUNT_1_BIT,
19763 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19764 VK_ATTACHMENT_STORE_OP_STORE,
19765 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19766 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19767 VK_IMAGE_LAYOUT_UNDEFINED,
19768 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019769
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019770 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019771
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019772 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019773
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019774 VkSubpassDependency dep = {0,
19775 0,
19776 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19777 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19778 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19779 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19780 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019781
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019782 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019783
19784 VkResult err;
19785 VkRenderPass rp;
19786 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19787 ASSERT_VK_SUCCESS(err);
19788
19789 // A compatible framebuffer.
19790 VkImageObj image(m_device);
19791 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19792 ASSERT_TRUE(image.initialized());
19793
19794 VkImageViewCreateInfo ivci = {
19795 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19796 nullptr,
19797 0,
19798 image.handle(),
19799 VK_IMAGE_VIEW_TYPE_2D,
19800 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019801 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19802 VK_COMPONENT_SWIZZLE_IDENTITY},
19803 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019804 };
19805 VkImageView view;
19806 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19807 ASSERT_VK_SUCCESS(err);
19808
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019809 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019810 VkFramebuffer fb;
19811 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19812 ASSERT_VK_SUCCESS(err);
19813
19814 // Record a single command buffer which issues a pipeline barrier w/
19815 // image memory barrier for the attachment. This detects the previously
19816 // missing tracking of the subpass layout by throwing a validation error
19817 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019818 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 -070019819 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019820 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19821
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019822 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19823 nullptr,
19824 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19825 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19826 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19827 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19828 VK_QUEUE_FAMILY_IGNORED,
19829 VK_QUEUE_FAMILY_IGNORED,
19830 image.handle(),
19831 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019832 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019833 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19834 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019835
19836 vkCmdEndRenderPass(m_commandBuffer->handle());
19837 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019838 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019839
19840 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19841 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19842 vkDestroyImageView(m_device->device(), view, nullptr);
19843}
19844
19845TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019846 TEST_DESCRIPTION(
19847 "Validate that when an imageView of a depth/stencil image "
19848 "is used as a depth/stencil framebuffer attachment, the "
19849 "aspectMask is ignored and both depth and stencil image "
19850 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019851
19852 VkFormatProperties format_properties;
19853 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19854 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19855 return;
19856 }
19857
19858 m_errorMonitor->ExpectSuccess();
19859
19860 ASSERT_NO_FATAL_FAILURE(InitState());
19861
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019862 VkAttachmentDescription attachment = {0,
19863 VK_FORMAT_D32_SFLOAT_S8_UINT,
19864 VK_SAMPLE_COUNT_1_BIT,
19865 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19866 VK_ATTACHMENT_STORE_OP_STORE,
19867 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19868 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19869 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19870 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019871
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019872 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019873
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019874 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019875
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019876 VkSubpassDependency dep = {0,
19877 0,
19878 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19879 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19880 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19881 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19882 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019883
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019884 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019885
19886 VkResult err;
19887 VkRenderPass rp;
19888 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19889 ASSERT_VK_SUCCESS(err);
19890
19891 VkImageObj image(m_device);
19892 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019893 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019894 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019895 ASSERT_TRUE(image.initialized());
19896 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19897
19898 VkImageViewCreateInfo ivci = {
19899 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19900 nullptr,
19901 0,
19902 image.handle(),
19903 VK_IMAGE_VIEW_TYPE_2D,
19904 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019905 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19906 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019907 };
19908 VkImageView view;
19909 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19910 ASSERT_VK_SUCCESS(err);
19911
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019912 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019913 VkFramebuffer fb;
19914 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19915 ASSERT_VK_SUCCESS(err);
19916
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019917 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 -070019918 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019919 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19920
19921 VkImageMemoryBarrier imb = {};
19922 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19923 imb.pNext = nullptr;
19924 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19925 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19926 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19927 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19928 imb.srcQueueFamilyIndex = 0;
19929 imb.dstQueueFamilyIndex = 0;
19930 imb.image = image.handle();
19931 imb.subresourceRange.aspectMask = 0x6;
19932 imb.subresourceRange.baseMipLevel = 0;
19933 imb.subresourceRange.levelCount = 0x1;
19934 imb.subresourceRange.baseArrayLayer = 0;
19935 imb.subresourceRange.layerCount = 0x1;
19936
19937 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019938 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19939 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019940
19941 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019942 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019943 QueueCommandBuffer(false);
19944 m_errorMonitor->VerifyNotFound();
19945
19946 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19947 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19948 vkDestroyImageView(m_device->device(), view, nullptr);
19949}
19950
19951TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019952 TEST_DESCRIPTION(
19953 "Ensure that layout transitions work correctly without "
19954 "errors, when an attachment reference is "
19955 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019956
19957 m_errorMonitor->ExpectSuccess();
19958
19959 ASSERT_NO_FATAL_FAILURE(InitState());
19960
19961 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019962 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019963
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019964 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019965
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019966 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019967
19968 VkRenderPass rp;
19969 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19970 ASSERT_VK_SUCCESS(err);
19971
19972 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019973 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019974 VkFramebuffer fb;
19975 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19976 ASSERT_VK_SUCCESS(err);
19977
19978 // Record a command buffer which just begins and ends the renderpass. The
19979 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019980 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 -070019981 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019982 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19983 vkCmdEndRenderPass(m_commandBuffer->handle());
19984 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019985 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019986
19987 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19988 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19989}
19990
19991// This is a positive test. No errors are expected.
19992TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019993 TEST_DESCRIPTION(
19994 "Create a stencil-only attachment with a LOAD_OP set to "
19995 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019996 VkResult result = VK_SUCCESS;
Tony Barbourf887b162017-03-09 10:06:46 -070019997 ASSERT_NO_FATAL_FAILURE(InitState());
19998 auto depth_format = find_depth_stencil_format(m_device);
19999 if (!depth_format) {
20000 printf(" No Depth + Stencil format found. Skipped.\n");
20001 return;
20002 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020003 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070020004 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020005 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
20006 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020007 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
20008 return;
20009 }
20010
Tony Barbourf887b162017-03-09 10:06:46 -070020011 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020012 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020013 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020014 VkAttachmentDescription att = {};
20015 VkAttachmentReference ref = {};
20016 att.format = depth_stencil_fmt;
20017 att.samples = VK_SAMPLE_COUNT_1_BIT;
20018 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
20019 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20020 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20021 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
20022 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20023 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20024
20025 VkClearValue clear;
20026 clear.depthStencil.depth = 1.0;
20027 clear.depthStencil.stencil = 0;
20028 ref.attachment = 0;
20029 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20030
20031 VkSubpassDescription subpass = {};
20032 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
20033 subpass.flags = 0;
20034 subpass.inputAttachmentCount = 0;
20035 subpass.pInputAttachments = NULL;
20036 subpass.colorAttachmentCount = 0;
20037 subpass.pColorAttachments = NULL;
20038 subpass.pResolveAttachments = NULL;
20039 subpass.pDepthStencilAttachment = &ref;
20040 subpass.preserveAttachmentCount = 0;
20041 subpass.pPreserveAttachments = NULL;
20042
20043 VkRenderPass rp;
20044 VkRenderPassCreateInfo rp_info = {};
20045 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20046 rp_info.attachmentCount = 1;
20047 rp_info.pAttachments = &att;
20048 rp_info.subpassCount = 1;
20049 rp_info.pSubpasses = &subpass;
20050 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
20051 ASSERT_VK_SUCCESS(result);
20052
20053 VkImageView *depthView = m_depthStencil->BindInfo();
20054 VkFramebufferCreateInfo fb_info = {};
20055 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
20056 fb_info.pNext = NULL;
20057 fb_info.renderPass = rp;
20058 fb_info.attachmentCount = 1;
20059 fb_info.pAttachments = depthView;
20060 fb_info.width = 100;
20061 fb_info.height = 100;
20062 fb_info.layers = 1;
20063 VkFramebuffer fb;
20064 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
20065 ASSERT_VK_SUCCESS(result);
20066
20067 VkRenderPassBeginInfo rpbinfo = {};
20068 rpbinfo.clearValueCount = 1;
20069 rpbinfo.pClearValues = &clear;
20070 rpbinfo.pNext = NULL;
20071 rpbinfo.renderPass = rp;
20072 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
20073 rpbinfo.renderArea.extent.width = 100;
20074 rpbinfo.renderArea.extent.height = 100;
20075 rpbinfo.renderArea.offset.x = 0;
20076 rpbinfo.renderArea.offset.y = 0;
20077 rpbinfo.framebuffer = fb;
20078
20079 VkFence fence = {};
20080 VkFenceCreateInfo fence_ci = {};
20081 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20082 fence_ci.pNext = nullptr;
20083 fence_ci.flags = 0;
20084 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
20085 ASSERT_VK_SUCCESS(result);
20086
20087 m_commandBuffer->BeginCommandBuffer();
20088 m_commandBuffer->BeginRenderPass(rpbinfo);
20089 m_commandBuffer->EndRenderPass();
20090 m_commandBuffer->EndCommandBuffer();
20091 m_commandBuffer->QueueCommandBuffer(fence);
20092
20093 VkImageObj destImage(m_device);
20094 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 -070020095 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020096 VkImageMemoryBarrier barrier = {};
20097 VkImageSubresourceRange range;
20098 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20099 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20100 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
20101 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20102 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20103 barrier.image = m_depthStencil->handle();
20104 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20105 range.baseMipLevel = 0;
20106 range.levelCount = 1;
20107 range.baseArrayLayer = 0;
20108 range.layerCount = 1;
20109 barrier.subresourceRange = range;
20110 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20111 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
20112 cmdbuf.BeginCommandBuffer();
20113 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 -070020114 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020115 barrier.srcAccessMask = 0;
20116 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
20117 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20118 barrier.image = destImage.handle();
20119 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20120 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 -070020121 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020122 VkImageCopy cregion;
20123 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20124 cregion.srcSubresource.mipLevel = 0;
20125 cregion.srcSubresource.baseArrayLayer = 0;
20126 cregion.srcSubresource.layerCount = 1;
20127 cregion.srcOffset.x = 0;
20128 cregion.srcOffset.y = 0;
20129 cregion.srcOffset.z = 0;
20130 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20131 cregion.dstSubresource.mipLevel = 0;
20132 cregion.dstSubresource.baseArrayLayer = 0;
20133 cregion.dstSubresource.layerCount = 1;
20134 cregion.dstOffset.x = 0;
20135 cregion.dstOffset.y = 0;
20136 cregion.dstOffset.z = 0;
20137 cregion.extent.width = 100;
20138 cregion.extent.height = 100;
20139 cregion.extent.depth = 1;
20140 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020141 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020142 cmdbuf.EndCommandBuffer();
20143
20144 VkSubmitInfo submit_info;
20145 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20146 submit_info.pNext = NULL;
20147 submit_info.waitSemaphoreCount = 0;
20148 submit_info.pWaitSemaphores = NULL;
20149 submit_info.pWaitDstStageMask = NULL;
20150 submit_info.commandBufferCount = 1;
20151 submit_info.pCommandBuffers = &cmdbuf.handle();
20152 submit_info.signalSemaphoreCount = 0;
20153 submit_info.pSignalSemaphores = NULL;
20154
20155 m_errorMonitor->ExpectSuccess();
20156 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20157 m_errorMonitor->VerifyNotFound();
20158
20159 vkQueueWaitIdle(m_device->m_queue);
20160 vkDestroyFence(m_device->device(), fence, nullptr);
20161 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20162 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20163}
20164
20165// This is a positive test. No errors should be generated.
20166TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
20167 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
20168
20169 m_errorMonitor->ExpectSuccess();
20170 ASSERT_NO_FATAL_FAILURE(InitState());
20171
20172 VkEvent event;
20173 VkEventCreateInfo event_create_info{};
20174 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20175 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20176
20177 VkCommandPool command_pool;
20178 VkCommandPoolCreateInfo pool_create_info{};
20179 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20180 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20181 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20182 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20183
20184 VkCommandBuffer command_buffer;
20185 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20186 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20187 command_buffer_allocate_info.commandPool = command_pool;
20188 command_buffer_allocate_info.commandBufferCount = 1;
20189 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20190 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20191
20192 VkQueue queue = VK_NULL_HANDLE;
20193 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20194
20195 {
20196 VkCommandBufferBeginInfo begin_info{};
20197 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20198 vkBeginCommandBuffer(command_buffer, &begin_info);
20199
20200 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 -070020201 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020202 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
20203 vkEndCommandBuffer(command_buffer);
20204 }
20205 {
20206 VkSubmitInfo submit_info{};
20207 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20208 submit_info.commandBufferCount = 1;
20209 submit_info.pCommandBuffers = &command_buffer;
20210 submit_info.signalSemaphoreCount = 0;
20211 submit_info.pSignalSemaphores = nullptr;
20212 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20213 }
20214 { vkSetEvent(m_device->device(), event); }
20215
20216 vkQueueWaitIdle(queue);
20217
20218 vkDestroyEvent(m_device->device(), event, nullptr);
20219 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20220 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20221
20222 m_errorMonitor->VerifyNotFound();
20223}
20224// This is a positive test. No errors should be generated.
20225TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
20226 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
20227
20228 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020229 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020230
20231 m_errorMonitor->ExpectSuccess();
20232
20233 VkQueryPool query_pool;
20234 VkQueryPoolCreateInfo query_pool_create_info{};
20235 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20236 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20237 query_pool_create_info.queryCount = 1;
20238 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20239
20240 VkCommandPool command_pool;
20241 VkCommandPoolCreateInfo pool_create_info{};
20242 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20243 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20244 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20245 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20246
20247 VkCommandBuffer command_buffer;
20248 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20249 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20250 command_buffer_allocate_info.commandPool = command_pool;
20251 command_buffer_allocate_info.commandBufferCount = 1;
20252 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20253 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20254
20255 VkCommandBuffer secondary_command_buffer;
20256 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20257 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20258
20259 VkQueue queue = VK_NULL_HANDLE;
20260 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20261
20262 uint32_t qfi = 0;
20263 VkBufferCreateInfo buff_create_info = {};
20264 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20265 buff_create_info.size = 1024;
20266 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20267 buff_create_info.queueFamilyIndexCount = 1;
20268 buff_create_info.pQueueFamilyIndices = &qfi;
20269
20270 VkResult err;
20271 VkBuffer buffer;
20272 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20273 ASSERT_VK_SUCCESS(err);
20274 VkMemoryAllocateInfo mem_alloc = {};
20275 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20276 mem_alloc.pNext = NULL;
20277 mem_alloc.allocationSize = 1024;
20278 mem_alloc.memoryTypeIndex = 0;
20279
20280 VkMemoryRequirements memReqs;
20281 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20282 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20283 if (!pass) {
20284 vkDestroyBuffer(m_device->device(), buffer, NULL);
20285 return;
20286 }
20287
20288 VkDeviceMemory mem;
20289 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20290 ASSERT_VK_SUCCESS(err);
20291 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20292 ASSERT_VK_SUCCESS(err);
20293
20294 VkCommandBufferInheritanceInfo hinfo = {};
20295 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20296 hinfo.renderPass = VK_NULL_HANDLE;
20297 hinfo.subpass = 0;
20298 hinfo.framebuffer = VK_NULL_HANDLE;
20299 hinfo.occlusionQueryEnable = VK_FALSE;
20300 hinfo.queryFlags = 0;
20301 hinfo.pipelineStatistics = 0;
20302
20303 {
20304 VkCommandBufferBeginInfo begin_info{};
20305 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20306 begin_info.pInheritanceInfo = &hinfo;
20307 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20308
20309 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20310 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20311
20312 vkEndCommandBuffer(secondary_command_buffer);
20313
20314 begin_info.pInheritanceInfo = nullptr;
20315 vkBeginCommandBuffer(command_buffer, &begin_info);
20316
20317 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20318 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20319
20320 vkEndCommandBuffer(command_buffer);
20321 }
20322 {
20323 VkSubmitInfo submit_info{};
20324 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20325 submit_info.commandBufferCount = 1;
20326 submit_info.pCommandBuffers = &command_buffer;
20327 submit_info.signalSemaphoreCount = 0;
20328 submit_info.pSignalSemaphores = nullptr;
20329 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20330 }
20331
20332 vkQueueWaitIdle(queue);
20333
20334 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20335 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20336 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20337 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20338 vkDestroyBuffer(m_device->device(), buffer, NULL);
20339 vkFreeMemory(m_device->device(), mem, NULL);
20340
20341 m_errorMonitor->VerifyNotFound();
20342}
20343
20344// This is a positive test. No errors should be generated.
20345TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20346 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20347
20348 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020349 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020350
20351 m_errorMonitor->ExpectSuccess();
20352
20353 VkQueryPool query_pool;
20354 VkQueryPoolCreateInfo query_pool_create_info{};
20355 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20356 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20357 query_pool_create_info.queryCount = 1;
20358 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20359
20360 VkCommandPool command_pool;
20361 VkCommandPoolCreateInfo pool_create_info{};
20362 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20363 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20364 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20365 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20366
20367 VkCommandBuffer command_buffer[2];
20368 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20369 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20370 command_buffer_allocate_info.commandPool = command_pool;
20371 command_buffer_allocate_info.commandBufferCount = 2;
20372 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20373 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20374
20375 VkQueue queue = VK_NULL_HANDLE;
20376 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20377
20378 uint32_t qfi = 0;
20379 VkBufferCreateInfo buff_create_info = {};
20380 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20381 buff_create_info.size = 1024;
20382 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20383 buff_create_info.queueFamilyIndexCount = 1;
20384 buff_create_info.pQueueFamilyIndices = &qfi;
20385
20386 VkResult err;
20387 VkBuffer buffer;
20388 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20389 ASSERT_VK_SUCCESS(err);
20390 VkMemoryAllocateInfo mem_alloc = {};
20391 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20392 mem_alloc.pNext = NULL;
20393 mem_alloc.allocationSize = 1024;
20394 mem_alloc.memoryTypeIndex = 0;
20395
20396 VkMemoryRequirements memReqs;
20397 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20398 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20399 if (!pass) {
20400 vkDestroyBuffer(m_device->device(), buffer, NULL);
20401 return;
20402 }
20403
20404 VkDeviceMemory mem;
20405 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20406 ASSERT_VK_SUCCESS(err);
20407 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20408 ASSERT_VK_SUCCESS(err);
20409
20410 {
20411 VkCommandBufferBeginInfo begin_info{};
20412 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20413 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20414
20415 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20416 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20417
20418 vkEndCommandBuffer(command_buffer[0]);
20419
20420 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20421
20422 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20423
20424 vkEndCommandBuffer(command_buffer[1]);
20425 }
20426 {
20427 VkSubmitInfo submit_info{};
20428 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20429 submit_info.commandBufferCount = 2;
20430 submit_info.pCommandBuffers = command_buffer;
20431 submit_info.signalSemaphoreCount = 0;
20432 submit_info.pSignalSemaphores = nullptr;
20433 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20434 }
20435
20436 vkQueueWaitIdle(queue);
20437
20438 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20439 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20440 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20441 vkDestroyBuffer(m_device->device(), buffer, NULL);
20442 vkFreeMemory(m_device->device(), mem, NULL);
20443
20444 m_errorMonitor->VerifyNotFound();
20445}
20446
Tony Barbourc46924f2016-11-04 11:49:52 -060020447TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020448 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20449
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020450 ASSERT_NO_FATAL_FAILURE(InitState());
20451 VkEvent event;
20452 VkEventCreateInfo event_create_info{};
20453 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20454 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20455
20456 VkCommandPool command_pool;
20457 VkCommandPoolCreateInfo pool_create_info{};
20458 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20459 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20460 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20461 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20462
20463 VkCommandBuffer command_buffer;
20464 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20465 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20466 command_buffer_allocate_info.commandPool = command_pool;
20467 command_buffer_allocate_info.commandBufferCount = 1;
20468 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20469 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20470
20471 VkQueue queue = VK_NULL_HANDLE;
20472 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20473
20474 {
20475 VkCommandBufferBeginInfo begin_info{};
20476 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20477 vkBeginCommandBuffer(command_buffer, &begin_info);
20478
20479 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020480 vkEndCommandBuffer(command_buffer);
20481 }
20482 {
20483 VkSubmitInfo submit_info{};
20484 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20485 submit_info.commandBufferCount = 1;
20486 submit_info.pCommandBuffers = &command_buffer;
20487 submit_info.signalSemaphoreCount = 0;
20488 submit_info.pSignalSemaphores = nullptr;
20489 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20490 }
20491 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20493 "that is already in use by a "
20494 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020495 vkSetEvent(m_device->device(), event);
20496 m_errorMonitor->VerifyFound();
20497 }
20498
20499 vkQueueWaitIdle(queue);
20500
20501 vkDestroyEvent(m_device->device(), event, nullptr);
20502 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20503 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20504}
20505
20506// This is a positive test. No errors should be generated.
20507TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020508 TEST_DESCRIPTION(
20509 "Two command buffers with two separate fences are each "
20510 "run through a Submit & WaitForFences cycle 3 times. This "
20511 "previously revealed a bug so running this positive test "
20512 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020513 m_errorMonitor->ExpectSuccess();
20514
20515 ASSERT_NO_FATAL_FAILURE(InitState());
20516 VkQueue queue = VK_NULL_HANDLE;
20517 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20518
20519 static const uint32_t NUM_OBJECTS = 2;
20520 static const uint32_t NUM_FRAMES = 3;
20521 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20522 VkFence fences[NUM_OBJECTS] = {};
20523
20524 VkCommandPool cmd_pool;
20525 VkCommandPoolCreateInfo cmd_pool_ci = {};
20526 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20527 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20528 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20529 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20530 ASSERT_VK_SUCCESS(err);
20531
20532 VkCommandBufferAllocateInfo cmd_buf_info = {};
20533 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20534 cmd_buf_info.commandPool = cmd_pool;
20535 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20536 cmd_buf_info.commandBufferCount = 1;
20537
20538 VkFenceCreateInfo fence_ci = {};
20539 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20540 fence_ci.pNext = nullptr;
20541 fence_ci.flags = 0;
20542
20543 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20544 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20545 ASSERT_VK_SUCCESS(err);
20546 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20547 ASSERT_VK_SUCCESS(err);
20548 }
20549
20550 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20551 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20552 // Create empty cmd buffer
20553 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20554 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20555
20556 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20557 ASSERT_VK_SUCCESS(err);
20558 err = vkEndCommandBuffer(cmd_buffers[obj]);
20559 ASSERT_VK_SUCCESS(err);
20560
20561 VkSubmitInfo submit_info = {};
20562 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20563 submit_info.commandBufferCount = 1;
20564 submit_info.pCommandBuffers = &cmd_buffers[obj];
20565 // Submit cmd buffer and wait for fence
20566 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20567 ASSERT_VK_SUCCESS(err);
20568 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20569 ASSERT_VK_SUCCESS(err);
20570 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20571 ASSERT_VK_SUCCESS(err);
20572 }
20573 }
20574 m_errorMonitor->VerifyNotFound();
20575 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20576 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20577 vkDestroyFence(m_device->device(), fences[i], nullptr);
20578 }
20579}
20580// This is a positive test. No errors should be generated.
20581TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020582 TEST_DESCRIPTION(
20583 "Two command buffers, each in a separate QueueSubmit call "
20584 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020585
20586 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020587 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020588
20589 m_errorMonitor->ExpectSuccess();
20590
20591 VkSemaphore semaphore;
20592 VkSemaphoreCreateInfo semaphore_create_info{};
20593 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20594 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20595
20596 VkCommandPool command_pool;
20597 VkCommandPoolCreateInfo pool_create_info{};
20598 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20599 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20600 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20601 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20602
20603 VkCommandBuffer command_buffer[2];
20604 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20605 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20606 command_buffer_allocate_info.commandPool = command_pool;
20607 command_buffer_allocate_info.commandBufferCount = 2;
20608 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20609 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20610
20611 VkQueue queue = VK_NULL_HANDLE;
20612 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20613
20614 {
20615 VkCommandBufferBeginInfo begin_info{};
20616 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20617 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20618
20619 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 -070020620 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020621
20622 VkViewport viewport{};
20623 viewport.maxDepth = 1.0f;
20624 viewport.minDepth = 0.0f;
20625 viewport.width = 512;
20626 viewport.height = 512;
20627 viewport.x = 0;
20628 viewport.y = 0;
20629 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20630 vkEndCommandBuffer(command_buffer[0]);
20631 }
20632 {
20633 VkCommandBufferBeginInfo begin_info{};
20634 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20635 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20636
20637 VkViewport viewport{};
20638 viewport.maxDepth = 1.0f;
20639 viewport.minDepth = 0.0f;
20640 viewport.width = 512;
20641 viewport.height = 512;
20642 viewport.x = 0;
20643 viewport.y = 0;
20644 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20645 vkEndCommandBuffer(command_buffer[1]);
20646 }
20647 {
20648 VkSubmitInfo submit_info{};
20649 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20650 submit_info.commandBufferCount = 1;
20651 submit_info.pCommandBuffers = &command_buffer[0];
20652 submit_info.signalSemaphoreCount = 1;
20653 submit_info.pSignalSemaphores = &semaphore;
20654 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20655 }
20656 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020657 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020658 VkSubmitInfo submit_info{};
20659 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20660 submit_info.commandBufferCount = 1;
20661 submit_info.pCommandBuffers = &command_buffer[1];
20662 submit_info.waitSemaphoreCount = 1;
20663 submit_info.pWaitSemaphores = &semaphore;
20664 submit_info.pWaitDstStageMask = flags;
20665 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20666 }
20667
20668 vkQueueWaitIdle(m_device->m_queue);
20669
20670 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20671 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20672 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20673
20674 m_errorMonitor->VerifyNotFound();
20675}
20676
20677// This is a positive test. No errors should be generated.
20678TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020679 TEST_DESCRIPTION(
20680 "Two command buffers, each in a separate QueueSubmit call "
20681 "submitted on separate queues, the second having a fence"
20682 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020683
20684 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020685 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020686
20687 m_errorMonitor->ExpectSuccess();
20688
20689 VkFence fence;
20690 VkFenceCreateInfo fence_create_info{};
20691 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20692 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20693
20694 VkSemaphore semaphore;
20695 VkSemaphoreCreateInfo semaphore_create_info{};
20696 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20697 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20698
20699 VkCommandPool command_pool;
20700 VkCommandPoolCreateInfo pool_create_info{};
20701 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20702 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20703 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20704 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20705
20706 VkCommandBuffer command_buffer[2];
20707 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20708 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20709 command_buffer_allocate_info.commandPool = command_pool;
20710 command_buffer_allocate_info.commandBufferCount = 2;
20711 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20712 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20713
20714 VkQueue queue = VK_NULL_HANDLE;
20715 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20716
20717 {
20718 VkCommandBufferBeginInfo begin_info{};
20719 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20720 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20721
20722 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 -070020723 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020724
20725 VkViewport viewport{};
20726 viewport.maxDepth = 1.0f;
20727 viewport.minDepth = 0.0f;
20728 viewport.width = 512;
20729 viewport.height = 512;
20730 viewport.x = 0;
20731 viewport.y = 0;
20732 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20733 vkEndCommandBuffer(command_buffer[0]);
20734 }
20735 {
20736 VkCommandBufferBeginInfo begin_info{};
20737 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20738 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20739
20740 VkViewport viewport{};
20741 viewport.maxDepth = 1.0f;
20742 viewport.minDepth = 0.0f;
20743 viewport.width = 512;
20744 viewport.height = 512;
20745 viewport.x = 0;
20746 viewport.y = 0;
20747 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20748 vkEndCommandBuffer(command_buffer[1]);
20749 }
20750 {
20751 VkSubmitInfo submit_info{};
20752 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20753 submit_info.commandBufferCount = 1;
20754 submit_info.pCommandBuffers = &command_buffer[0];
20755 submit_info.signalSemaphoreCount = 1;
20756 submit_info.pSignalSemaphores = &semaphore;
20757 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20758 }
20759 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020760 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020761 VkSubmitInfo submit_info{};
20762 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20763 submit_info.commandBufferCount = 1;
20764 submit_info.pCommandBuffers = &command_buffer[1];
20765 submit_info.waitSemaphoreCount = 1;
20766 submit_info.pWaitSemaphores = &semaphore;
20767 submit_info.pWaitDstStageMask = flags;
20768 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20769 }
20770
20771 vkQueueWaitIdle(m_device->m_queue);
20772
20773 vkDestroyFence(m_device->device(), fence, nullptr);
20774 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20775 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20776 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20777
20778 m_errorMonitor->VerifyNotFound();
20779}
20780
20781// This is a positive test. No errors should be generated.
20782TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020783 TEST_DESCRIPTION(
20784 "Two command buffers, each in a separate QueueSubmit call "
20785 "submitted on separate queues, the second having a fence"
20786 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020787
20788 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020789 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020790
20791 m_errorMonitor->ExpectSuccess();
20792
20793 VkFence fence;
20794 VkFenceCreateInfo fence_create_info{};
20795 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20796 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20797
20798 VkSemaphore semaphore;
20799 VkSemaphoreCreateInfo semaphore_create_info{};
20800 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20801 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20802
20803 VkCommandPool command_pool;
20804 VkCommandPoolCreateInfo pool_create_info{};
20805 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20806 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20807 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20808 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20809
20810 VkCommandBuffer command_buffer[2];
20811 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20812 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20813 command_buffer_allocate_info.commandPool = command_pool;
20814 command_buffer_allocate_info.commandBufferCount = 2;
20815 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20816 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20817
20818 VkQueue queue = VK_NULL_HANDLE;
20819 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20820
20821 {
20822 VkCommandBufferBeginInfo begin_info{};
20823 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20824 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20825
20826 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 -070020827 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020828
20829 VkViewport viewport{};
20830 viewport.maxDepth = 1.0f;
20831 viewport.minDepth = 0.0f;
20832 viewport.width = 512;
20833 viewport.height = 512;
20834 viewport.x = 0;
20835 viewport.y = 0;
20836 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20837 vkEndCommandBuffer(command_buffer[0]);
20838 }
20839 {
20840 VkCommandBufferBeginInfo begin_info{};
20841 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20842 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20843
20844 VkViewport viewport{};
20845 viewport.maxDepth = 1.0f;
20846 viewport.minDepth = 0.0f;
20847 viewport.width = 512;
20848 viewport.height = 512;
20849 viewport.x = 0;
20850 viewport.y = 0;
20851 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20852 vkEndCommandBuffer(command_buffer[1]);
20853 }
20854 {
20855 VkSubmitInfo submit_info{};
20856 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20857 submit_info.commandBufferCount = 1;
20858 submit_info.pCommandBuffers = &command_buffer[0];
20859 submit_info.signalSemaphoreCount = 1;
20860 submit_info.pSignalSemaphores = &semaphore;
20861 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20862 }
20863 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020864 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020865 VkSubmitInfo submit_info{};
20866 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20867 submit_info.commandBufferCount = 1;
20868 submit_info.pCommandBuffers = &command_buffer[1];
20869 submit_info.waitSemaphoreCount = 1;
20870 submit_info.pWaitSemaphores = &semaphore;
20871 submit_info.pWaitDstStageMask = flags;
20872 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20873 }
20874
20875 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20876 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20877
20878 vkDestroyFence(m_device->device(), fence, nullptr);
20879 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20880 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20881 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20882
20883 m_errorMonitor->VerifyNotFound();
20884}
20885
20886TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020887 ASSERT_NO_FATAL_FAILURE(InitState());
20888 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020889 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020890 return;
20891 }
20892
20893 VkResult err;
20894
20895 m_errorMonitor->ExpectSuccess();
20896
20897 VkQueue q0 = m_device->m_queue;
20898 VkQueue q1 = nullptr;
20899 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20900 ASSERT_NE(q1, nullptr);
20901
20902 // An (empty) command buffer. We must have work in the first submission --
20903 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020904 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020905 VkCommandPool pool;
20906 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20907 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020908 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20909 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020910 VkCommandBuffer cb;
20911 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20912 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020913 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020914 err = vkBeginCommandBuffer(cb, &cbbi);
20915 ASSERT_VK_SUCCESS(err);
20916 err = vkEndCommandBuffer(cb);
20917 ASSERT_VK_SUCCESS(err);
20918
20919 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020920 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020921 VkSemaphore s;
20922 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20923 ASSERT_VK_SUCCESS(err);
20924
20925 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020926 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020927
20928 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20929 ASSERT_VK_SUCCESS(err);
20930
20931 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020932 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020933 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020934
20935 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20936 ASSERT_VK_SUCCESS(err);
20937
20938 // Wait for q0 idle
20939 err = vkQueueWaitIdle(q0);
20940 ASSERT_VK_SUCCESS(err);
20941
20942 // Command buffer should have been completed (it was on q0); reset the pool.
20943 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20944
20945 m_errorMonitor->VerifyNotFound();
20946
20947 // Force device completely idle and clean up resources
20948 vkDeviceWaitIdle(m_device->device());
20949 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20950 vkDestroySemaphore(m_device->device(), s, nullptr);
20951}
20952
20953// This is a positive test. No errors should be generated.
20954TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020955 TEST_DESCRIPTION(
20956 "Two command buffers, each in a separate QueueSubmit call "
20957 "submitted on separate queues, the second having a fence, "
20958 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020959
20960 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020961 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020962
20963 m_errorMonitor->ExpectSuccess();
20964
20965 ASSERT_NO_FATAL_FAILURE(InitState());
20966 VkFence fence;
20967 VkFenceCreateInfo fence_create_info{};
20968 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20969 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20970
20971 VkSemaphore semaphore;
20972 VkSemaphoreCreateInfo semaphore_create_info{};
20973 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20974 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20975
20976 VkCommandPool command_pool;
20977 VkCommandPoolCreateInfo pool_create_info{};
20978 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20979 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20980 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20981 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20982
20983 VkCommandBuffer command_buffer[2];
20984 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20985 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20986 command_buffer_allocate_info.commandPool = command_pool;
20987 command_buffer_allocate_info.commandBufferCount = 2;
20988 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20989 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20990
20991 VkQueue queue = VK_NULL_HANDLE;
20992 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20993
20994 {
20995 VkCommandBufferBeginInfo begin_info{};
20996 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20997 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20998
20999 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 -070021000 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021001
21002 VkViewport viewport{};
21003 viewport.maxDepth = 1.0f;
21004 viewport.minDepth = 0.0f;
21005 viewport.width = 512;
21006 viewport.height = 512;
21007 viewport.x = 0;
21008 viewport.y = 0;
21009 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21010 vkEndCommandBuffer(command_buffer[0]);
21011 }
21012 {
21013 VkCommandBufferBeginInfo begin_info{};
21014 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21015 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21016
21017 VkViewport viewport{};
21018 viewport.maxDepth = 1.0f;
21019 viewport.minDepth = 0.0f;
21020 viewport.width = 512;
21021 viewport.height = 512;
21022 viewport.x = 0;
21023 viewport.y = 0;
21024 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21025 vkEndCommandBuffer(command_buffer[1]);
21026 }
21027 {
21028 VkSubmitInfo submit_info{};
21029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21030 submit_info.commandBufferCount = 1;
21031 submit_info.pCommandBuffers = &command_buffer[0];
21032 submit_info.signalSemaphoreCount = 1;
21033 submit_info.pSignalSemaphores = &semaphore;
21034 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21035 }
21036 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021037 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021038 VkSubmitInfo submit_info{};
21039 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21040 submit_info.commandBufferCount = 1;
21041 submit_info.pCommandBuffers = &command_buffer[1];
21042 submit_info.waitSemaphoreCount = 1;
21043 submit_info.pWaitSemaphores = &semaphore;
21044 submit_info.pWaitDstStageMask = flags;
21045 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21046 }
21047
21048 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21049
21050 vkDestroyFence(m_device->device(), fence, nullptr);
21051 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21052 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21053 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21054
21055 m_errorMonitor->VerifyNotFound();
21056}
21057
21058// This is a positive test. No errors should be generated.
21059TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021060 TEST_DESCRIPTION(
21061 "Two command buffers, each in a separate QueueSubmit call "
21062 "on the same queue, sharing a signal/wait semaphore, the "
21063 "second having a fence, "
21064 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021065
21066 m_errorMonitor->ExpectSuccess();
21067
21068 ASSERT_NO_FATAL_FAILURE(InitState());
21069 VkFence fence;
21070 VkFenceCreateInfo fence_create_info{};
21071 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21072 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21073
21074 VkSemaphore semaphore;
21075 VkSemaphoreCreateInfo semaphore_create_info{};
21076 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21077 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21078
21079 VkCommandPool command_pool;
21080 VkCommandPoolCreateInfo pool_create_info{};
21081 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21082 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21083 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21084 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21085
21086 VkCommandBuffer command_buffer[2];
21087 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21088 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21089 command_buffer_allocate_info.commandPool = command_pool;
21090 command_buffer_allocate_info.commandBufferCount = 2;
21091 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21092 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21093
21094 {
21095 VkCommandBufferBeginInfo begin_info{};
21096 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21097 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21098
21099 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 -070021100 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021101
21102 VkViewport viewport{};
21103 viewport.maxDepth = 1.0f;
21104 viewport.minDepth = 0.0f;
21105 viewport.width = 512;
21106 viewport.height = 512;
21107 viewport.x = 0;
21108 viewport.y = 0;
21109 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21110 vkEndCommandBuffer(command_buffer[0]);
21111 }
21112 {
21113 VkCommandBufferBeginInfo begin_info{};
21114 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21115 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21116
21117 VkViewport viewport{};
21118 viewport.maxDepth = 1.0f;
21119 viewport.minDepth = 0.0f;
21120 viewport.width = 512;
21121 viewport.height = 512;
21122 viewport.x = 0;
21123 viewport.y = 0;
21124 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21125 vkEndCommandBuffer(command_buffer[1]);
21126 }
21127 {
21128 VkSubmitInfo submit_info{};
21129 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21130 submit_info.commandBufferCount = 1;
21131 submit_info.pCommandBuffers = &command_buffer[0];
21132 submit_info.signalSemaphoreCount = 1;
21133 submit_info.pSignalSemaphores = &semaphore;
21134 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21135 }
21136 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021137 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021138 VkSubmitInfo submit_info{};
21139 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21140 submit_info.commandBufferCount = 1;
21141 submit_info.pCommandBuffers = &command_buffer[1];
21142 submit_info.waitSemaphoreCount = 1;
21143 submit_info.pWaitSemaphores = &semaphore;
21144 submit_info.pWaitDstStageMask = flags;
21145 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21146 }
21147
21148 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21149
21150 vkDestroyFence(m_device->device(), fence, nullptr);
21151 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21152 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21153 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21154
21155 m_errorMonitor->VerifyNotFound();
21156}
21157
21158// This is a positive test. No errors should be generated.
21159TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021160 TEST_DESCRIPTION(
21161 "Two command buffers, each in a separate QueueSubmit call "
21162 "on the same queue, no fences, followed by a third QueueSubmit with NO "
21163 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021164
21165 m_errorMonitor->ExpectSuccess();
21166
21167 ASSERT_NO_FATAL_FAILURE(InitState());
21168 VkFence fence;
21169 VkFenceCreateInfo fence_create_info{};
21170 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21171 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21172
21173 VkCommandPool command_pool;
21174 VkCommandPoolCreateInfo pool_create_info{};
21175 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21176 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21177 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21178 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21179
21180 VkCommandBuffer command_buffer[2];
21181 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21182 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21183 command_buffer_allocate_info.commandPool = command_pool;
21184 command_buffer_allocate_info.commandBufferCount = 2;
21185 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21186 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21187
21188 {
21189 VkCommandBufferBeginInfo begin_info{};
21190 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21191 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21192
21193 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 -070021194 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021195
21196 VkViewport viewport{};
21197 viewport.maxDepth = 1.0f;
21198 viewport.minDepth = 0.0f;
21199 viewport.width = 512;
21200 viewport.height = 512;
21201 viewport.x = 0;
21202 viewport.y = 0;
21203 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21204 vkEndCommandBuffer(command_buffer[0]);
21205 }
21206 {
21207 VkCommandBufferBeginInfo begin_info{};
21208 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21209 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21210
21211 VkViewport viewport{};
21212 viewport.maxDepth = 1.0f;
21213 viewport.minDepth = 0.0f;
21214 viewport.width = 512;
21215 viewport.height = 512;
21216 viewport.x = 0;
21217 viewport.y = 0;
21218 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21219 vkEndCommandBuffer(command_buffer[1]);
21220 }
21221 {
21222 VkSubmitInfo submit_info{};
21223 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21224 submit_info.commandBufferCount = 1;
21225 submit_info.pCommandBuffers = &command_buffer[0];
21226 submit_info.signalSemaphoreCount = 0;
21227 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21228 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21229 }
21230 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021231 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021232 VkSubmitInfo submit_info{};
21233 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21234 submit_info.commandBufferCount = 1;
21235 submit_info.pCommandBuffers = &command_buffer[1];
21236 submit_info.waitSemaphoreCount = 0;
21237 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21238 submit_info.pWaitDstStageMask = flags;
21239 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21240 }
21241
21242 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
21243
21244 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21245 ASSERT_VK_SUCCESS(err);
21246
21247 vkDestroyFence(m_device->device(), fence, nullptr);
21248 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21249 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21250
21251 m_errorMonitor->VerifyNotFound();
21252}
21253
21254// This is a positive test. No errors should be generated.
21255TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021256 TEST_DESCRIPTION(
21257 "Two command buffers, each in a separate QueueSubmit call "
21258 "on the same queue, the second having a fence, followed "
21259 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021260
21261 m_errorMonitor->ExpectSuccess();
21262
21263 ASSERT_NO_FATAL_FAILURE(InitState());
21264 VkFence fence;
21265 VkFenceCreateInfo fence_create_info{};
21266 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21267 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21268
21269 VkCommandPool command_pool;
21270 VkCommandPoolCreateInfo pool_create_info{};
21271 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21272 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21273 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21274 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21275
21276 VkCommandBuffer command_buffer[2];
21277 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21278 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21279 command_buffer_allocate_info.commandPool = command_pool;
21280 command_buffer_allocate_info.commandBufferCount = 2;
21281 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21282 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21283
21284 {
21285 VkCommandBufferBeginInfo begin_info{};
21286 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21287 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21288
21289 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 -070021290 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021291
21292 VkViewport viewport{};
21293 viewport.maxDepth = 1.0f;
21294 viewport.minDepth = 0.0f;
21295 viewport.width = 512;
21296 viewport.height = 512;
21297 viewport.x = 0;
21298 viewport.y = 0;
21299 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21300 vkEndCommandBuffer(command_buffer[0]);
21301 }
21302 {
21303 VkCommandBufferBeginInfo begin_info{};
21304 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21305 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21306
21307 VkViewport viewport{};
21308 viewport.maxDepth = 1.0f;
21309 viewport.minDepth = 0.0f;
21310 viewport.width = 512;
21311 viewport.height = 512;
21312 viewport.x = 0;
21313 viewport.y = 0;
21314 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21315 vkEndCommandBuffer(command_buffer[1]);
21316 }
21317 {
21318 VkSubmitInfo submit_info{};
21319 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21320 submit_info.commandBufferCount = 1;
21321 submit_info.pCommandBuffers = &command_buffer[0];
21322 submit_info.signalSemaphoreCount = 0;
21323 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21324 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21325 }
21326 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021327 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021328 VkSubmitInfo submit_info{};
21329 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21330 submit_info.commandBufferCount = 1;
21331 submit_info.pCommandBuffers = &command_buffer[1];
21332 submit_info.waitSemaphoreCount = 0;
21333 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21334 submit_info.pWaitDstStageMask = flags;
21335 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21336 }
21337
21338 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21339
21340 vkDestroyFence(m_device->device(), fence, nullptr);
21341 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21342 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21343
21344 m_errorMonitor->VerifyNotFound();
21345}
21346
21347// This is a positive test. No errors should be generated.
21348TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021349 TEST_DESCRIPTION(
21350 "Two command buffers each in a separate SubmitInfo sent in a single "
21351 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021352 ASSERT_NO_FATAL_FAILURE(InitState());
21353
21354 m_errorMonitor->ExpectSuccess();
21355
21356 VkFence fence;
21357 VkFenceCreateInfo fence_create_info{};
21358 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21359 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21360
21361 VkSemaphore semaphore;
21362 VkSemaphoreCreateInfo semaphore_create_info{};
21363 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21364 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21365
21366 VkCommandPool command_pool;
21367 VkCommandPoolCreateInfo pool_create_info{};
21368 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21369 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21370 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21371 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21372
21373 VkCommandBuffer command_buffer[2];
21374 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21375 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21376 command_buffer_allocate_info.commandPool = command_pool;
21377 command_buffer_allocate_info.commandBufferCount = 2;
21378 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21379 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21380
21381 {
21382 VkCommandBufferBeginInfo begin_info{};
21383 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21384 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21385
21386 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 -070021387 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021388
21389 VkViewport viewport{};
21390 viewport.maxDepth = 1.0f;
21391 viewport.minDepth = 0.0f;
21392 viewport.width = 512;
21393 viewport.height = 512;
21394 viewport.x = 0;
21395 viewport.y = 0;
21396 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21397 vkEndCommandBuffer(command_buffer[0]);
21398 }
21399 {
21400 VkCommandBufferBeginInfo begin_info{};
21401 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21402 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21403
21404 VkViewport viewport{};
21405 viewport.maxDepth = 1.0f;
21406 viewport.minDepth = 0.0f;
21407 viewport.width = 512;
21408 viewport.height = 512;
21409 viewport.x = 0;
21410 viewport.y = 0;
21411 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21412 vkEndCommandBuffer(command_buffer[1]);
21413 }
21414 {
21415 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021416 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021417
21418 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21419 submit_info[0].pNext = NULL;
21420 submit_info[0].commandBufferCount = 1;
21421 submit_info[0].pCommandBuffers = &command_buffer[0];
21422 submit_info[0].signalSemaphoreCount = 1;
21423 submit_info[0].pSignalSemaphores = &semaphore;
21424 submit_info[0].waitSemaphoreCount = 0;
21425 submit_info[0].pWaitSemaphores = NULL;
21426 submit_info[0].pWaitDstStageMask = 0;
21427
21428 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21429 submit_info[1].pNext = NULL;
21430 submit_info[1].commandBufferCount = 1;
21431 submit_info[1].pCommandBuffers = &command_buffer[1];
21432 submit_info[1].waitSemaphoreCount = 1;
21433 submit_info[1].pWaitSemaphores = &semaphore;
21434 submit_info[1].pWaitDstStageMask = flags;
21435 submit_info[1].signalSemaphoreCount = 0;
21436 submit_info[1].pSignalSemaphores = NULL;
21437 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21438 }
21439
21440 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21441
21442 vkDestroyFence(m_device->device(), fence, nullptr);
21443 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21444 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21445 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21446
21447 m_errorMonitor->VerifyNotFound();
21448}
21449
21450TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21451 m_errorMonitor->ExpectSuccess();
21452
21453 ASSERT_NO_FATAL_FAILURE(InitState());
21454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21455
Tony Barbour552f6c02016-12-21 14:34:07 -070021456 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021457
21458 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21459 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21460 m_errorMonitor->VerifyNotFound();
21461 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21462 m_errorMonitor->VerifyNotFound();
21463 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21464 m_errorMonitor->VerifyNotFound();
21465
21466 m_commandBuffer->EndCommandBuffer();
21467 m_errorMonitor->VerifyNotFound();
21468}
21469
21470TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021471 TEST_DESCRIPTION(
21472 "Positive test where we create a renderpass with an "
21473 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21474 "has a valid layout, and a second subpass then uses a "
21475 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021476 m_errorMonitor->ExpectSuccess();
21477 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070021478 auto depth_format = find_depth_stencil_format(m_device);
21479 if (!depth_format) {
21480 printf(" No Depth + Stencil format found. Skipped.\n");
21481 return;
21482 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021483
21484 VkAttachmentReference attach[2] = {};
21485 attach[0].attachment = 0;
21486 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21487 attach[1].attachment = 0;
21488 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21489 VkSubpassDescription subpasses[2] = {};
21490 // First subpass clears DS attach on load
21491 subpasses[0].pDepthStencilAttachment = &attach[0];
21492 // 2nd subpass reads in DS as input attachment
21493 subpasses[1].inputAttachmentCount = 1;
21494 subpasses[1].pInputAttachments = &attach[1];
21495 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070021496 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021497 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21498 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21499 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21500 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21501 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21502 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21503 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21504 VkRenderPassCreateInfo rpci = {};
21505 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21506 rpci.attachmentCount = 1;
21507 rpci.pAttachments = &attach_desc;
21508 rpci.subpassCount = 2;
21509 rpci.pSubpasses = subpasses;
21510
21511 // Now create RenderPass and verify no errors
21512 VkRenderPass rp;
21513 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21514 m_errorMonitor->VerifyNotFound();
21515
21516 vkDestroyRenderPass(m_device->device(), rp, NULL);
21517}
21518
Tobin Ehlis01103de2017-02-16 13:22:47 -070021519TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21520 TEST_DESCRIPTION(
21521 "Create a render pass with depth-stencil attachment where layout transition "
21522 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21523 "transition has correctly occurred at queue submit time with no validation errors.");
21524
Tony Barbourf887b162017-03-09 10:06:46 -070021525 ASSERT_NO_FATAL_FAILURE(InitState());
21526 auto depth_format = find_depth_stencil_format(m_device);
21527 if (!depth_format) {
21528 printf(" No Depth + Stencil format found. Skipped.\n");
21529 return;
21530 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070021531 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070021532 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021533 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21534 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070021535 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070021536 return;
21537 }
21538
21539 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070021540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21541
21542 // A renderpass with one depth/stencil attachment.
21543 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070021544 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021545 VK_SAMPLE_COUNT_1_BIT,
21546 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21547 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21548 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21549 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21550 VK_IMAGE_LAYOUT_UNDEFINED,
21551 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21552
21553 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21554
21555 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21556
21557 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21558
21559 VkRenderPass rp;
21560 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21561 ASSERT_VK_SUCCESS(err);
21562 // A compatible ds image.
21563 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070021564 image.init(32, 32, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis01103de2017-02-16 13:22:47 -070021565 ASSERT_TRUE(image.initialized());
21566
21567 VkImageViewCreateInfo ivci = {
21568 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21569 nullptr,
21570 0,
21571 image.handle(),
21572 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070021573 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021574 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21575 VK_COMPONENT_SWIZZLE_IDENTITY},
21576 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21577 };
21578 VkImageView view;
21579 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21580 ASSERT_VK_SUCCESS(err);
21581
21582 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21583 VkFramebuffer fb;
21584 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21585 ASSERT_VK_SUCCESS(err);
21586
21587 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21588 m_commandBuffer->BeginCommandBuffer();
21589 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21590 vkCmdEndRenderPass(m_commandBuffer->handle());
21591 m_commandBuffer->EndCommandBuffer();
21592 QueueCommandBuffer(false);
21593 m_errorMonitor->VerifyNotFound();
21594
21595 // Cleanup
21596 vkDestroyImageView(m_device->device(), view, NULL);
21597 vkDestroyRenderPass(m_device->device(), rp, NULL);
21598 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21599}
21600
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021601TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021602 TEST_DESCRIPTION(
21603 "Test that pipeline validation accepts matrices passed "
21604 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021605 m_errorMonitor->ExpectSuccess();
21606
21607 ASSERT_NO_FATAL_FAILURE(InitState());
21608 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21609
21610 VkVertexInputBindingDescription input_binding;
21611 memset(&input_binding, 0, sizeof(input_binding));
21612
21613 VkVertexInputAttributeDescription input_attribs[2];
21614 memset(input_attribs, 0, sizeof(input_attribs));
21615
21616 for (int i = 0; i < 2; i++) {
21617 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21618 input_attribs[i].location = i;
21619 }
21620
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021621 char const *vsSource =
21622 "#version 450\n"
21623 "\n"
21624 "layout(location=0) in mat2x4 x;\n"
21625 "out gl_PerVertex {\n"
21626 " vec4 gl_Position;\n"
21627 "};\n"
21628 "void main(){\n"
21629 " gl_Position = x[0] + x[1];\n"
21630 "}\n";
21631 char const *fsSource =
21632 "#version 450\n"
21633 "\n"
21634 "layout(location=0) out vec4 color;\n"
21635 "void main(){\n"
21636 " color = vec4(1);\n"
21637 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021638
21639 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21640 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21641
21642 VkPipelineObj pipe(m_device);
21643 pipe.AddColorAttachment();
21644 pipe.AddShader(&vs);
21645 pipe.AddShader(&fs);
21646
21647 pipe.AddVertexInputBindings(&input_binding, 1);
21648 pipe.AddVertexInputAttribs(input_attribs, 2);
21649
21650 VkDescriptorSetObj descriptorSet(m_device);
21651 descriptorSet.AppendDummy();
21652 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21653
21654 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21655
21656 /* expect success */
21657 m_errorMonitor->VerifyNotFound();
21658}
21659
21660TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21661 m_errorMonitor->ExpectSuccess();
21662
21663 ASSERT_NO_FATAL_FAILURE(InitState());
21664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21665
21666 VkVertexInputBindingDescription input_binding;
21667 memset(&input_binding, 0, sizeof(input_binding));
21668
21669 VkVertexInputAttributeDescription input_attribs[2];
21670 memset(input_attribs, 0, sizeof(input_attribs));
21671
21672 for (int i = 0; i < 2; i++) {
21673 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21674 input_attribs[i].location = i;
21675 }
21676
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021677 char const *vsSource =
21678 "#version 450\n"
21679 "\n"
21680 "layout(location=0) in vec4 x[2];\n"
21681 "out gl_PerVertex {\n"
21682 " vec4 gl_Position;\n"
21683 "};\n"
21684 "void main(){\n"
21685 " gl_Position = x[0] + x[1];\n"
21686 "}\n";
21687 char const *fsSource =
21688 "#version 450\n"
21689 "\n"
21690 "layout(location=0) out vec4 color;\n"
21691 "void main(){\n"
21692 " color = vec4(1);\n"
21693 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021694
21695 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21696 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21697
21698 VkPipelineObj pipe(m_device);
21699 pipe.AddColorAttachment();
21700 pipe.AddShader(&vs);
21701 pipe.AddShader(&fs);
21702
21703 pipe.AddVertexInputBindings(&input_binding, 1);
21704 pipe.AddVertexInputAttribs(input_attribs, 2);
21705
21706 VkDescriptorSetObj descriptorSet(m_device);
21707 descriptorSet.AppendDummy();
21708 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21709
21710 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21711
21712 m_errorMonitor->VerifyNotFound();
21713}
21714
21715TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021716 TEST_DESCRIPTION(
21717 "Test that pipeline validation accepts consuming a vertex attribute "
21718 "through multiple vertex shader inputs, each consuming a different "
21719 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021720 m_errorMonitor->ExpectSuccess();
21721
21722 ASSERT_NO_FATAL_FAILURE(InitState());
21723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21724
21725 VkVertexInputBindingDescription input_binding;
21726 memset(&input_binding, 0, sizeof(input_binding));
21727
21728 VkVertexInputAttributeDescription input_attribs[3];
21729 memset(input_attribs, 0, sizeof(input_attribs));
21730
21731 for (int i = 0; i < 3; i++) {
21732 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21733 input_attribs[i].location = i;
21734 }
21735
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021736 char const *vsSource =
21737 "#version 450\n"
21738 "\n"
21739 "layout(location=0) in vec4 x;\n"
21740 "layout(location=1) in vec3 y1;\n"
21741 "layout(location=1, component=3) in float y2;\n"
21742 "layout(location=2) in vec4 z;\n"
21743 "out gl_PerVertex {\n"
21744 " vec4 gl_Position;\n"
21745 "};\n"
21746 "void main(){\n"
21747 " gl_Position = x + vec4(y1, y2) + z;\n"
21748 "}\n";
21749 char const *fsSource =
21750 "#version 450\n"
21751 "\n"
21752 "layout(location=0) out vec4 color;\n"
21753 "void main(){\n"
21754 " color = vec4(1);\n"
21755 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021756
21757 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21758 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21759
21760 VkPipelineObj pipe(m_device);
21761 pipe.AddColorAttachment();
21762 pipe.AddShader(&vs);
21763 pipe.AddShader(&fs);
21764
21765 pipe.AddVertexInputBindings(&input_binding, 1);
21766 pipe.AddVertexInputAttribs(input_attribs, 3);
21767
21768 VkDescriptorSetObj descriptorSet(m_device);
21769 descriptorSet.AppendDummy();
21770 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21771
21772 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21773
21774 m_errorMonitor->VerifyNotFound();
21775}
21776
21777TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21778 m_errorMonitor->ExpectSuccess();
21779
21780 ASSERT_NO_FATAL_FAILURE(InitState());
21781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21782
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021783 char const *vsSource =
21784 "#version 450\n"
21785 "out gl_PerVertex {\n"
21786 " vec4 gl_Position;\n"
21787 "};\n"
21788 "void main(){\n"
21789 " gl_Position = vec4(0);\n"
21790 "}\n";
21791 char const *fsSource =
21792 "#version 450\n"
21793 "\n"
21794 "layout(location=0) out vec4 color;\n"
21795 "void main(){\n"
21796 " color = vec4(1);\n"
21797 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021798
21799 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21800 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21801
21802 VkPipelineObj pipe(m_device);
21803 pipe.AddColorAttachment();
21804 pipe.AddShader(&vs);
21805 pipe.AddShader(&fs);
21806
21807 VkDescriptorSetObj descriptorSet(m_device);
21808 descriptorSet.AppendDummy();
21809 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21810
21811 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21812
21813 m_errorMonitor->VerifyNotFound();
21814}
21815
21816TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021817 TEST_DESCRIPTION(
21818 "Test that pipeline validation accepts the relaxed type matching rules "
21819 "set out in 14.1.3: fundamental type must match, and producer side must "
21820 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021821 m_errorMonitor->ExpectSuccess();
21822
21823 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21824
21825 ASSERT_NO_FATAL_FAILURE(InitState());
21826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21827
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021828 char const *vsSource =
21829 "#version 450\n"
21830 "out gl_PerVertex {\n"
21831 " vec4 gl_Position;\n"
21832 "};\n"
21833 "layout(location=0) out vec3 x;\n"
21834 "layout(location=1) out ivec3 y;\n"
21835 "layout(location=2) out vec3 z;\n"
21836 "void main(){\n"
21837 " gl_Position = vec4(0);\n"
21838 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21839 "}\n";
21840 char const *fsSource =
21841 "#version 450\n"
21842 "\n"
21843 "layout(location=0) out vec4 color;\n"
21844 "layout(location=0) in float x;\n"
21845 "layout(location=1) flat in int y;\n"
21846 "layout(location=2) in vec2 z;\n"
21847 "void main(){\n"
21848 " color = vec4(1 + x + y + z.x);\n"
21849 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021850
21851 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21852 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21853
21854 VkPipelineObj pipe(m_device);
21855 pipe.AddColorAttachment();
21856 pipe.AddShader(&vs);
21857 pipe.AddShader(&fs);
21858
21859 VkDescriptorSetObj descriptorSet(m_device);
21860 descriptorSet.AppendDummy();
21861 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21862
21863 VkResult err = VK_SUCCESS;
21864 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21865 ASSERT_VK_SUCCESS(err);
21866
21867 m_errorMonitor->VerifyNotFound();
21868}
21869
21870TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021871 TEST_DESCRIPTION(
21872 "Test that pipeline validation accepts per-vertex variables "
21873 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021874 m_errorMonitor->ExpectSuccess();
21875
21876 ASSERT_NO_FATAL_FAILURE(InitState());
21877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21878
21879 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021880 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021881 return;
21882 }
21883
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021884 char const *vsSource =
21885 "#version 450\n"
21886 "void main(){}\n";
21887 char const *tcsSource =
21888 "#version 450\n"
21889 "layout(location=0) out int x[];\n"
21890 "layout(vertices=3) out;\n"
21891 "void main(){\n"
21892 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21893 " gl_TessLevelInner[0] = 1;\n"
21894 " x[gl_InvocationID] = gl_InvocationID;\n"
21895 "}\n";
21896 char const *tesSource =
21897 "#version 450\n"
21898 "layout(triangles, equal_spacing, cw) in;\n"
21899 "layout(location=0) in int x[];\n"
21900 "out gl_PerVertex { vec4 gl_Position; };\n"
21901 "void main(){\n"
21902 " gl_Position.xyz = gl_TessCoord;\n"
21903 " gl_Position.w = x[0] + x[1] + x[2];\n"
21904 "}\n";
21905 char const *fsSource =
21906 "#version 450\n"
21907 "layout(location=0) out vec4 color;\n"
21908 "void main(){\n"
21909 " color = vec4(1);\n"
21910 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021911
21912 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21913 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21914 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21915 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21916
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021917 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21918 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021919
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021920 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021921
21922 VkPipelineObj pipe(m_device);
21923 pipe.SetInputAssembly(&iasci);
21924 pipe.SetTessellation(&tsci);
21925 pipe.AddColorAttachment();
21926 pipe.AddShader(&vs);
21927 pipe.AddShader(&tcs);
21928 pipe.AddShader(&tes);
21929 pipe.AddShader(&fs);
21930
21931 VkDescriptorSetObj descriptorSet(m_device);
21932 descriptorSet.AppendDummy();
21933 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21934
21935 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21936
21937 m_errorMonitor->VerifyNotFound();
21938}
21939
21940TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021941 TEST_DESCRIPTION(
21942 "Test that pipeline validation accepts a user-defined "
21943 "interface block passed into the geometry shader. This "
21944 "is interesting because the 'extra' array level is not "
21945 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021946 m_errorMonitor->ExpectSuccess();
21947
21948 ASSERT_NO_FATAL_FAILURE(InitState());
21949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21950
21951 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021952 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021953 return;
21954 }
21955
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021956 char const *vsSource =
21957 "#version 450\n"
21958 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21959 "void main(){\n"
21960 " vs_out.x = vec4(1);\n"
21961 "}\n";
21962 char const *gsSource =
21963 "#version 450\n"
21964 "layout(triangles) in;\n"
21965 "layout(triangle_strip, max_vertices=3) out;\n"
21966 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21967 "out gl_PerVertex { vec4 gl_Position; };\n"
21968 "void main() {\n"
21969 " gl_Position = gs_in[0].x;\n"
21970 " EmitVertex();\n"
21971 "}\n";
21972 char const *fsSource =
21973 "#version 450\n"
21974 "layout(location=0) out vec4 color;\n"
21975 "void main(){\n"
21976 " color = vec4(1);\n"
21977 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021978
21979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21980 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21981 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21982
21983 VkPipelineObj pipe(m_device);
21984 pipe.AddColorAttachment();
21985 pipe.AddShader(&vs);
21986 pipe.AddShader(&gs);
21987 pipe.AddShader(&fs);
21988
21989 VkDescriptorSetObj descriptorSet(m_device);
21990 descriptorSet.AppendDummy();
21991 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21992
21993 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21994
21995 m_errorMonitor->VerifyNotFound();
21996}
21997
21998TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021999 TEST_DESCRIPTION(
22000 "Test that pipeline validation accepts basic use of 64bit vertex "
22001 "attributes. This is interesting because they consume multiple "
22002 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022003 m_errorMonitor->ExpectSuccess();
22004
22005 ASSERT_NO_FATAL_FAILURE(InitState());
22006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22007
22008 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022009 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022010 return;
22011 }
22012
22013 VkVertexInputBindingDescription input_bindings[1];
22014 memset(input_bindings, 0, sizeof(input_bindings));
22015
22016 VkVertexInputAttributeDescription input_attribs[4];
22017 memset(input_attribs, 0, sizeof(input_attribs));
22018 input_attribs[0].location = 0;
22019 input_attribs[0].offset = 0;
22020 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22021 input_attribs[1].location = 2;
22022 input_attribs[1].offset = 32;
22023 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22024 input_attribs[2].location = 4;
22025 input_attribs[2].offset = 64;
22026 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22027 input_attribs[3].location = 6;
22028 input_attribs[3].offset = 96;
22029 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22030
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022031 char const *vsSource =
22032 "#version 450\n"
22033 "\n"
22034 "layout(location=0) in dmat4 x;\n"
22035 "out gl_PerVertex {\n"
22036 " vec4 gl_Position;\n"
22037 "};\n"
22038 "void main(){\n"
22039 " gl_Position = vec4(x[0][0]);\n"
22040 "}\n";
22041 char const *fsSource =
22042 "#version 450\n"
22043 "\n"
22044 "layout(location=0) out vec4 color;\n"
22045 "void main(){\n"
22046 " color = vec4(1);\n"
22047 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022048
22049 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22050 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22051
22052 VkPipelineObj pipe(m_device);
22053 pipe.AddColorAttachment();
22054 pipe.AddShader(&vs);
22055 pipe.AddShader(&fs);
22056
22057 pipe.AddVertexInputBindings(input_bindings, 1);
22058 pipe.AddVertexInputAttribs(input_attribs, 4);
22059
22060 VkDescriptorSetObj descriptorSet(m_device);
22061 descriptorSet.AppendDummy();
22062 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22063
22064 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22065
22066 m_errorMonitor->VerifyNotFound();
22067}
22068
22069TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
22070 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
22071 m_errorMonitor->ExpectSuccess();
22072
22073 ASSERT_NO_FATAL_FAILURE(InitState());
22074
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022075 char const *vsSource =
22076 "#version 450\n"
22077 "\n"
22078 "out gl_PerVertex {\n"
22079 " vec4 gl_Position;\n"
22080 "};\n"
22081 "void main(){\n"
22082 " gl_Position = vec4(1);\n"
22083 "}\n";
22084 char const *fsSource =
22085 "#version 450\n"
22086 "\n"
22087 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
22088 "layout(location=0) out vec4 color;\n"
22089 "void main() {\n"
22090 " color = subpassLoad(x);\n"
22091 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022092
22093 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22094 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22095
22096 VkPipelineObj pipe(m_device);
22097 pipe.AddShader(&vs);
22098 pipe.AddShader(&fs);
22099 pipe.AddColorAttachment();
22100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22101
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022102 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
22103 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022104 VkDescriptorSetLayout dsl;
22105 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22106 ASSERT_VK_SUCCESS(err);
22107
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022108 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022109 VkPipelineLayout pl;
22110 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22111 ASSERT_VK_SUCCESS(err);
22112
22113 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022114 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22115 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22116 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
22117 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22118 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 -060022119 };
22120 VkAttachmentReference color = {
22121 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22122 };
22123 VkAttachmentReference input = {
22124 1, VK_IMAGE_LAYOUT_GENERAL,
22125 };
22126
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022127 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022128
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022129 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022130 VkRenderPass rp;
22131 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22132 ASSERT_VK_SUCCESS(err);
22133
22134 // should be OK. would go wrong here if it's going to...
22135 pipe.CreateVKPipeline(pl, rp);
22136
22137 m_errorMonitor->VerifyNotFound();
22138
22139 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22140 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22141 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22142}
22143
22144TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022145 TEST_DESCRIPTION(
22146 "Test that pipeline validation accepts a compute pipeline which declares a "
22147 "descriptor-backed resource which is not provided, but the shader does not "
22148 "statically use it. This is interesting because it requires compute pipelines "
22149 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022150 m_errorMonitor->ExpectSuccess();
22151
22152 ASSERT_NO_FATAL_FAILURE(InitState());
22153
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022154 char const *csSource =
22155 "#version 450\n"
22156 "\n"
22157 "layout(local_size_x=1) in;\n"
22158 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
22159 "void main(){\n"
22160 " // x is not used.\n"
22161 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022162
22163 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22164
22165 VkDescriptorSetObj descriptorSet(m_device);
22166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22167
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022168 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22169 nullptr,
22170 0,
22171 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22172 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22173 descriptorSet.GetPipelineLayout(),
22174 VK_NULL_HANDLE,
22175 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022176
22177 VkPipeline pipe;
22178 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22179
22180 m_errorMonitor->VerifyNotFound();
22181
22182 if (err == VK_SUCCESS) {
22183 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22184 }
22185}
22186
22187TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022188 TEST_DESCRIPTION(
22189 "Test that pipeline validation accepts a shader consuming only the "
22190 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022191 m_errorMonitor->ExpectSuccess();
22192
22193 ASSERT_NO_FATAL_FAILURE(InitState());
22194
22195 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022196 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22197 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22198 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022199 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022200 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022201 VkDescriptorSetLayout dsl;
22202 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22203 ASSERT_VK_SUCCESS(err);
22204
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022205 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022206 VkPipelineLayout pl;
22207 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22208 ASSERT_VK_SUCCESS(err);
22209
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022210 char const *csSource =
22211 "#version 450\n"
22212 "\n"
22213 "layout(local_size_x=1) in;\n"
22214 "layout(set=0, binding=0) uniform sampler s;\n"
22215 "layout(set=0, binding=1) uniform texture2D t;\n"
22216 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22217 "void main() {\n"
22218 " x = texture(sampler2D(t, s), vec2(0));\n"
22219 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022220 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22221
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022222 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22223 nullptr,
22224 0,
22225 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22226 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22227 pl,
22228 VK_NULL_HANDLE,
22229 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022230
22231 VkPipeline pipe;
22232 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22233
22234 m_errorMonitor->VerifyNotFound();
22235
22236 if (err == VK_SUCCESS) {
22237 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22238 }
22239
22240 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22241 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22242}
22243
22244TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022245 TEST_DESCRIPTION(
22246 "Test that pipeline validation accepts a shader consuming only the "
22247 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022248 m_errorMonitor->ExpectSuccess();
22249
22250 ASSERT_NO_FATAL_FAILURE(InitState());
22251
22252 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022253 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22254 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22255 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022256 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022257 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022258 VkDescriptorSetLayout dsl;
22259 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22260 ASSERT_VK_SUCCESS(err);
22261
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022262 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022263 VkPipelineLayout pl;
22264 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22265 ASSERT_VK_SUCCESS(err);
22266
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022267 char const *csSource =
22268 "#version 450\n"
22269 "\n"
22270 "layout(local_size_x=1) in;\n"
22271 "layout(set=0, binding=0) uniform texture2D t;\n"
22272 "layout(set=0, binding=1) uniform sampler s;\n"
22273 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22274 "void main() {\n"
22275 " x = texture(sampler2D(t, s), vec2(0));\n"
22276 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022277 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22278
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022279 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22280 nullptr,
22281 0,
22282 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22283 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22284 pl,
22285 VK_NULL_HANDLE,
22286 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022287
22288 VkPipeline pipe;
22289 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22290
22291 m_errorMonitor->VerifyNotFound();
22292
22293 if (err == VK_SUCCESS) {
22294 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22295 }
22296
22297 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22298 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22299}
22300
22301TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022302 TEST_DESCRIPTION(
22303 "Test that pipeline validation accepts a shader consuming "
22304 "both the sampler and the image of a combined image+sampler "
22305 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022306 m_errorMonitor->ExpectSuccess();
22307
22308 ASSERT_NO_FATAL_FAILURE(InitState());
22309
22310 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022311 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22312 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022313 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022314 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022315 VkDescriptorSetLayout dsl;
22316 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22317 ASSERT_VK_SUCCESS(err);
22318
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022319 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022320 VkPipelineLayout pl;
22321 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22322 ASSERT_VK_SUCCESS(err);
22323
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022324 char const *csSource =
22325 "#version 450\n"
22326 "\n"
22327 "layout(local_size_x=1) in;\n"
22328 "layout(set=0, binding=0) uniform texture2D t;\n"
22329 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22330 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22331 "void main() {\n"
22332 " x = texture(sampler2D(t, s), vec2(0));\n"
22333 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022334 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22335
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022336 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22337 nullptr,
22338 0,
22339 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22340 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22341 pl,
22342 VK_NULL_HANDLE,
22343 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022344
22345 VkPipeline pipe;
22346 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22347
22348 m_errorMonitor->VerifyNotFound();
22349
22350 if (err == VK_SUCCESS) {
22351 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22352 }
22353
22354 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22355 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22356}
22357
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060022358// This test class enables the Maintenance1 extension for related validation tests
22359TEST_F(VkMaintenance1LayerTest, Maintenance1Tests) {
22360 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
22361
22362 // Ensure that extension is available and enabled.
22363 uint32_t extension_count = 0;
22364 bool supports_maintenance1_extension = false;
22365 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22366 ASSERT_VK_SUCCESS(err);
22367 if (extension_count > 0) {
22368 std::vector<VkExtensionProperties> available_extensions(extension_count);
22369
22370 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22371 ASSERT_VK_SUCCESS(err);
22372 for (const auto &extension_props : available_extensions) {
22373 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
22374 supports_maintenance1_extension = true;
22375 }
22376 }
22377 }
22378
22379 // Proceed if extension is supported by hardware
22380 if (!supports_maintenance1_extension) {
22381 printf(" Maintenance1 Extension not supported, skipping tests\n");
22382 return;
22383 }
22384 ASSERT_NO_FATAL_FAILURE(InitState());
22385
22386 m_errorMonitor->ExpectSuccess();
22387
22388 VkCommandBuffer cmd_buf;
22389 VkCommandBufferAllocateInfo alloc_info;
22390 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22391 alloc_info.pNext = NULL;
22392 alloc_info.commandBufferCount = 1;
22393 alloc_info.commandPool = m_commandPool;
22394 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22395 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
22396
22397 VkCommandBufferBeginInfo cb_binfo;
22398 cb_binfo.pNext = NULL;
22399 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22400 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
22401 cb_binfo.flags = 0;
22402 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
22403 // Set Negative height, should give error if Maintenance 1 is not enabled
22404 VkViewport viewport = {0, 0, 16, -16, 0, 1};
22405 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
22406 vkEndCommandBuffer(cmd_buf);
22407
22408 m_errorMonitor->VerifyNotFound();
22409}
22410
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022411TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22412 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22413
22414 ASSERT_NO_FATAL_FAILURE(InitState());
22415
22416 // Positive test to check parameter_validation and unique_objects support
22417 // for NV_dedicated_allocation
22418 uint32_t extension_count = 0;
22419 bool supports_nv_dedicated_allocation = false;
22420 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22421 ASSERT_VK_SUCCESS(err);
22422
22423 if (extension_count > 0) {
22424 std::vector<VkExtensionProperties> available_extensions(extension_count);
22425
22426 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22427 ASSERT_VK_SUCCESS(err);
22428
22429 for (const auto &extension_props : available_extensions) {
22430 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22431 supports_nv_dedicated_allocation = true;
22432 }
22433 }
22434 }
22435
22436 if (supports_nv_dedicated_allocation) {
22437 m_errorMonitor->ExpectSuccess();
22438
22439 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22440 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22441 dedicated_buffer_create_info.pNext = nullptr;
22442 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22443
22444 uint32_t queue_family_index = 0;
22445 VkBufferCreateInfo buffer_create_info = {};
22446 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22447 buffer_create_info.pNext = &dedicated_buffer_create_info;
22448 buffer_create_info.size = 1024;
22449 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22450 buffer_create_info.queueFamilyIndexCount = 1;
22451 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22452
22453 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022454 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022455 ASSERT_VK_SUCCESS(err);
22456
22457 VkMemoryRequirements memory_reqs;
22458 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22459
22460 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22461 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22462 dedicated_memory_info.pNext = nullptr;
22463 dedicated_memory_info.buffer = buffer;
22464 dedicated_memory_info.image = VK_NULL_HANDLE;
22465
22466 VkMemoryAllocateInfo memory_info = {};
22467 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22468 memory_info.pNext = &dedicated_memory_info;
22469 memory_info.allocationSize = memory_reqs.size;
22470
22471 bool pass;
22472 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22473 ASSERT_TRUE(pass);
22474
22475 VkDeviceMemory buffer_memory;
22476 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22477 ASSERT_VK_SUCCESS(err);
22478
22479 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22480 ASSERT_VK_SUCCESS(err);
22481
22482 vkDestroyBuffer(m_device->device(), buffer, NULL);
22483 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22484
22485 m_errorMonitor->VerifyNotFound();
22486 }
22487}
22488
22489TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22490 VkResult err;
22491
22492 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22493
22494 ASSERT_NO_FATAL_FAILURE(InitState());
22495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22496
22497 std::vector<const char *> device_extension_names;
22498 auto features = m_device->phy().features();
22499 // Artificially disable support for non-solid fill modes
22500 features.fillModeNonSolid = false;
22501 // The sacrificial device object
22502 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22503
22504 VkRenderpassObj render_pass(&test_device);
22505
22506 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22507 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22508 pipeline_layout_ci.setLayoutCount = 0;
22509 pipeline_layout_ci.pSetLayouts = NULL;
22510
22511 VkPipelineLayout pipeline_layout;
22512 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22513 ASSERT_VK_SUCCESS(err);
22514
22515 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22516 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22517 rs_ci.pNext = nullptr;
22518 rs_ci.lineWidth = 1.0f;
22519 rs_ci.rasterizerDiscardEnable = true;
22520
22521 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22522 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22523
22524 // Set polygonMode=FILL. No error is expected
22525 m_errorMonitor->ExpectSuccess();
22526 {
22527 VkPipelineObj pipe(&test_device);
22528 pipe.AddShader(&vs);
22529 pipe.AddShader(&fs);
22530 pipe.AddColorAttachment();
22531 // Set polygonMode to a good value
22532 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22533 pipe.SetRasterization(&rs_ci);
22534 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22535 }
22536 m_errorMonitor->VerifyNotFound();
22537
22538 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22539}
22540
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022541#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022542TEST_F(VkPositiveLayerTest, LongFenceChain)
22543{
22544 m_errorMonitor->ExpectSuccess();
22545
22546 ASSERT_NO_FATAL_FAILURE(InitState());
22547 VkResult err;
22548
22549 std::vector<VkFence> fences;
22550
22551 const int chainLength = 32768;
22552
22553 for (int i = 0; i < chainLength; i++) {
22554 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22555 VkFence fence;
22556 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22557 ASSERT_VK_SUCCESS(err);
22558
22559 fences.push_back(fence);
22560
22561 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22562 0, nullptr, 0, nullptr };
22563 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22564 ASSERT_VK_SUCCESS(err);
22565
22566 }
22567
22568 // BOOM, stack overflow.
22569 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22570
22571 for (auto fence : fences)
22572 vkDestroyFence(m_device->device(), fence, nullptr);
22573
22574 m_errorMonitor->VerifyNotFound();
22575}
22576#endif
22577
Cody Northrop1242dfd2016-07-13 17:24:59 -060022578#if defined(ANDROID) && defined(VALIDATION_APK)
22579static bool initialized = false;
22580static bool active = false;
22581
22582// Convert Intents to argv
22583// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022584std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022585 std::vector<std::string> args;
22586 JavaVM &vm = *app.activity->vm;
22587 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022588 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022589
22590 JNIEnv &env = *p_env;
22591 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022592 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022593 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022594 jmethodID get_string_extra_method =
22595 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022596 jvalue get_string_extra_args;
22597 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022598 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022599
22600 std::string args_str;
22601 if (extra_str) {
22602 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22603 args_str = extra_utf;
22604 env.ReleaseStringUTFChars(extra_str, extra_utf);
22605 env.DeleteLocalRef(extra_str);
22606 }
22607
22608 env.DeleteLocalRef(get_string_extra_args.l);
22609 env.DeleteLocalRef(intent);
22610 vm.DetachCurrentThread();
22611
22612 // split args_str
22613 std::stringstream ss(args_str);
22614 std::string arg;
22615 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022616 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022617 }
22618
22619 return args;
22620}
22621
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022622static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022624static void processCommand(struct android_app *app, int32_t cmd) {
22625 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022626 case APP_CMD_INIT_WINDOW: {
22627 if (app->window) {
22628 initialized = true;
22629 }
22630 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022631 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022632 case APP_CMD_GAINED_FOCUS: {
22633 active = true;
22634 break;
22635 }
22636 case APP_CMD_LOST_FOCUS: {
22637 active = false;
22638 break;
22639 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022640 }
22641}
22642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022643void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022644 app_dummy();
22645
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022646 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022647
22648 int vulkanSupport = InitVulkan();
22649 if (vulkanSupport == 0) {
22650 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22651 return;
22652 }
22653
22654 app->onAppCmd = processCommand;
22655 app->onInputEvent = processInput;
22656
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022657 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022658 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022659 struct android_poll_source *source;
22660 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022661 if (source) {
22662 source->process(app, source);
22663 }
22664
22665 if (app->destroyRequested != 0) {
22666 VkTestFramework::Finish();
22667 return;
22668 }
22669 }
22670
22671 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022672 // Use the following key to send arguments to gtest, i.e.
22673 // --es args "--gtest_filter=-VkLayerTest.foo"
22674 const char key[] = "args";
22675 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022676
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022677 std::string filter = "";
22678 if (args.size() > 0) {
22679 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22680 filter += args[0];
22681 } else {
22682 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22683 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022684
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022685 int argc = 2;
22686 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22687 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022688
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022689 // Route output to files until we can override the gtest output
22690 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22691 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022693 ::testing::InitGoogleTest(&argc, argv);
22694 VkTestFramework::InitArgs(&argc, argv);
22695 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022696
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022697 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022698
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022699 if (result != 0) {
22700 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22701 } else {
22702 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22703 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022705 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022706
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022707 fclose(stdout);
22708 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022709
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022710 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022711 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022712 }
22713 }
22714}
22715#endif
22716
Tony Barbour300a6082015-04-07 13:44:53 -060022717int main(int argc, char **argv) {
22718 int result;
22719
Cody Northrop8e54a402016-03-08 22:25:52 -070022720#ifdef ANDROID
22721 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022722 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022723#endif
22724
Tony Barbour300a6082015-04-07 13:44:53 -060022725 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022726 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022727
22728 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22729
22730 result = RUN_ALL_TESTS();
22731
Tony Barbour6918cd52015-04-09 12:58:51 -060022732 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022733 return result;
22734}