blob: b7918ead305591510375117650faf9e0b912fef4 [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);
Tony Barbour256c80a2016-10-05 13:23:46 -06009191 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009192 ASSERT_TRUE(image.initialized());
9193
9194 VkImageMemoryBarrier barrier = {};
9195 VkImageSubresourceRange range;
9196 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9197 barrier.srcAccessMask = 0;
9198 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9199 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9200 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9201 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9202 barrier.image = image.handle();
9203 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9204 range.baseMipLevel = 0;
9205 range.levelCount = 1;
9206 range.baseArrayLayer = 0;
9207 range.layerCount = 1;
9208 barrier.subresourceRange = range;
9209 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9210 cmdbuf.BeginCommandBuffer();
9211 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9212 &barrier);
9213 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9214 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9215 barrier.srcAccessMask = 0;
9216 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9217 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9218 &barrier);
9219
9220 m_errorMonitor->VerifyFound();
9221}
9222
Karl Schultz6addd812016-02-02 17:17:23 -07009223TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009224 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009225 ASSERT_NO_FATAL_FAILURE(InitState());
9226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009227
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009228 uint32_t const indices[] = {0};
9229 VkBufferCreateInfo buf_info = {};
9230 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9231 buf_info.size = 1024;
9232 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9233 buf_info.queueFamilyIndexCount = 1;
9234 buf_info.pQueueFamilyIndices = indices;
9235
9236 VkBuffer buffer;
9237 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
9238 ASSERT_VK_SUCCESS(err);
9239
9240 VkMemoryRequirements requirements;
9241 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
9242
9243 VkMemoryAllocateInfo alloc_info{};
9244 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9245 alloc_info.pNext = NULL;
9246 alloc_info.memoryTypeIndex = 0;
9247 alloc_info.allocationSize = requirements.size;
9248 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
9249 ASSERT_TRUE(pass);
9250
9251 VkDeviceMemory memory;
9252 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
9253 ASSERT_VK_SUCCESS(err);
9254
9255 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009256 ASSERT_VK_SUCCESS(err);
9257
Tony Barbour552f6c02016-12-21 14:34:07 -07009258 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009259 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009260
Karl Schultz6addd812016-02-02 17:17:23 -07009261 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9262 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009263 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
9265 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009266 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009267
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009268 vkFreeMemory(m_device->device(), memory, NULL);
9269 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009270}
9271
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009272TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9273 // Create an out-of-range queueFamilyIndex
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009274 ASSERT_NO_FATAL_FAILURE(InitState());
9275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9276 VkBufferCreateInfo buffCI = {};
9277 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9278 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009279 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009280 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009281 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009282 uint32_t qfi[2];
9283 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009284 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009285
9286 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009287 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009288
9289 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9291 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one of the indices "
9292 "specified when the device was created, via the VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009293 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009294 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009295
9296 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -07009297 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9299
9300 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9301 buffCI.queueFamilyIndexCount = 2;
9302 qfi[0] = 1;
9303 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -07009304 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009305 VkDeviceMemory mem;
9306 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -07009307 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009308
9309 VkMemoryAllocateInfo alloc_info = {};
9310 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9311 alloc_info.allocationSize = 1024;
9312 bool pass = false;
9313 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9314 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -07009315 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009316 return;
9317 }
9318 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -07009319 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009320
9321 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -07009322 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009323 m_commandBuffer->end();
9324 QueueCommandBuffer(false);
9325 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -07009326 vkDestroyBuffer(m_device->device(), ib2, NULL);
9327 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009328 }
9329
Tony Barbourdf4c0042016-06-01 15:55:43 -06009330 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009331}
9332
Karl Schultz6addd812016-02-02 17:17:23 -07009333TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009334 TEST_DESCRIPTION(
9335 "Attempt vkCmdExecuteCommands with a primary command buffer"
9336 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009337
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009338 ASSERT_NO_FATAL_FAILURE(InitState());
9339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009340
Chris Forbesf29a84f2016-10-06 18:39:28 +13009341 // An empty primary command buffer
9342 VkCommandBufferObj cb(m_device, m_commandPool);
9343 cb.BeginCommandBuffer();
9344 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009345
Chris Forbesf29a84f2016-10-06 18:39:28 +13009346 m_commandBuffer->BeginCommandBuffer();
9347 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9348 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009349
Chris Forbesf29a84f2016-10-06 18:39:28 +13009350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9351 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009352 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009353
9354 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009355}
9356
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009357TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009358 TEST_DESCRIPTION(
9359 "Attempt to update descriptor sets for images and buffers "
9360 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009361 VkResult err;
9362
9363 ASSERT_NO_FATAL_FAILURE(InitState());
9364 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9365 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9366 ds_type_count[i].type = VkDescriptorType(i);
9367 ds_type_count[i].descriptorCount = 1;
9368 }
9369 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9370 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9371 ds_pool_ci.pNext = NULL;
9372 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9373 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9374 ds_pool_ci.pPoolSizes = ds_type_count;
9375
9376 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009377 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009378 ASSERT_VK_SUCCESS(err);
9379
9380 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009381 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009382 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9383 dsl_binding[i].binding = 0;
9384 dsl_binding[i].descriptorType = VkDescriptorType(i);
9385 dsl_binding[i].descriptorCount = 1;
9386 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9387 dsl_binding[i].pImmutableSamplers = NULL;
9388 }
9389
9390 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9391 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9392 ds_layout_ci.pNext = NULL;
9393 ds_layout_ci.bindingCount = 1;
9394 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9395 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9396 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009397 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009398 ASSERT_VK_SUCCESS(err);
9399 }
9400 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9401 VkDescriptorSetAllocateInfo alloc_info = {};
9402 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9403 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9404 alloc_info.descriptorPool = ds_pool;
9405 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009406 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009407 ASSERT_VK_SUCCESS(err);
9408
9409 // Create a buffer & bufferView to be used for invalid updates
9410 VkBufferCreateInfo buff_ci = {};
9411 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009412 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009413 buff_ci.size = 256;
9414 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009415 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009416 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9417 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009418
9419 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9420 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9421 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9422 ASSERT_VK_SUCCESS(err);
9423
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009424 VkMemoryRequirements mem_reqs;
9425 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9426 VkMemoryAllocateInfo mem_alloc_info = {};
9427 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9428 mem_alloc_info.pNext = NULL;
9429 mem_alloc_info.memoryTypeIndex = 0;
9430 mem_alloc_info.allocationSize = mem_reqs.size;
9431 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9432 if (!pass) {
9433 vkDestroyBuffer(m_device->device(), buffer, NULL);
9434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9435 return;
9436 }
9437 VkDeviceMemory mem;
9438 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9439 ASSERT_VK_SUCCESS(err);
9440 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9441 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009442
9443 VkBufferViewCreateInfo buff_view_ci = {};
9444 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9445 buff_view_ci.buffer = buffer;
9446 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9447 buff_view_ci.range = VK_WHOLE_SIZE;
9448 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009449 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009450 ASSERT_VK_SUCCESS(err);
9451
Tony Barbour415497c2017-01-24 10:06:09 -07009452 // Now get resources / view for storage_texel_buffer
9453 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9454 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9455 if (!pass) {
9456 vkDestroyBuffer(m_device->device(), buffer, NULL);
9457 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9458 vkFreeMemory(m_device->device(), mem, NULL);
9459 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9461 return;
9462 }
9463 VkDeviceMemory storage_texel_buffer_mem;
9464 VkBufferView storage_texel_buffer_view;
9465 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9466 ASSERT_VK_SUCCESS(err);
9467 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9468 ASSERT_VK_SUCCESS(err);
9469 buff_view_ci.buffer = storage_texel_buffer;
9470 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9471 ASSERT_VK_SUCCESS(err);
9472
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009473 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009474 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009475 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009476 image_ci.format = VK_FORMAT_UNDEFINED;
9477 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9478 VkFormat format = static_cast<VkFormat>(f);
9479 VkFormatProperties fProps = m_device->format_properties(format);
9480 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9481 image_ci.format = format;
9482 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9483 break;
9484 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9485 image_ci.format = format;
9486 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9487 break;
9488 }
9489 }
9490 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9491 return;
9492 }
9493
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009494 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9495 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009496 image_ci.extent.width = 64;
9497 image_ci.extent.height = 64;
9498 image_ci.extent.depth = 1;
9499 image_ci.mipLevels = 1;
9500 image_ci.arrayLayers = 1;
9501 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009502 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009503 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009504 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9505 VkImage image;
9506 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9507 ASSERT_VK_SUCCESS(err);
9508 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009509 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009510
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009511 VkMemoryAllocateInfo mem_alloc = {};
9512 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9513 mem_alloc.pNext = NULL;
9514 mem_alloc.allocationSize = 0;
9515 mem_alloc.memoryTypeIndex = 0;
9516 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9517 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009518 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009519 ASSERT_TRUE(pass);
9520 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9521 ASSERT_VK_SUCCESS(err);
9522 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9523 ASSERT_VK_SUCCESS(err);
9524 // Now create view for image
9525 VkImageViewCreateInfo image_view_ci = {};
9526 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9527 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009528 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009529 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9530 image_view_ci.subresourceRange.layerCount = 1;
9531 image_view_ci.subresourceRange.baseArrayLayer = 0;
9532 image_view_ci.subresourceRange.levelCount = 1;
9533 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9534 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009535 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009536 ASSERT_VK_SUCCESS(err);
9537
9538 VkDescriptorBufferInfo buff_info = {};
9539 buff_info.buffer = buffer;
9540 VkDescriptorImageInfo img_info = {};
9541 img_info.imageView = image_view;
9542 VkWriteDescriptorSet descriptor_write = {};
9543 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9544 descriptor_write.dstBinding = 0;
9545 descriptor_write.descriptorCount = 1;
9546 descriptor_write.pTexelBufferView = &buff_view;
9547 descriptor_write.pBufferInfo = &buff_info;
9548 descriptor_write.pImageInfo = &img_info;
9549
9550 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009551 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009552 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9553 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9554 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9555 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9556 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9557 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9558 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9559 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9560 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9561 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9562 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009563 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009564 // Start loop at 1 as SAMPLER desc type has no usage bit error
9565 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009566 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9567 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9568 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9569 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009570 descriptor_write.descriptorType = VkDescriptorType(i);
9571 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009573
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009574 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009575
9576 m_errorMonitor->VerifyFound();
9577 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009578 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9579 descriptor_write.pTexelBufferView = &buff_view;
9580 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009581 }
Tony Barbour415497c2017-01-24 10:06:09 -07009582
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009583 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9584 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009585 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009586 vkDestroyImageView(m_device->device(), image_view, NULL);
9587 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009588 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009589 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009590 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009591 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009592 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009593 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9594}
9595
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009596TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009597 TEST_DESCRIPTION(
9598 "Attempt to update buffer descriptor set that has incorrect "
9599 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009600 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009601 "2. range value of 0\n"
9602 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009603 VkResult err;
9604
9605 ASSERT_NO_FATAL_FAILURE(InitState());
9606 VkDescriptorPoolSize ds_type_count = {};
9607 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9608 ds_type_count.descriptorCount = 1;
9609
9610 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9611 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9612 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009613 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009614 ds_pool_ci.maxSets = 1;
9615 ds_pool_ci.poolSizeCount = 1;
9616 ds_pool_ci.pPoolSizes = &ds_type_count;
9617
9618 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009619 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009620 ASSERT_VK_SUCCESS(err);
9621
9622 // Create layout with single uniform buffer descriptor
9623 VkDescriptorSetLayoutBinding dsl_binding = {};
9624 dsl_binding.binding = 0;
9625 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9626 dsl_binding.descriptorCount = 1;
9627 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9628 dsl_binding.pImmutableSamplers = NULL;
9629
9630 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9631 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9632 ds_layout_ci.pNext = NULL;
9633 ds_layout_ci.bindingCount = 1;
9634 ds_layout_ci.pBindings = &dsl_binding;
9635 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009636 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009637 ASSERT_VK_SUCCESS(err);
9638
9639 VkDescriptorSet descriptor_set = {};
9640 VkDescriptorSetAllocateInfo alloc_info = {};
9641 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9642 alloc_info.descriptorSetCount = 1;
9643 alloc_info.descriptorPool = ds_pool;
9644 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009645 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009646 ASSERT_VK_SUCCESS(err);
9647
9648 // Create a buffer to be used for invalid updates
9649 VkBufferCreateInfo buff_ci = {};
9650 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9651 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009652 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009653 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9654 VkBuffer buffer;
9655 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9656 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009657
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009658 // Have to bind memory to buffer before descriptor update
9659 VkMemoryAllocateInfo mem_alloc = {};
9660 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9661 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009662 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009663 mem_alloc.memoryTypeIndex = 0;
9664
9665 VkMemoryRequirements mem_reqs;
9666 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009667 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009668 if (!pass) {
9669 vkDestroyBuffer(m_device->device(), buffer, NULL);
9670 return;
9671 }
9672
9673 VkDeviceMemory mem;
9674 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9675 ASSERT_VK_SUCCESS(err);
9676 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9677 ASSERT_VK_SUCCESS(err);
9678
9679 VkDescriptorBufferInfo buff_info = {};
9680 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009681 // Cause error due to offset out of range
9682 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009683 buff_info.range = VK_WHOLE_SIZE;
9684 VkWriteDescriptorSet descriptor_write = {};
9685 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9686 descriptor_write.dstBinding = 0;
9687 descriptor_write.descriptorCount = 1;
9688 descriptor_write.pTexelBufferView = nullptr;
9689 descriptor_write.pBufferInfo = &buff_info;
9690 descriptor_write.pImageInfo = nullptr;
9691
9692 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9693 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009695
9696 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9697
9698 m_errorMonitor->VerifyFound();
9699 // Now cause error due to range of 0
9700 buff_info.offset = 0;
9701 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009703
9704 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9705
9706 m_errorMonitor->VerifyFound();
9707 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009708 buff_info.offset = 0;
9709 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009711
9712 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9713
9714 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009715 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009716 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9717 vkDestroyBuffer(m_device->device(), buffer, NULL);
9718 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9719 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9720}
9721
Tobin Ehlis845887e2017-02-02 19:01:44 -07009722TEST_F(VkLayerTest, DSBufferLimitErrors) {
9723 TEST_DESCRIPTION(
9724 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9725 "Test cases include:\n"
9726 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9727 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9728 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9729 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9730 VkResult err;
9731
9732 ASSERT_NO_FATAL_FAILURE(InitState());
9733 VkDescriptorPoolSize ds_type_count[2] = {};
9734 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9735 ds_type_count[0].descriptorCount = 1;
9736 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9737 ds_type_count[1].descriptorCount = 1;
9738
9739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9741 ds_pool_ci.pNext = NULL;
9742 ds_pool_ci.maxSets = 1;
9743 ds_pool_ci.poolSizeCount = 2;
9744 ds_pool_ci.pPoolSizes = ds_type_count;
9745
9746 VkDescriptorPool ds_pool;
9747 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9748 ASSERT_VK_SUCCESS(err);
9749
9750 // Create layout with single uniform buffer & single storage buffer descriptor
9751 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9752 dsl_binding[0].binding = 0;
9753 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9754 dsl_binding[0].descriptorCount = 1;
9755 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9756 dsl_binding[0].pImmutableSamplers = NULL;
9757 dsl_binding[1].binding = 1;
9758 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9759 dsl_binding[1].descriptorCount = 1;
9760 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9761 dsl_binding[1].pImmutableSamplers = NULL;
9762
9763 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9764 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9765 ds_layout_ci.pNext = NULL;
9766 ds_layout_ci.bindingCount = 2;
9767 ds_layout_ci.pBindings = dsl_binding;
9768 VkDescriptorSetLayout ds_layout;
9769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9770 ASSERT_VK_SUCCESS(err);
9771
9772 VkDescriptorSet descriptor_set = {};
9773 VkDescriptorSetAllocateInfo alloc_info = {};
9774 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9775 alloc_info.descriptorSetCount = 1;
9776 alloc_info.descriptorPool = ds_pool;
9777 alloc_info.pSetLayouts = &ds_layout;
9778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9779 ASSERT_VK_SUCCESS(err);
9780
9781 // Create a buffer to be used for invalid updates
9782 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9783 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9784 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9785 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9786 VkBufferCreateInfo ub_ci = {};
9787 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9788 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9789 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9790 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9791 VkBuffer uniform_buffer;
9792 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9793 ASSERT_VK_SUCCESS(err);
9794 VkBufferCreateInfo sb_ci = {};
9795 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9796 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9797 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9798 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9799 VkBuffer storage_buffer;
9800 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9801 ASSERT_VK_SUCCESS(err);
9802 // Have to bind memory to buffer before descriptor update
9803 VkMemoryAllocateInfo mem_alloc = {};
9804 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9805 mem_alloc.pNext = NULL;
9806 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9807 mem_alloc.memoryTypeIndex = 0;
9808
Cort Stratton77a0d592017-02-17 13:14:13 -08009809 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9810 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9811 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9812 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9813 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009814 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009815 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009816 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009817 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9818 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009819 return;
9820 }
9821
9822 VkDeviceMemory mem;
9823 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009824 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009825 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9827 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9828 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9829 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9830 return;
9831 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009832 ASSERT_VK_SUCCESS(err);
9833 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9834 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009835 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009836 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9837 ASSERT_VK_SUCCESS(err);
9838
9839 VkDescriptorBufferInfo buff_info = {};
9840 buff_info.buffer = uniform_buffer;
9841 buff_info.range = ub_ci.size; // This will exceed limit
9842 VkWriteDescriptorSet descriptor_write = {};
9843 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9844 descriptor_write.dstBinding = 0;
9845 descriptor_write.descriptorCount = 1;
9846 descriptor_write.pTexelBufferView = nullptr;
9847 descriptor_write.pBufferInfo = &buff_info;
9848 descriptor_write.pImageInfo = nullptr;
9849
9850 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9851 descriptor_write.dstSet = descriptor_set;
9852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9853 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9854 m_errorMonitor->VerifyFound();
9855
9856 // Reduce size of range to acceptable limit & cause offset error
9857 buff_info.range = max_ub_range;
9858 buff_info.offset = min_ub_align - 1;
9859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9861 m_errorMonitor->VerifyFound();
9862
9863 // Now break storage updates
9864 buff_info.buffer = storage_buffer;
9865 buff_info.range = sb_ci.size; // This will exceed limit
9866 buff_info.offset = 0; // Reset offset for this update
9867
9868 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9869 descriptor_write.dstBinding = 1;
9870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9871 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9872 m_errorMonitor->VerifyFound();
9873
9874 // Reduce size of range to acceptable limit & cause offset error
9875 buff_info.range = max_sb_range;
9876 buff_info.offset = min_sb_align - 1;
9877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9878 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9879 m_errorMonitor->VerifyFound();
9880
9881 vkFreeMemory(m_device->device(), mem, NULL);
9882 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9883 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9884 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9885 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9886}
9887
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009888TEST_F(VkLayerTest, DSAspectBitsErrors) {
9889 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9890 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009891 TEST_DESCRIPTION(
9892 "Attempt to update descriptor sets for images "
9893 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009894 VkResult err;
9895
9896 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07009897 auto depth_format = find_depth_stencil_format(m_device);
9898 if (!depth_format) {
9899 printf(" No Depth + Stencil format found. Skipped.\n");
9900 return;
9901 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009902 VkDescriptorPoolSize ds_type_count = {};
9903 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9904 ds_type_count.descriptorCount = 1;
9905
9906 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9907 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9908 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -07009909 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009910 ds_pool_ci.maxSets = 5;
9911 ds_pool_ci.poolSizeCount = 1;
9912 ds_pool_ci.pPoolSizes = &ds_type_count;
9913
9914 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009915 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009916 ASSERT_VK_SUCCESS(err);
9917
9918 VkDescriptorSetLayoutBinding dsl_binding = {};
9919 dsl_binding.binding = 0;
9920 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9921 dsl_binding.descriptorCount = 1;
9922 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9923 dsl_binding.pImmutableSamplers = NULL;
9924
9925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9926 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9927 ds_layout_ci.pNext = NULL;
9928 ds_layout_ci.bindingCount = 1;
9929 ds_layout_ci.pBindings = &dsl_binding;
9930 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009931 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009932 ASSERT_VK_SUCCESS(err);
9933
9934 VkDescriptorSet descriptor_set = {};
9935 VkDescriptorSetAllocateInfo alloc_info = {};
9936 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9937 alloc_info.descriptorSetCount = 1;
9938 alloc_info.descriptorPool = ds_pool;
9939 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009940 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009941 ASSERT_VK_SUCCESS(err);
9942
9943 // Create an image to be used for invalid updates
9944 VkImageCreateInfo image_ci = {};
9945 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9946 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009947 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009948 image_ci.extent.width = 64;
9949 image_ci.extent.height = 64;
9950 image_ci.extent.depth = 1;
9951 image_ci.mipLevels = 1;
9952 image_ci.arrayLayers = 1;
9953 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -07009954 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009955 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9956 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9957 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9958 VkImage image;
9959 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9960 ASSERT_VK_SUCCESS(err);
9961 // Bind memory to image
9962 VkMemoryRequirements mem_reqs;
9963 VkDeviceMemory image_mem;
9964 bool pass;
9965 VkMemoryAllocateInfo mem_alloc = {};
9966 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9967 mem_alloc.pNext = NULL;
9968 mem_alloc.allocationSize = 0;
9969 mem_alloc.memoryTypeIndex = 0;
9970 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9971 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009973 ASSERT_TRUE(pass);
9974 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9975 ASSERT_VK_SUCCESS(err);
9976 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9977 ASSERT_VK_SUCCESS(err);
9978 // Now create view for image
9979 VkImageViewCreateInfo image_view_ci = {};
9980 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9981 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -07009982 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009983 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9984 image_view_ci.subresourceRange.layerCount = 1;
9985 image_view_ci.subresourceRange.baseArrayLayer = 0;
9986 image_view_ci.subresourceRange.levelCount = 1;
9987 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009988 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009989
9990 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009991 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009992 ASSERT_VK_SUCCESS(err);
9993
9994 VkDescriptorImageInfo img_info = {};
9995 img_info.imageView = image_view;
9996 VkWriteDescriptorSet descriptor_write = {};
9997 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9998 descriptor_write.dstBinding = 0;
9999 descriptor_write.descriptorCount = 1;
10000 descriptor_write.pTexelBufferView = NULL;
10001 descriptor_write.pBufferInfo = NULL;
10002 descriptor_write.pImageInfo = &img_info;
10003 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10004 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010005 const char *error_msg =
10006 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10007 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010009
10010 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10011
10012 m_errorMonitor->VerifyFound();
10013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10014 vkDestroyImage(m_device->device(), image, NULL);
10015 vkFreeMemory(m_device->device(), image_mem, NULL);
10016 vkDestroyImageView(m_device->device(), image_view, NULL);
10017 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10018 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10019}
10020
Karl Schultz6addd812016-02-02 17:17:23 -070010021TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010022 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010023 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10026 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10027 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010028
Tobin Ehlis3b780662015-05-28 12:11:26 -060010029 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010030 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010031 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010032 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10033 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010034
10035 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010036 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10037 ds_pool_ci.pNext = NULL;
10038 ds_pool_ci.maxSets = 1;
10039 ds_pool_ci.poolSizeCount = 1;
10040 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010041
Tobin Ehlis3b780662015-05-28 12:11:26 -060010042 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010043 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010044 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010045 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010046 dsl_binding.binding = 0;
10047 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10048 dsl_binding.descriptorCount = 1;
10049 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10050 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010051
Tony Barboureb254902015-07-15 12:50:33 -060010052 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010053 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10054 ds_layout_ci.pNext = NULL;
10055 ds_layout_ci.bindingCount = 1;
10056 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010057
Tobin Ehlis3b780662015-05-28 12:11:26 -060010058 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010059 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010060 ASSERT_VK_SUCCESS(err);
10061
10062 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010063 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010064 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010065 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010066 alloc_info.descriptorPool = ds_pool;
10067 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010069 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010070
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010071 VkSamplerCreateInfo sampler_ci = {};
10072 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10073 sampler_ci.pNext = NULL;
10074 sampler_ci.magFilter = VK_FILTER_NEAREST;
10075 sampler_ci.minFilter = VK_FILTER_NEAREST;
10076 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10077 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10078 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10079 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10080 sampler_ci.mipLodBias = 1.0;
10081 sampler_ci.anisotropyEnable = VK_FALSE;
10082 sampler_ci.maxAnisotropy = 1;
10083 sampler_ci.compareEnable = VK_FALSE;
10084 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10085 sampler_ci.minLod = 1.0;
10086 sampler_ci.maxLod = 1.0;
10087 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10088 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10089 VkSampler sampler;
10090 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10091 ASSERT_VK_SUCCESS(err);
10092
10093 VkDescriptorImageInfo info = {};
10094 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010095
10096 VkWriteDescriptorSet descriptor_write;
10097 memset(&descriptor_write, 0, sizeof(descriptor_write));
10098 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010099 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010100 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010101 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010102 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010103 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010104
10105 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10106
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010107 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010108
Chia-I Wuf7458c52015-10-26 21:10:41 +080010109 vkDestroySampler(m_device->device(), sampler, NULL);
10110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10111 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010112}
10113
Karl Schultz6addd812016-02-02 17:17:23 -070010114TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010115 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010116 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010117
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010119
Tobin Ehlis3b780662015-05-28 12:11:26 -060010120 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010121 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010122 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010123 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10124 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010125
10126 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010127 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10128 ds_pool_ci.pNext = NULL;
10129 ds_pool_ci.maxSets = 1;
10130 ds_pool_ci.poolSizeCount = 1;
10131 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010132
Tobin Ehlis3b780662015-05-28 12:11:26 -060010133 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010135 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010136
Tony Barboureb254902015-07-15 12:50:33 -060010137 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010138 dsl_binding.binding = 0;
10139 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10140 dsl_binding.descriptorCount = 1;
10141 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10142 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010143
10144 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010145 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10146 ds_layout_ci.pNext = NULL;
10147 ds_layout_ci.bindingCount = 1;
10148 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010149
Tobin Ehlis3b780662015-05-28 12:11:26 -060010150 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010151 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010152 ASSERT_VK_SUCCESS(err);
10153
10154 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010155 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010156 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010157 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010158 alloc_info.descriptorPool = ds_pool;
10159 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010160 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010161 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010162
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010163 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10164
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010165 // Correctly update descriptor to avoid "NOT_UPDATED" error
10166 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010167 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010168 buff_info.offset = 0;
10169 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010170
10171 VkWriteDescriptorSet descriptor_write;
10172 memset(&descriptor_write, 0, sizeof(descriptor_write));
10173 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010174 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010175 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010176 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010177 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10178 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010179
10180 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10181
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010182 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010183
Chia-I Wuf7458c52015-10-26 21:10:41 +080010184 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010186}
10187
Karl Schultz6addd812016-02-02 17:17:23 -070010188TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010189 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010190 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010191
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010193
Tobin Ehlis3b780662015-05-28 12:11:26 -060010194 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010195 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010196 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010197 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10198 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010199
10200 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010201 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10202 ds_pool_ci.pNext = NULL;
10203 ds_pool_ci.maxSets = 1;
10204 ds_pool_ci.poolSizeCount = 1;
10205 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010206
Tobin Ehlis3b780662015-05-28 12:11:26 -060010207 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010209 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010210
Tony Barboureb254902015-07-15 12:50:33 -060010211 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010212 dsl_binding.binding = 0;
10213 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10214 dsl_binding.descriptorCount = 1;
10215 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10216 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010217
10218 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010219 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10220 ds_layout_ci.pNext = NULL;
10221 ds_layout_ci.bindingCount = 1;
10222 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010223 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010224 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010225 ASSERT_VK_SUCCESS(err);
10226
10227 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010228 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010229 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010230 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010231 alloc_info.descriptorPool = ds_pool;
10232 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010233 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010234 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010235
Tony Barboureb254902015-07-15 12:50:33 -060010236 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010237 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10238 sampler_ci.pNext = NULL;
10239 sampler_ci.magFilter = VK_FILTER_NEAREST;
10240 sampler_ci.minFilter = VK_FILTER_NEAREST;
10241 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10242 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10243 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10244 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10245 sampler_ci.mipLodBias = 1.0;
10246 sampler_ci.anisotropyEnable = VK_FALSE;
10247 sampler_ci.maxAnisotropy = 1;
10248 sampler_ci.compareEnable = VK_FALSE;
10249 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10250 sampler_ci.minLod = 1.0;
10251 sampler_ci.maxLod = 1.0;
10252 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10253 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010254
Tobin Ehlis3b780662015-05-28 12:11:26 -060010255 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010256 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010257 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010258
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010259 VkDescriptorImageInfo info = {};
10260 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010261
10262 VkWriteDescriptorSet descriptor_write;
10263 memset(&descriptor_write, 0, sizeof(descriptor_write));
10264 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010265 descriptor_write.dstSet = descriptorSet;
10266 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010267 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010268 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010269 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010270 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010271
10272 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10273
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010274 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010275
Chia-I Wuf7458c52015-10-26 21:10:41 +080010276 vkDestroySampler(m_device->device(), sampler, NULL);
10277 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10278 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010279}
10280
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010281TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10282 // Create layout w/ empty binding and attempt to update it
10283 VkResult err;
10284
10285 ASSERT_NO_FATAL_FAILURE(InitState());
10286
10287 VkDescriptorPoolSize ds_type_count = {};
10288 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10289 ds_type_count.descriptorCount = 1;
10290
10291 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10292 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10293 ds_pool_ci.pNext = NULL;
10294 ds_pool_ci.maxSets = 1;
10295 ds_pool_ci.poolSizeCount = 1;
10296 ds_pool_ci.pPoolSizes = &ds_type_count;
10297
10298 VkDescriptorPool ds_pool;
10299 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10300 ASSERT_VK_SUCCESS(err);
10301
10302 VkDescriptorSetLayoutBinding dsl_binding = {};
10303 dsl_binding.binding = 0;
10304 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10305 dsl_binding.descriptorCount = 0;
10306 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10307 dsl_binding.pImmutableSamplers = NULL;
10308
10309 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10310 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10311 ds_layout_ci.pNext = NULL;
10312 ds_layout_ci.bindingCount = 1;
10313 ds_layout_ci.pBindings = &dsl_binding;
10314 VkDescriptorSetLayout ds_layout;
10315 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10316 ASSERT_VK_SUCCESS(err);
10317
10318 VkDescriptorSet descriptor_set;
10319 VkDescriptorSetAllocateInfo alloc_info = {};
10320 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10321 alloc_info.descriptorSetCount = 1;
10322 alloc_info.descriptorPool = ds_pool;
10323 alloc_info.pSetLayouts = &ds_layout;
10324 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10325 ASSERT_VK_SUCCESS(err);
10326
10327 VkSamplerCreateInfo sampler_ci = {};
10328 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10329 sampler_ci.magFilter = VK_FILTER_NEAREST;
10330 sampler_ci.minFilter = VK_FILTER_NEAREST;
10331 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10332 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10333 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10334 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10335 sampler_ci.mipLodBias = 1.0;
10336 sampler_ci.maxAnisotropy = 1;
10337 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10338 sampler_ci.minLod = 1.0;
10339 sampler_ci.maxLod = 1.0;
10340 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10341
10342 VkSampler sampler;
10343 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10344 ASSERT_VK_SUCCESS(err);
10345
10346 VkDescriptorImageInfo info = {};
10347 info.sampler = sampler;
10348
10349 VkWriteDescriptorSet descriptor_write;
10350 memset(&descriptor_write, 0, sizeof(descriptor_write));
10351 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10352 descriptor_write.dstSet = descriptor_set;
10353 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010354 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010355 // This is the wrong type, but empty binding error will be flagged first
10356 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10357 descriptor_write.pImageInfo = &info;
10358
10359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10360 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10361 m_errorMonitor->VerifyFound();
10362
10363 vkDestroySampler(m_device->device(), sampler, NULL);
10364 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10365 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10366}
10367
Karl Schultz6addd812016-02-02 17:17:23 -070010368TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10369 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10370 // types
10371 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010373 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 -060010374
Tobin Ehlis3b780662015-05-28 12:11:26 -060010375 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010376
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010377 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010378 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10379 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010380
10381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10383 ds_pool_ci.pNext = NULL;
10384 ds_pool_ci.maxSets = 1;
10385 ds_pool_ci.poolSizeCount = 1;
10386 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010387
Tobin Ehlis3b780662015-05-28 12:11:26 -060010388 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010389 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010390 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010391 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010392 dsl_binding.binding = 0;
10393 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10394 dsl_binding.descriptorCount = 1;
10395 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10396 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010397
Tony Barboureb254902015-07-15 12:50:33 -060010398 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010399 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10400 ds_layout_ci.pNext = NULL;
10401 ds_layout_ci.bindingCount = 1;
10402 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010403
Tobin Ehlis3b780662015-05-28 12:11:26 -060010404 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010406 ASSERT_VK_SUCCESS(err);
10407
10408 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010409 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010410 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010411 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010412 alloc_info.descriptorPool = ds_pool;
10413 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010414 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010415 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010416
Tony Barboureb254902015-07-15 12:50:33 -060010417 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010418 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10419 sampler_ci.pNext = NULL;
10420 sampler_ci.magFilter = VK_FILTER_NEAREST;
10421 sampler_ci.minFilter = VK_FILTER_NEAREST;
10422 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10423 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10424 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10425 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10426 sampler_ci.mipLodBias = 1.0;
10427 sampler_ci.anisotropyEnable = VK_FALSE;
10428 sampler_ci.maxAnisotropy = 1;
10429 sampler_ci.compareEnable = VK_FALSE;
10430 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10431 sampler_ci.minLod = 1.0;
10432 sampler_ci.maxLod = 1.0;
10433 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10434 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010435 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010436 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010437 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010438
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010439 VkDescriptorImageInfo info = {};
10440 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010441
10442 VkWriteDescriptorSet descriptor_write;
10443 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010444 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010445 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010446 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010447 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010448 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010449 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010450
10451 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10452
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010453 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010454
Chia-I Wuf7458c52015-10-26 21:10:41 +080010455 vkDestroySampler(m_device->device(), sampler, NULL);
10456 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10457 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010458}
10459
Karl Schultz6addd812016-02-02 17:17:23 -070010460TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010461 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010462 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010463
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010465
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010466 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010467 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10468 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010469 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010470 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10471 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010472
10473 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010474 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10475 ds_pool_ci.pNext = NULL;
10476 ds_pool_ci.maxSets = 1;
10477 ds_pool_ci.poolSizeCount = 1;
10478 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010479
10480 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010481 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010482 ASSERT_VK_SUCCESS(err);
10483
10484 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010485 dsl_binding.binding = 0;
10486 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10487 dsl_binding.descriptorCount = 1;
10488 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10489 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010490
10491 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010492 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10493 ds_layout_ci.pNext = NULL;
10494 ds_layout_ci.bindingCount = 1;
10495 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010496 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010497 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010498 ASSERT_VK_SUCCESS(err);
10499
10500 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010501 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010502 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010503 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010504 alloc_info.descriptorPool = ds_pool;
10505 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010506 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010507 ASSERT_VK_SUCCESS(err);
10508
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010509 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010510
10511 VkDescriptorImageInfo descriptor_info;
10512 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10513 descriptor_info.sampler = sampler;
10514
10515 VkWriteDescriptorSet descriptor_write;
10516 memset(&descriptor_write, 0, sizeof(descriptor_write));
10517 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010518 descriptor_write.dstSet = descriptorSet;
10519 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010520 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010521 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10522 descriptor_write.pImageInfo = &descriptor_info;
10523
10524 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10525
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010526 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010527
Chia-I Wuf7458c52015-10-26 21:10:41 +080010528 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10529 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010530}
10531
Karl Schultz6addd812016-02-02 17:17:23 -070010532TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10533 // Create a single combined Image/Sampler descriptor and send it an invalid
10534 // imageView
10535 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010536
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010538
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010539 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010540 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010541 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10542 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010543
10544 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010545 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10546 ds_pool_ci.pNext = NULL;
10547 ds_pool_ci.maxSets = 1;
10548 ds_pool_ci.poolSizeCount = 1;
10549 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010550
10551 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010552 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010553 ASSERT_VK_SUCCESS(err);
10554
10555 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010556 dsl_binding.binding = 0;
10557 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10558 dsl_binding.descriptorCount = 1;
10559 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10560 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010561
10562 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010563 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10564 ds_layout_ci.pNext = NULL;
10565 ds_layout_ci.bindingCount = 1;
10566 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010567 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010568 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010569 ASSERT_VK_SUCCESS(err);
10570
10571 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010572 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010573 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010574 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010575 alloc_info.descriptorPool = ds_pool;
10576 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010577 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010578 ASSERT_VK_SUCCESS(err);
10579
10580 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010581 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10582 sampler_ci.pNext = NULL;
10583 sampler_ci.magFilter = VK_FILTER_NEAREST;
10584 sampler_ci.minFilter = VK_FILTER_NEAREST;
10585 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10586 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10587 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10588 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10589 sampler_ci.mipLodBias = 1.0;
10590 sampler_ci.anisotropyEnable = VK_FALSE;
10591 sampler_ci.maxAnisotropy = 1;
10592 sampler_ci.compareEnable = VK_FALSE;
10593 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10594 sampler_ci.minLod = 1.0;
10595 sampler_ci.maxLod = 1.0;
10596 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10597 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010598
10599 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010600 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010601 ASSERT_VK_SUCCESS(err);
10602
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010603 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010604
10605 VkDescriptorImageInfo descriptor_info;
10606 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10607 descriptor_info.sampler = sampler;
10608 descriptor_info.imageView = view;
10609
10610 VkWriteDescriptorSet descriptor_write;
10611 memset(&descriptor_write, 0, sizeof(descriptor_write));
10612 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010613 descriptor_write.dstSet = descriptorSet;
10614 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010615 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010616 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10617 descriptor_write.pImageInfo = &descriptor_info;
10618
10619 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10620
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010621 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010622
Chia-I Wuf7458c52015-10-26 21:10:41 +080010623 vkDestroySampler(m_device->device(), sampler, NULL);
10624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010626}
10627
Karl Schultz6addd812016-02-02 17:17:23 -070010628TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10629 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10630 // into the other
10631 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010632
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10634 " binding #1 with type "
10635 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10636 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010637
Tobin Ehlis04356f92015-10-27 16:35:27 -060010638 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010639 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010640 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010641 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10642 ds_type_count[0].descriptorCount = 1;
10643 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10644 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010645
10646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10648 ds_pool_ci.pNext = NULL;
10649 ds_pool_ci.maxSets = 1;
10650 ds_pool_ci.poolSizeCount = 2;
10651 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010652
10653 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010654 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010655 ASSERT_VK_SUCCESS(err);
10656 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010657 dsl_binding[0].binding = 0;
10658 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10659 dsl_binding[0].descriptorCount = 1;
10660 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10661 dsl_binding[0].pImmutableSamplers = NULL;
10662 dsl_binding[1].binding = 1;
10663 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10664 dsl_binding[1].descriptorCount = 1;
10665 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10666 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010667
10668 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010669 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10670 ds_layout_ci.pNext = NULL;
10671 ds_layout_ci.bindingCount = 2;
10672 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010673
10674 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010675 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010676 ASSERT_VK_SUCCESS(err);
10677
10678 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010679 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010680 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010681 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010682 alloc_info.descriptorPool = ds_pool;
10683 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010684 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010685 ASSERT_VK_SUCCESS(err);
10686
10687 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010688 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10689 sampler_ci.pNext = NULL;
10690 sampler_ci.magFilter = VK_FILTER_NEAREST;
10691 sampler_ci.minFilter = VK_FILTER_NEAREST;
10692 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10693 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10694 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10695 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10696 sampler_ci.mipLodBias = 1.0;
10697 sampler_ci.anisotropyEnable = VK_FALSE;
10698 sampler_ci.maxAnisotropy = 1;
10699 sampler_ci.compareEnable = VK_FALSE;
10700 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10701 sampler_ci.minLod = 1.0;
10702 sampler_ci.maxLod = 1.0;
10703 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10704 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010705
10706 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010707 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010708 ASSERT_VK_SUCCESS(err);
10709
10710 VkDescriptorImageInfo info = {};
10711 info.sampler = sampler;
10712
10713 VkWriteDescriptorSet descriptor_write;
10714 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10715 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010716 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010717 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010718 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010719 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10720 descriptor_write.pImageInfo = &info;
10721 // This write update should succeed
10722 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10723 // Now perform a copy update that fails due to type mismatch
10724 VkCopyDescriptorSet copy_ds_update;
10725 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10726 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10727 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010728 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010729 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010730 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10731 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010732 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10733
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010734 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010735 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010736 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 -060010737 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10738 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10739 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010740 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010741 copy_ds_update.dstSet = descriptorSet;
10742 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010743 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010744 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10745
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010746 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010747
Tobin Ehlis04356f92015-10-27 16:35:27 -060010748 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10750 " binding#1 with offset index of 1 plus "
10751 "update array offset of 0 and update of "
10752 "5 descriptors oversteps total number "
10753 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010754
Tobin Ehlis04356f92015-10-27 16:35:27 -060010755 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10756 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10757 copy_ds_update.srcSet = descriptorSet;
10758 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010759 copy_ds_update.dstSet = descriptorSet;
10760 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010761 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010762 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10763
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010764 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010765
Chia-I Wuf7458c52015-10-26 21:10:41 +080010766 vkDestroySampler(m_device->device(), sampler, NULL);
10767 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10768 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010769}
10770
Karl Schultz6addd812016-02-02 17:17:23 -070010771TEST_F(VkLayerTest, NumSamplesMismatch) {
10772 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10773 // sampleCount
10774 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010777
Tobin Ehlis3b780662015-05-28 12:11:26 -060010778 ASSERT_NO_FATAL_FAILURE(InitState());
10779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010780 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010781 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010782 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010783
10784 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010785 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10786 ds_pool_ci.pNext = NULL;
10787 ds_pool_ci.maxSets = 1;
10788 ds_pool_ci.poolSizeCount = 1;
10789 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010790
Tobin Ehlis3b780662015-05-28 12:11:26 -060010791 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010792 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010793 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010794
Tony Barboureb254902015-07-15 12:50:33 -060010795 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010796 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010797 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010798 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010799 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10800 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010801
Tony Barboureb254902015-07-15 12:50:33 -060010802 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10803 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10804 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010805 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010806 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010807
Tobin Ehlis3b780662015-05-28 12:11:26 -060010808 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010809 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010810 ASSERT_VK_SUCCESS(err);
10811
10812 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010813 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010814 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010815 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010816 alloc_info.descriptorPool = ds_pool;
10817 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010818 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010819 ASSERT_VK_SUCCESS(err);
10820
Tony Barboureb254902015-07-15 12:50:33 -060010821 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010822 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010823 pipe_ms_state_ci.pNext = NULL;
10824 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10825 pipe_ms_state_ci.sampleShadingEnable = 0;
10826 pipe_ms_state_ci.minSampleShading = 1.0;
10827 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010828
Tony Barboureb254902015-07-15 12:50:33 -060010829 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010830 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10831 pipeline_layout_ci.pNext = NULL;
10832 pipeline_layout_ci.setLayoutCount = 1;
10833 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010834
10835 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010836 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010837 ASSERT_VK_SUCCESS(err);
10838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010839 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010840 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 -060010841 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010842 VkPipelineObj pipe(m_device);
10843 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010844 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010845 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010846 pipe.SetMSAA(&pipe_ms_state_ci);
10847 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010848
Tony Barbour552f6c02016-12-21 14:34:07 -070010849 m_commandBuffer->BeginCommandBuffer();
10850 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010851 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010852
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010853 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10854 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10855 VkRect2D scissor = {{0, 0}, {16, 16}};
10856 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10857
Mark Young29927482016-05-04 14:38:51 -060010858 // Render triangle (the error should trigger on the attempt to draw).
10859 Draw(3, 1, 0, 0);
10860
10861 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010862 m_commandBuffer->EndRenderPass();
10863 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010864
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010865 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010866
Chia-I Wuf7458c52015-10-26 21:10:41 +080010867 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10868 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10869 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010870}
Mark Young29927482016-05-04 14:38:51 -060010871
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010872TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010873 TEST_DESCRIPTION(
10874 "Hit RenderPass incompatible cases. "
10875 "Initial case is drawing with an active renderpass that's "
10876 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010877 VkResult err;
10878
10879 ASSERT_NO_FATAL_FAILURE(InitState());
10880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10881
10882 VkDescriptorSetLayoutBinding dsl_binding = {};
10883 dsl_binding.binding = 0;
10884 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10885 dsl_binding.descriptorCount = 1;
10886 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10887 dsl_binding.pImmutableSamplers = NULL;
10888
10889 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10890 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10891 ds_layout_ci.pNext = NULL;
10892 ds_layout_ci.bindingCount = 1;
10893 ds_layout_ci.pBindings = &dsl_binding;
10894
10895 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010896 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010897 ASSERT_VK_SUCCESS(err);
10898
10899 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10900 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10901 pipeline_layout_ci.pNext = NULL;
10902 pipeline_layout_ci.setLayoutCount = 1;
10903 pipeline_layout_ci.pSetLayouts = &ds_layout;
10904
10905 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010906 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010907 ASSERT_VK_SUCCESS(err);
10908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010909 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010910 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 -060010911 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010912 // Create a renderpass that will be incompatible with default renderpass
10913 VkAttachmentReference attach = {};
10914 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10915 VkAttachmentReference color_att = {};
10916 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10917 VkSubpassDescription subpass = {};
10918 subpass.inputAttachmentCount = 1;
10919 subpass.pInputAttachments = &attach;
10920 subpass.colorAttachmentCount = 1;
10921 subpass.pColorAttachments = &color_att;
10922 VkRenderPassCreateInfo rpci = {};
10923 rpci.subpassCount = 1;
10924 rpci.pSubpasses = &subpass;
10925 rpci.attachmentCount = 1;
10926 VkAttachmentDescription attach_desc = {};
10927 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010928 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10929 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010930 rpci.pAttachments = &attach_desc;
10931 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10932 VkRenderPass rp;
10933 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10934 VkPipelineObj pipe(m_device);
10935 pipe.AddShader(&vs);
10936 pipe.AddShader(&fs);
10937 pipe.AddColorAttachment();
10938 VkViewport view_port = {};
10939 m_viewports.push_back(view_port);
10940 pipe.SetViewport(m_viewports);
10941 VkRect2D rect = {};
10942 m_scissors.push_back(rect);
10943 pipe.SetScissor(m_scissors);
10944 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10945
10946 VkCommandBufferInheritanceInfo cbii = {};
10947 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10948 cbii.renderPass = rp;
10949 cbii.subpass = 0;
10950 VkCommandBufferBeginInfo cbbi = {};
10951 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10952 cbbi.pInheritanceInfo = &cbii;
10953 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10954 VkRenderPassBeginInfo rpbi = {};
10955 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10956 rpbi.framebuffer = m_framebuffer;
10957 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010958 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10959 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010962 // Render triangle (the error should trigger on the attempt to draw).
10963 Draw(3, 1, 0, 0);
10964
10965 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010966 m_commandBuffer->EndRenderPass();
10967 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010968
10969 m_errorMonitor->VerifyFound();
10970
10971 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10973 vkDestroyRenderPass(m_device->device(), rp, NULL);
10974}
10975
Mark Youngc89c6312016-03-31 16:03:20 -060010976TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10977 // Create Pipeline where the number of blend attachments doesn't match the
10978 // number of color attachments. In this case, we don't add any color
10979 // blend attachments even though we have a color attachment.
10980 VkResult err;
10981
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010983
10984 ASSERT_NO_FATAL_FAILURE(InitState());
10985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10986 VkDescriptorPoolSize ds_type_count = {};
10987 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10988 ds_type_count.descriptorCount = 1;
10989
10990 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10991 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10992 ds_pool_ci.pNext = NULL;
10993 ds_pool_ci.maxSets = 1;
10994 ds_pool_ci.poolSizeCount = 1;
10995 ds_pool_ci.pPoolSizes = &ds_type_count;
10996
10997 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010998 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010999 ASSERT_VK_SUCCESS(err);
11000
11001 VkDescriptorSetLayoutBinding dsl_binding = {};
11002 dsl_binding.binding = 0;
11003 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11004 dsl_binding.descriptorCount = 1;
11005 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11006 dsl_binding.pImmutableSamplers = NULL;
11007
11008 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11009 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11010 ds_layout_ci.pNext = NULL;
11011 ds_layout_ci.bindingCount = 1;
11012 ds_layout_ci.pBindings = &dsl_binding;
11013
11014 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011015 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011016 ASSERT_VK_SUCCESS(err);
11017
11018 VkDescriptorSet descriptorSet;
11019 VkDescriptorSetAllocateInfo alloc_info = {};
11020 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11021 alloc_info.descriptorSetCount = 1;
11022 alloc_info.descriptorPool = ds_pool;
11023 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011024 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011025 ASSERT_VK_SUCCESS(err);
11026
11027 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011028 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011029 pipe_ms_state_ci.pNext = NULL;
11030 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11031 pipe_ms_state_ci.sampleShadingEnable = 0;
11032 pipe_ms_state_ci.minSampleShading = 1.0;
11033 pipe_ms_state_ci.pSampleMask = NULL;
11034
11035 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11036 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11037 pipeline_layout_ci.pNext = NULL;
11038 pipeline_layout_ci.setLayoutCount = 1;
11039 pipeline_layout_ci.pSetLayouts = &ds_layout;
11040
11041 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011042 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011043 ASSERT_VK_SUCCESS(err);
11044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011045 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011046 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 -060011047 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011048 VkPipelineObj pipe(m_device);
11049 pipe.AddShader(&vs);
11050 pipe.AddShader(&fs);
11051 pipe.SetMSAA(&pipe_ms_state_ci);
11052 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011053 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011054
11055 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11056 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11057 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11058}
Mark Young29927482016-05-04 14:38:51 -060011059
Mark Muellerd4914412016-06-13 17:52:06 -060011060TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011061 TEST_DESCRIPTION(
11062 "Points to a wrong colorAttachment index in a VkClearAttachment "
11063 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011064 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011066
11067 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11068 m_errorMonitor->VerifyFound();
11069}
11070
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011071TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011072 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11073 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011074
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011075 ASSERT_NO_FATAL_FAILURE(InitState());
11076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011077
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011078 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011079 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11080 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011081
11082 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011083 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11084 ds_pool_ci.pNext = NULL;
11085 ds_pool_ci.maxSets = 1;
11086 ds_pool_ci.poolSizeCount = 1;
11087 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011088
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011089 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011090 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011091 ASSERT_VK_SUCCESS(err);
11092
Tony Barboureb254902015-07-15 12:50:33 -060011093 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011094 dsl_binding.binding = 0;
11095 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11096 dsl_binding.descriptorCount = 1;
11097 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11098 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011099
Tony Barboureb254902015-07-15 12:50:33 -060011100 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011101 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11102 ds_layout_ci.pNext = NULL;
11103 ds_layout_ci.bindingCount = 1;
11104 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011105
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011106 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011107 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011108 ASSERT_VK_SUCCESS(err);
11109
11110 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011111 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011112 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011113 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011114 alloc_info.descriptorPool = ds_pool;
11115 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011116 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011117 ASSERT_VK_SUCCESS(err);
11118
Tony Barboureb254902015-07-15 12:50:33 -060011119 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011120 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011121 pipe_ms_state_ci.pNext = NULL;
11122 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11123 pipe_ms_state_ci.sampleShadingEnable = 0;
11124 pipe_ms_state_ci.minSampleShading = 1.0;
11125 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011126
Tony Barboureb254902015-07-15 12:50:33 -060011127 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011128 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11129 pipeline_layout_ci.pNext = NULL;
11130 pipeline_layout_ci.setLayoutCount = 1;
11131 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011132
11133 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011134 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011135 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011137 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011138 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011139 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011140 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011141
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011142 VkPipelineObj pipe(m_device);
11143 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011144 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011145 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011146 pipe.SetMSAA(&pipe_ms_state_ci);
11147 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011148
Tony Barbour552f6c02016-12-21 14:34:07 -070011149 m_commandBuffer->BeginCommandBuffer();
11150 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011151
Karl Schultz6addd812016-02-02 17:17:23 -070011152 // Main thing we care about for this test is that the VkImage obj we're
11153 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011154 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011155 VkClearAttachment color_attachment;
11156 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11157 color_attachment.clearValue.color.float32[0] = 1.0;
11158 color_attachment.clearValue.color.float32[1] = 1.0;
11159 color_attachment.clearValue.color.float32[2] = 1.0;
11160 color_attachment.clearValue.color.float32[3] = 1.0;
11161 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011162 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011163
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011164 // Call for full-sized FB Color attachment prior to issuing a Draw
11165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011166 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011167 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011168 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011169
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011170 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11171 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11173 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11174 m_errorMonitor->VerifyFound();
11175
11176 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11177 clear_rect.layerCount = 2;
11178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11179 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011180 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011181
Chia-I Wuf7458c52015-10-26 21:10:41 +080011182 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11183 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11184 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011185}
11186
Karl Schultz6addd812016-02-02 17:17:23 -070011187TEST_F(VkLayerTest, VtxBufferBadIndex) {
11188 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11191 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011192
Tobin Ehlis502480b2015-06-24 15:53:07 -060011193 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011194 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011196
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011197 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011198 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11199 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011200
11201 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011202 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11203 ds_pool_ci.pNext = NULL;
11204 ds_pool_ci.maxSets = 1;
11205 ds_pool_ci.poolSizeCount = 1;
11206 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011207
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011208 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011209 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011210 ASSERT_VK_SUCCESS(err);
11211
Tony Barboureb254902015-07-15 12:50:33 -060011212 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011213 dsl_binding.binding = 0;
11214 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11215 dsl_binding.descriptorCount = 1;
11216 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11217 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011218
Tony Barboureb254902015-07-15 12:50:33 -060011219 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011220 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11221 ds_layout_ci.pNext = NULL;
11222 ds_layout_ci.bindingCount = 1;
11223 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011224
Tobin Ehlis502480b2015-06-24 15:53:07 -060011225 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011226 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011227 ASSERT_VK_SUCCESS(err);
11228
11229 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011230 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011231 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011232 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011233 alloc_info.descriptorPool = ds_pool;
11234 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011235 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011236 ASSERT_VK_SUCCESS(err);
11237
Tony Barboureb254902015-07-15 12:50:33 -060011238 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011240 pipe_ms_state_ci.pNext = NULL;
11241 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11242 pipe_ms_state_ci.sampleShadingEnable = 0;
11243 pipe_ms_state_ci.minSampleShading = 1.0;
11244 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011245
Tony Barboureb254902015-07-15 12:50:33 -060011246 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011247 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11248 pipeline_layout_ci.pNext = NULL;
11249 pipeline_layout_ci.setLayoutCount = 1;
11250 pipeline_layout_ci.pSetLayouts = &ds_layout;
11251 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011253 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011254 ASSERT_VK_SUCCESS(err);
11255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011256 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011257 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 -060011258 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011259 VkPipelineObj pipe(m_device);
11260 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011261 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011262 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011263 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011264 pipe.SetViewport(m_viewports);
11265 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011266 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011267
Tony Barbour552f6c02016-12-21 14:34:07 -070011268 m_commandBuffer->BeginCommandBuffer();
11269 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011270 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011271 // Don't care about actual data, just need to get to draw to flag error
11272 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011273 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011274 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011275 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011276
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011277 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011278
Chia-I Wuf7458c52015-10-26 21:10:41 +080011279 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11280 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11281 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011282}
Mark Muellerdfe37552016-07-07 14:47:42 -060011283
Mark Mueller2ee294f2016-08-04 12:59:48 -060011284TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011285 TEST_DESCRIPTION(
11286 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11287 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011288 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011289
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011290 const char *invalid_queueFamilyIndex_message =
11291 "Invalid queue create request in vkCreateDevice(). Invalid "
11292 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011294 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011295
Mark Mueller880fce52016-08-17 15:23:23 -060011296 // The following test fails with recent NVidia drivers.
11297 // By the time core_validation is reached, the NVidia
11298 // driver has sanitized the invalid condition and core_validation
11299 // is not introduced to the failure condition. This is not the case
11300 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011301 // uint32_t count = static_cast<uint32_t>(~0);
11302 // VkPhysicalDevice physical_device;
11303 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11304 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011307 float queue_priority = 0.0;
11308
11309 VkDeviceQueueCreateInfo queue_create_info = {};
11310 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11311 queue_create_info.queueCount = 1;
11312 queue_create_info.pQueuePriorities = &queue_priority;
11313 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11314
11315 VkPhysicalDeviceFeatures features = m_device->phy().features();
11316 VkDevice testDevice;
11317 VkDeviceCreateInfo device_create_info = {};
11318 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11319 device_create_info.queueCreateInfoCount = 1;
11320 device_create_info.pQueueCreateInfos = &queue_create_info;
11321 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011322 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011323 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11324 m_errorMonitor->VerifyFound();
11325
11326 queue_create_info.queueFamilyIndex = 1;
11327
11328 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11329 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11330 for (unsigned i = 0; i < feature_count; i++) {
11331 if (VK_FALSE == feature_array[i]) {
11332 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011334 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011335 m_errorMonitor->SetUnexpectedError(
11336 "You requested features that are unavailable on this device. You should first query feature availability by "
11337 "calling vkGetPhysicalDeviceFeatures().");
11338 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011339 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11340 m_errorMonitor->VerifyFound();
11341 break;
11342 }
11343 }
11344}
11345
Tobin Ehlis16edf082016-11-21 12:33:49 -070011346TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11347 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11348
11349 ASSERT_NO_FATAL_FAILURE(InitState());
11350
11351 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11352 std::vector<VkDeviceQueueCreateInfo> queue_info;
11353 queue_info.reserve(queue_props.size());
11354 std::vector<std::vector<float>> queue_priorities;
11355 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11356 VkDeviceQueueCreateInfo qi{};
11357 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11358 qi.queueFamilyIndex = i;
11359 qi.queueCount = queue_props[i].queueCount;
11360 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11361 qi.pQueuePriorities = queue_priorities[i].data();
11362 queue_info.push_back(qi);
11363 }
11364
11365 std::vector<const char *> device_extension_names;
11366
11367 VkDevice local_device;
11368 VkDeviceCreateInfo device_create_info = {};
11369 auto features = m_device->phy().features();
11370 // Intentionally disable pipeline stats
11371 features.pipelineStatisticsQuery = VK_FALSE;
11372 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11373 device_create_info.pNext = NULL;
11374 device_create_info.queueCreateInfoCount = queue_info.size();
11375 device_create_info.pQueueCreateInfos = queue_info.data();
11376 device_create_info.enabledLayerCount = 0;
11377 device_create_info.ppEnabledLayerNames = NULL;
11378 device_create_info.pEnabledFeatures = &features;
11379 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11380 ASSERT_VK_SUCCESS(err);
11381
11382 VkQueryPoolCreateInfo qpci{};
11383 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11384 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11385 qpci.queryCount = 1;
11386 VkQueryPool query_pool;
11387
11388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11389 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11390 m_errorMonitor->VerifyFound();
11391
11392 vkDestroyDevice(local_device, nullptr);
11393}
11394
Mark Mueller2ee294f2016-08-04 12:59:48 -060011395TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011396 TEST_DESCRIPTION(
11397 "Use an invalid queue index in a vkCmdWaitEvents call."
11398 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011399
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011400 const char *invalid_queue_index =
11401 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11402 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11403 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011405 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011406
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011408
11409 ASSERT_NO_FATAL_FAILURE(InitState());
11410
11411 VkEvent event;
11412 VkEventCreateInfo event_create_info{};
11413 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11414 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11415
Mark Mueller2ee294f2016-08-04 12:59:48 -060011416 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011417 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011418
Tony Barbour552f6c02016-12-21 14:34:07 -070011419 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011420
11421 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011422 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 -060011423 ASSERT_TRUE(image.initialized());
11424 VkImageMemoryBarrier img_barrier = {};
11425 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11426 img_barrier.pNext = NULL;
11427 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11428 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11429 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11430 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11431 img_barrier.image = image.handle();
11432 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011433
11434 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11435 // that layer validation catches the case when it is not.
11436 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011437 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11438 img_barrier.subresourceRange.baseArrayLayer = 0;
11439 img_barrier.subresourceRange.baseMipLevel = 0;
11440 img_barrier.subresourceRange.layerCount = 1;
11441 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011442 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11443 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011444 m_errorMonitor->VerifyFound();
11445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011447
11448 VkQueryPool query_pool;
11449 VkQueryPoolCreateInfo query_pool_create_info = {};
11450 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11451 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11452 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011453 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011454
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011455 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011456 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11457
11458 vkEndCommandBuffer(m_commandBuffer->handle());
11459 m_errorMonitor->VerifyFound();
11460
11461 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11462 vkDestroyEvent(m_device->device(), event, nullptr);
11463}
11464
Mark Muellerdfe37552016-07-07 14:47:42 -060011465TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011466 TEST_DESCRIPTION(
11467 "Submit a command buffer using deleted vertex buffer, "
11468 "delete a buffer twice, use an invalid offset for each "
11469 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011471 const char *deleted_buffer_in_command_buffer =
11472 "Cannot submit cmd buffer "
11473 "using deleted buffer ";
11474 const char *invalid_offset_message =
11475 "vkBindBufferMemory(): "
11476 "memoryOffset is 0x";
11477 const char *invalid_storage_buffer_offset_message =
11478 "vkBindBufferMemory(): "
11479 "storage memoryOffset "
11480 "is 0x";
11481 const char *invalid_texel_buffer_offset_message =
11482 "vkBindBufferMemory(): "
11483 "texel memoryOffset "
11484 "is 0x";
11485 const char *invalid_uniform_buffer_offset_message =
11486 "vkBindBufferMemory(): "
11487 "uniform memoryOffset "
11488 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011489
11490 ASSERT_NO_FATAL_FAILURE(InitState());
11491 ASSERT_NO_FATAL_FAILURE(InitViewport());
11492 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11493
11494 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011495 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011496 pipe_ms_state_ci.pNext = NULL;
11497 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11498 pipe_ms_state_ci.sampleShadingEnable = 0;
11499 pipe_ms_state_ci.minSampleShading = 1.0;
11500 pipe_ms_state_ci.pSampleMask = nullptr;
11501
11502 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11503 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11504 VkPipelineLayout pipeline_layout;
11505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011506 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011507 ASSERT_VK_SUCCESS(err);
11508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011509 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11510 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011511 VkPipelineObj pipe(m_device);
11512 pipe.AddShader(&vs);
11513 pipe.AddShader(&fs);
11514 pipe.AddColorAttachment();
11515 pipe.SetMSAA(&pipe_ms_state_ci);
11516 pipe.SetViewport(m_viewports);
11517 pipe.SetScissor(m_scissors);
11518 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11519
Tony Barbour552f6c02016-12-21 14:34:07 -070011520 m_commandBuffer->BeginCommandBuffer();
11521 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011522 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011523
11524 {
11525 // Create and bind a vertex buffer in a reduced scope, which will cause
11526 // it to be deleted upon leaving this scope
11527 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011528 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011529 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11530 draw_verticies.AddVertexInputToPipe(pipe);
11531 }
11532
11533 Draw(1, 0, 0, 0);
11534
Tony Barbour552f6c02016-12-21 14:34:07 -070011535 m_commandBuffer->EndRenderPass();
11536 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011539 QueueCommandBuffer(false);
11540 m_errorMonitor->VerifyFound();
11541
11542 {
11543 // Create and bind a vertex buffer in a reduced scope, and delete it
11544 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011545 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011547 buffer_test.TestDoubleDestroy();
11548 }
11549 m_errorMonitor->VerifyFound();
11550
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011551 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011552 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011553 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011555 m_errorMonitor->SetUnexpectedError(
11556 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11557 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011558 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11559 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011560 m_errorMonitor->VerifyFound();
11561 }
11562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011563 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11564 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011565 // Create and bind a memory buffer with an invalid offset again,
11566 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011568 m_errorMonitor->SetUnexpectedError(
11569 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11570 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011571 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11572 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011573 m_errorMonitor->VerifyFound();
11574 }
11575
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011576 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011577 // Create and bind a memory buffer with an invalid offset again, but
11578 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011580 m_errorMonitor->SetUnexpectedError(
11581 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11582 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11584 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011585 m_errorMonitor->VerifyFound();
11586 }
11587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011588 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011589 // Create and bind a memory buffer with an invalid offset again, but
11590 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011592 m_errorMonitor->SetUnexpectedError(
11593 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11594 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011595 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11596 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011597 m_errorMonitor->VerifyFound();
11598 }
11599
11600 {
11601 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011603 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11604 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011605 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11606 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011607 m_errorMonitor->VerifyFound();
11608 }
11609
11610 {
11611 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011613 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11614 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011615 }
11616 m_errorMonitor->VerifyFound();
11617
11618 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11619}
11620
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011621// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11622TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011623 TEST_DESCRIPTION(
11624 "Hit all possible validation checks associated with the "
11625 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11626 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011627 // 3 in ValidateCmdBufImageLayouts
11628 // * -1 Attempt to submit cmd buf w/ deleted image
11629 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11630 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011631
11632 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070011633 auto depth_format = find_depth_stencil_format(m_device);
11634 if (!depth_format) {
11635 printf(" No Depth + Stencil format found. Skipped.\n");
11636 return;
11637 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011638 // Create src & dst images to use for copy operations
11639 VkImage src_image;
11640 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011641 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011642
11643 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11644 const int32_t tex_width = 32;
11645 const int32_t tex_height = 32;
11646
11647 VkImageCreateInfo image_create_info = {};
11648 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11649 image_create_info.pNext = NULL;
11650 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11651 image_create_info.format = tex_format;
11652 image_create_info.extent.width = tex_width;
11653 image_create_info.extent.height = tex_height;
11654 image_create_info.extent.depth = 1;
11655 image_create_info.mipLevels = 1;
11656 image_create_info.arrayLayers = 4;
11657 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11658 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11659 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011660 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011661 image_create_info.flags = 0;
11662
11663 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11664 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011665 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011666 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11667 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011668 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11669 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11670 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11671 ASSERT_VK_SUCCESS(err);
11672
11673 // Allocate memory
11674 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011675 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011676 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011677 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11678 mem_alloc.pNext = NULL;
11679 mem_alloc.allocationSize = 0;
11680 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011681
11682 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011683 mem_alloc.allocationSize = img_mem_reqs.size;
11684 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011685 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011686 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011687 ASSERT_VK_SUCCESS(err);
11688
11689 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011690 mem_alloc.allocationSize = img_mem_reqs.size;
11691 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011692 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011693 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011694 ASSERT_VK_SUCCESS(err);
11695
11696 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011697 mem_alloc.allocationSize = img_mem_reqs.size;
11698 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011699 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011700 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011701 ASSERT_VK_SUCCESS(err);
11702
11703 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11704 ASSERT_VK_SUCCESS(err);
11705 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11706 ASSERT_VK_SUCCESS(err);
11707 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11708 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011709
Tony Barbour552f6c02016-12-21 14:34:07 -070011710 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011711 VkImageCopy copy_region;
11712 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11713 copy_region.srcSubresource.mipLevel = 0;
11714 copy_region.srcSubresource.baseArrayLayer = 0;
11715 copy_region.srcSubresource.layerCount = 1;
11716 copy_region.srcOffset.x = 0;
11717 copy_region.srcOffset.y = 0;
11718 copy_region.srcOffset.z = 0;
11719 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11720 copy_region.dstSubresource.mipLevel = 0;
11721 copy_region.dstSubresource.baseArrayLayer = 0;
11722 copy_region.dstSubresource.layerCount = 1;
11723 copy_region.dstOffset.x = 0;
11724 copy_region.dstOffset.y = 0;
11725 copy_region.dstOffset.z = 0;
11726 copy_region.extent.width = 1;
11727 copy_region.extent.height = 1;
11728 copy_region.extent.depth = 1;
11729
11730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11731 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011732 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011733 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 -060011734 m_errorMonitor->VerifyFound();
11735 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11737 "Cannot copy from an image whose source layout is "
11738 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11739 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011740 m_errorMonitor->SetUnexpectedError(
11741 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011742 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 -060011743 m_errorMonitor->VerifyFound();
11744 // Final src error is due to bad layout type
11745 m_errorMonitor->SetDesiredFailureMsg(
11746 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11747 "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 -070011748 m_errorMonitor->SetUnexpectedError(
11749 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11750 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011751 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 -060011752 m_errorMonitor->VerifyFound();
11753 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11755 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011756 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011757 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 -060011758 m_errorMonitor->VerifyFound();
11759 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11761 "Cannot copy from an image whose dest layout is "
11762 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11763 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011764 m_errorMonitor->SetUnexpectedError(
11765 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011766 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 -060011767 m_errorMonitor->VerifyFound();
11768 m_errorMonitor->SetDesiredFailureMsg(
11769 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11770 "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 -070011771 m_errorMonitor->SetUnexpectedError(
11772 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11773 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011774 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 -060011775 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011776
Cort3b021012016-12-07 12:00:57 -080011777 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11778 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11779 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11780 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11781 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11782 transfer_dst_image_barrier[0].srcAccessMask = 0;
11783 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11784 transfer_dst_image_barrier[0].image = dst_image;
11785 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11786 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11787 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11788 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11789 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11790 transfer_dst_image_barrier[0].image = depth_image;
11791 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11792 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11793 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11794
11795 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011796 VkClearColorValue color_clear_value = {};
11797 VkImageSubresourceRange clear_range;
11798 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11799 clear_range.baseMipLevel = 0;
11800 clear_range.baseArrayLayer = 0;
11801 clear_range.layerCount = 1;
11802 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011803
Cort3b021012016-12-07 12:00:57 -080011804 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11805 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011808 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011809 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011810 // Fail due to provided layout not matching actual current layout for color clear.
11811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011812 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011813 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011814
Cort530cf382016-12-08 09:59:47 -080011815 VkClearDepthStencilValue depth_clear_value = {};
11816 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011817
11818 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11819 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011822 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011823 m_errorMonitor->VerifyFound();
11824 // Fail due to provided layout not matching actual current layout for depth clear.
11825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011826 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011827 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011828
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011829 // Now cause error due to bad image layout transition in PipelineBarrier
11830 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011831 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011832 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011833 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011834 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011835 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11836 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011837 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11839 "You cannot transition the layout of aspect 1 from "
11840 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11841 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011842 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11843 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011844 m_errorMonitor->VerifyFound();
11845
11846 // Finally some layout errors at RenderPass create time
11847 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11848 VkAttachmentReference attach = {};
11849 // perf warning for GENERAL layout w/ non-DS input attachment
11850 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11851 VkSubpassDescription subpass = {};
11852 subpass.inputAttachmentCount = 1;
11853 subpass.pInputAttachments = &attach;
11854 VkRenderPassCreateInfo rpci = {};
11855 rpci.subpassCount = 1;
11856 rpci.pSubpasses = &subpass;
11857 rpci.attachmentCount = 1;
11858 VkAttachmentDescription attach_desc = {};
11859 attach_desc.format = VK_FORMAT_UNDEFINED;
11860 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011861 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011862 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11864 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011865 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11866 m_errorMonitor->VerifyFound();
11867 // error w/ non-general layout
11868 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11869
11870 m_errorMonitor->SetDesiredFailureMsg(
11871 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11872 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11873 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11874 m_errorMonitor->VerifyFound();
11875 subpass.inputAttachmentCount = 0;
11876 subpass.colorAttachmentCount = 1;
11877 subpass.pColorAttachments = &attach;
11878 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11879 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11881 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011882 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11883 m_errorMonitor->VerifyFound();
11884 // error w/ non-color opt or GENERAL layout for color attachment
11885 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11886 m_errorMonitor->SetDesiredFailureMsg(
11887 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11888 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11889 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11890 m_errorMonitor->VerifyFound();
11891 subpass.colorAttachmentCount = 0;
11892 subpass.pDepthStencilAttachment = &attach;
11893 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11894 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11896 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011897 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11898 m_errorMonitor->VerifyFound();
11899 // error w/ non-ds opt or GENERAL layout for color attachment
11900 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11902 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11903 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011904 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11905 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011906 // For this error we need a valid renderpass so create default one
11907 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11908 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070011909 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011910 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11911 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11912 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11913 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11914 // Can't do a CLEAR load on READ_ONLY initialLayout
11915 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11916 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11917 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11919 " with invalid first layout "
11920 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11921 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011922 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11923 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011924
Cort3b021012016-12-07 12:00:57 -080011925 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11926 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11927 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011928 vkDestroyImage(m_device->device(), src_image, NULL);
11929 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011930 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011931}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011932
Tobin Ehlise0936662016-10-11 08:10:51 -060011933TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11934 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11935 VkResult err;
11936
11937 ASSERT_NO_FATAL_FAILURE(InitState());
11938
11939 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11940 VkImageTiling tiling;
11941 VkFormatProperties format_properties;
11942 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11943 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11944 tiling = VK_IMAGE_TILING_LINEAR;
11945 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11946 tiling = VK_IMAGE_TILING_OPTIMAL;
11947 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011948 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011949 return;
11950 }
11951
11952 VkDescriptorPoolSize ds_type = {};
11953 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11954 ds_type.descriptorCount = 1;
11955
11956 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11957 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11958 ds_pool_ci.maxSets = 1;
11959 ds_pool_ci.poolSizeCount = 1;
11960 ds_pool_ci.pPoolSizes = &ds_type;
11961 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11962
11963 VkDescriptorPool ds_pool;
11964 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11965 ASSERT_VK_SUCCESS(err);
11966
11967 VkDescriptorSetLayoutBinding dsl_binding = {};
11968 dsl_binding.binding = 0;
11969 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11970 dsl_binding.descriptorCount = 1;
11971 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11972 dsl_binding.pImmutableSamplers = NULL;
11973
11974 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11975 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11976 ds_layout_ci.pNext = NULL;
11977 ds_layout_ci.bindingCount = 1;
11978 ds_layout_ci.pBindings = &dsl_binding;
11979
11980 VkDescriptorSetLayout ds_layout;
11981 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11982 ASSERT_VK_SUCCESS(err);
11983
11984 VkDescriptorSetAllocateInfo alloc_info = {};
11985 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11986 alloc_info.descriptorSetCount = 1;
11987 alloc_info.descriptorPool = ds_pool;
11988 alloc_info.pSetLayouts = &ds_layout;
11989 VkDescriptorSet descriptor_set;
11990 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11991 ASSERT_VK_SUCCESS(err);
11992
11993 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11994 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11995 pipeline_layout_ci.pNext = NULL;
11996 pipeline_layout_ci.setLayoutCount = 1;
11997 pipeline_layout_ci.pSetLayouts = &ds_layout;
11998 VkPipelineLayout pipeline_layout;
11999 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12000 ASSERT_VK_SUCCESS(err);
12001
12002 VkImageObj image(m_device);
12003 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
12004 ASSERT_TRUE(image.initialized());
12005 VkImageView view = image.targetView(tex_format);
12006
12007 VkDescriptorImageInfo image_info = {};
12008 image_info.imageView = view;
12009 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12010
12011 VkWriteDescriptorSet descriptor_write = {};
12012 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12013 descriptor_write.dstSet = descriptor_set;
12014 descriptor_write.dstBinding = 0;
12015 descriptor_write.descriptorCount = 1;
12016 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12017 descriptor_write.pImageInfo = &image_info;
12018
12019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12020 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12021 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12023 m_errorMonitor->VerifyFound();
12024
12025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12027 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12028 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12029}
12030
Mark Mueller93b938f2016-08-18 10:27:40 -060012031TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012032 TEST_DESCRIPTION(
12033 "Use vkCmdExecuteCommands with invalid state "
12034 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012035
12036 ASSERT_NO_FATAL_FAILURE(InitState());
12037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12038
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012039 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012040 const char *simultaneous_use_message2 =
12041 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12042 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012043
12044 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012045 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012046 command_buffer_allocate_info.commandPool = m_commandPool;
12047 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12048 command_buffer_allocate_info.commandBufferCount = 1;
12049
12050 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012051 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012052 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12053 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012054 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012055 command_buffer_inheritance_info.renderPass = m_renderPass;
12056 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012057
Mark Mueller93b938f2016-08-18 10:27:40 -060012058 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012059 command_buffer_begin_info.flags =
12060 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012061 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12062
12063 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12064 vkEndCommandBuffer(secondary_command_buffer);
12065
Mark Mueller93b938f2016-08-18 10:27:40 -060012066 VkSubmitInfo submit_info = {};
12067 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12068 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012069 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012070
Mark Mueller4042b652016-09-05 22:52:21 -060012071 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012072 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12074 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012075 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012076 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012077 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12078 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012079
Dave Houltonfbf52152017-01-06 12:55:29 -070012080 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012081 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012082 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012083
Mark Mueller4042b652016-09-05 22:52:21 -060012084 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012085 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12086 m_errorMonitor->SetUnexpectedError(
12087 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12088 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012089 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012090 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12093 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012094 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012095 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12096 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012097
12098 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012099
12100 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012101}
12102
Tony Barbour626994c2017-02-08 15:29:37 -070012103TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12104 TEST_DESCRIPTION(
12105 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12106 "errors");
12107 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12108 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12109 ASSERT_NO_FATAL_FAILURE(InitState());
12110
12111 VkCommandBuffer cmd_bufs[2];
12112 VkCommandBufferAllocateInfo alloc_info;
12113 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12114 alloc_info.pNext = NULL;
12115 alloc_info.commandBufferCount = 2;
12116 alloc_info.commandPool = m_commandPool;
12117 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12118 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12119
12120 VkCommandBufferBeginInfo cb_binfo;
12121 cb_binfo.pNext = NULL;
12122 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12123 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12124 cb_binfo.flags = 0;
12125 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12126 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12127 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12128 vkEndCommandBuffer(cmd_bufs[0]);
12129 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12130
12131 VkSubmitInfo submit_info = {};
12132 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12133 submit_info.commandBufferCount = 2;
12134 submit_info.pCommandBuffers = duplicates;
12135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12136 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12137 m_errorMonitor->VerifyFound();
12138 vkQueueWaitIdle(m_device->m_queue);
12139
12140 // Set one time use and now look for one time submit
12141 duplicates[0] = duplicates[1] = cmd_bufs[1];
12142 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12143 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12144 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12145 vkEndCommandBuffer(cmd_bufs[1]);
12146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12147 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12148 m_errorMonitor->VerifyFound();
12149 vkQueueWaitIdle(m_device->m_queue);
12150}
12151
Tobin Ehlisb093da82017-01-19 12:05:27 -070012152TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012153 TEST_DESCRIPTION(
12154 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12155 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012156
12157 ASSERT_NO_FATAL_FAILURE(InitState());
12158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12159
12160 std::vector<const char *> device_extension_names;
12161 auto features = m_device->phy().features();
12162 // Make sure gs & ts are disabled
12163 features.geometryShader = false;
12164 features.tessellationShader = false;
12165 // The sacrificial device object
12166 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12167
12168 VkCommandPoolCreateInfo pool_create_info{};
12169 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12170 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12171
12172 VkCommandPool command_pool;
12173 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12174
12175 VkCommandBufferAllocateInfo cmd = {};
12176 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12177 cmd.pNext = NULL;
12178 cmd.commandPool = command_pool;
12179 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12180 cmd.commandBufferCount = 1;
12181
12182 VkCommandBuffer cmd_buffer;
12183 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12184 ASSERT_VK_SUCCESS(err);
12185
12186 VkEvent event;
12187 VkEventCreateInfo evci = {};
12188 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12189 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12190 ASSERT_VK_SUCCESS(result);
12191
12192 VkCommandBufferBeginInfo cbbi = {};
12193 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12194 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12196 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12197 m_errorMonitor->VerifyFound();
12198
12199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12200 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12201 m_errorMonitor->VerifyFound();
12202
12203 vkDestroyEvent(test_device.handle(), event, NULL);
12204 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12205}
12206
Mark Mueller917f6bc2016-08-30 10:57:19 -060012207TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012208 TEST_DESCRIPTION(
12209 "Use vkCmdExecuteCommands with invalid state "
12210 "in primary and secondary command buffers. "
12211 "Delete objects that are inuse. Call VkQueueSubmit "
12212 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012213
12214 ASSERT_NO_FATAL_FAILURE(InitState());
12215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12216
Tony Barbour552f6c02016-12-21 14:34:07 -070012217 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012218
12219 VkEvent event;
12220 VkEventCreateInfo event_create_info = {};
12221 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12222 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012224
Tony Barbour552f6c02016-12-21 14:34:07 -070012225 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012226 vkDestroyEvent(m_device->device(), event, nullptr);
12227
12228 VkSubmitInfo submit_info = {};
12229 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12230 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012231 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012233 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12234 m_errorMonitor->VerifyFound();
12235
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012236 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012237 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12238
12239 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12240
Mark Mueller917f6bc2016-08-30 10:57:19 -060012241 VkSemaphoreCreateInfo semaphore_create_info = {};
12242 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12243 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012244 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012245 VkFenceCreateInfo fence_create_info = {};
12246 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12247 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012248 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012249
12250 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012251 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012252 descriptor_pool_type_count.descriptorCount = 1;
12253
12254 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12255 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12256 descriptor_pool_create_info.maxSets = 1;
12257 descriptor_pool_create_info.poolSizeCount = 1;
12258 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012259 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012260
12261 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012262 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012263
12264 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012265 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012266 descriptorset_layout_binding.descriptorCount = 1;
12267 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12268
12269 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012270 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012271 descriptorset_layout_create_info.bindingCount = 1;
12272 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12273
12274 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012275 ASSERT_VK_SUCCESS(
12276 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012277
12278 VkDescriptorSet descriptorset;
12279 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012280 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012281 descriptorset_allocate_info.descriptorSetCount = 1;
12282 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12283 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012284 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012285
Mark Mueller4042b652016-09-05 22:52:21 -060012286 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12287
12288 VkDescriptorBufferInfo buffer_info = {};
12289 buffer_info.buffer = buffer_test.GetBuffer();
12290 buffer_info.offset = 0;
12291 buffer_info.range = 1024;
12292
12293 VkWriteDescriptorSet write_descriptor_set = {};
12294 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12295 write_descriptor_set.dstSet = descriptorset;
12296 write_descriptor_set.descriptorCount = 1;
12297 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12298 write_descriptor_set.pBufferInfo = &buffer_info;
12299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012300 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012302 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12303 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012304
12305 VkPipelineObj pipe(m_device);
12306 pipe.AddColorAttachment();
12307 pipe.AddShader(&vs);
12308 pipe.AddShader(&fs);
12309
12310 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012311 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012312 pipeline_layout_create_info.setLayoutCount = 1;
12313 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12314
12315 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012316 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012317
12318 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12319
Tony Barbour552f6c02016-12-21 14:34:07 -070012320 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012321 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012323 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12324 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12325 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012326
Tony Barbour552f6c02016-12-21 14:34:07 -070012327 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012328
Mark Mueller917f6bc2016-08-30 10:57:19 -060012329 submit_info.signalSemaphoreCount = 1;
12330 submit_info.pSignalSemaphores = &semaphore;
12331 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012332 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012333
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012335 vkDestroyEvent(m_device->device(), event, nullptr);
12336 m_errorMonitor->VerifyFound();
12337
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012339 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12340 m_errorMonitor->VerifyFound();
12341
Jeremy Hayes08369882017-02-02 10:31:06 -070012342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012343 vkDestroyFence(m_device->device(), fence, nullptr);
12344 m_errorMonitor->VerifyFound();
12345
Tobin Ehlis122207b2016-09-01 08:50:06 -070012346 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012347 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12348 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012349 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012350 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12351 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012352 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012353 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12354 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012355 vkDestroyEvent(m_device->device(), event, nullptr);
12356 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012357 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012358 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12359}
12360
Tobin Ehlis2adda372016-09-01 08:51:06 -070012361TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12362 TEST_DESCRIPTION("Delete in-use query pool.");
12363
12364 ASSERT_NO_FATAL_FAILURE(InitState());
12365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12366
12367 VkQueryPool query_pool;
12368 VkQueryPoolCreateInfo query_pool_ci{};
12369 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12370 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12371 query_pool_ci.queryCount = 1;
12372 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012373 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012374 // Reset query pool to create binding with cmd buffer
12375 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12376
Tony Barbour552f6c02016-12-21 14:34:07 -070012377 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012378
12379 VkSubmitInfo submit_info = {};
12380 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12381 submit_info.commandBufferCount = 1;
12382 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12383 // Submit cmd buffer and then destroy query pool while in-flight
12384 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12385
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012387 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12388 m_errorMonitor->VerifyFound();
12389
12390 vkQueueWaitIdle(m_device->m_queue);
12391 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012392 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12393 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012394 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12395}
12396
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012397TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12398 TEST_DESCRIPTION("Delete in-use pipeline.");
12399
12400 ASSERT_NO_FATAL_FAILURE(InitState());
12401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12402
12403 // Empty pipeline layout used for binding PSO
12404 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12405 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12406 pipeline_layout_ci.setLayoutCount = 0;
12407 pipeline_layout_ci.pSetLayouts = NULL;
12408
12409 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012410 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012411 ASSERT_VK_SUCCESS(err);
12412
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012414 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012415 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12416 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012417 // Store pipeline handle so we can actually delete it before test finishes
12418 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012419 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012420 VkPipelineObj pipe(m_device);
12421 pipe.AddShader(&vs);
12422 pipe.AddShader(&fs);
12423 pipe.AddColorAttachment();
12424 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12425 delete_this_pipeline = pipe.handle();
12426
Tony Barbour552f6c02016-12-21 14:34:07 -070012427 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012428 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012429 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012430
Tony Barbour552f6c02016-12-21 14:34:07 -070012431 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012432
12433 VkSubmitInfo submit_info = {};
12434 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12435 submit_info.commandBufferCount = 1;
12436 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12437 // Submit cmd buffer and then pipeline destroyed while in-flight
12438 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012439 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012440 m_errorMonitor->VerifyFound();
12441 // Make sure queue finished and then actually delete pipeline
12442 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012443 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12444 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012445 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12446 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12447}
12448
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012449TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12450 TEST_DESCRIPTION("Delete in-use imageView.");
12451
12452 ASSERT_NO_FATAL_FAILURE(InitState());
12453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12454
12455 VkDescriptorPoolSize ds_type_count;
12456 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12457 ds_type_count.descriptorCount = 1;
12458
12459 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12460 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12461 ds_pool_ci.maxSets = 1;
12462 ds_pool_ci.poolSizeCount = 1;
12463 ds_pool_ci.pPoolSizes = &ds_type_count;
12464
12465 VkDescriptorPool ds_pool;
12466 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12467 ASSERT_VK_SUCCESS(err);
12468
12469 VkSamplerCreateInfo sampler_ci = {};
12470 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12471 sampler_ci.pNext = NULL;
12472 sampler_ci.magFilter = VK_FILTER_NEAREST;
12473 sampler_ci.minFilter = VK_FILTER_NEAREST;
12474 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12475 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12476 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12477 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12478 sampler_ci.mipLodBias = 1.0;
12479 sampler_ci.anisotropyEnable = VK_FALSE;
12480 sampler_ci.maxAnisotropy = 1;
12481 sampler_ci.compareEnable = VK_FALSE;
12482 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12483 sampler_ci.minLod = 1.0;
12484 sampler_ci.maxLod = 1.0;
12485 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12486 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12487 VkSampler sampler;
12488
12489 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12490 ASSERT_VK_SUCCESS(err);
12491
12492 VkDescriptorSetLayoutBinding layout_binding;
12493 layout_binding.binding = 0;
12494 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12495 layout_binding.descriptorCount = 1;
12496 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12497 layout_binding.pImmutableSamplers = NULL;
12498
12499 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12500 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12501 ds_layout_ci.bindingCount = 1;
12502 ds_layout_ci.pBindings = &layout_binding;
12503 VkDescriptorSetLayout ds_layout;
12504 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12505 ASSERT_VK_SUCCESS(err);
12506
12507 VkDescriptorSetAllocateInfo alloc_info = {};
12508 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12509 alloc_info.descriptorSetCount = 1;
12510 alloc_info.descriptorPool = ds_pool;
12511 alloc_info.pSetLayouts = &ds_layout;
12512 VkDescriptorSet descriptor_set;
12513 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12514 ASSERT_VK_SUCCESS(err);
12515
12516 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12517 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12518 pipeline_layout_ci.pNext = NULL;
12519 pipeline_layout_ci.setLayoutCount = 1;
12520 pipeline_layout_ci.pSetLayouts = &ds_layout;
12521
12522 VkPipelineLayout pipeline_layout;
12523 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12524 ASSERT_VK_SUCCESS(err);
12525
12526 VkImageObj image(m_device);
12527 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12528 ASSERT_TRUE(image.initialized());
12529
12530 VkImageView view;
12531 VkImageViewCreateInfo ivci = {};
12532 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12533 ivci.image = image.handle();
12534 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12535 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12536 ivci.subresourceRange.layerCount = 1;
12537 ivci.subresourceRange.baseMipLevel = 0;
12538 ivci.subresourceRange.levelCount = 1;
12539 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12540
12541 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12542 ASSERT_VK_SUCCESS(err);
12543
12544 VkDescriptorImageInfo image_info{};
12545 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12546 image_info.imageView = view;
12547 image_info.sampler = sampler;
12548
12549 VkWriteDescriptorSet descriptor_write = {};
12550 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12551 descriptor_write.dstSet = descriptor_set;
12552 descriptor_write.dstBinding = 0;
12553 descriptor_write.descriptorCount = 1;
12554 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12555 descriptor_write.pImageInfo = &image_info;
12556
12557 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12558
12559 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012560 char const *vsSource =
12561 "#version 450\n"
12562 "\n"
12563 "out gl_PerVertex { \n"
12564 " vec4 gl_Position;\n"
12565 "};\n"
12566 "void main(){\n"
12567 " gl_Position = vec4(1);\n"
12568 "}\n";
12569 char const *fsSource =
12570 "#version 450\n"
12571 "\n"
12572 "layout(set=0, binding=0) uniform sampler2D s;\n"
12573 "layout(location=0) out vec4 x;\n"
12574 "void main(){\n"
12575 " x = texture(s, vec2(1));\n"
12576 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012577 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12578 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12579 VkPipelineObj pipe(m_device);
12580 pipe.AddShader(&vs);
12581 pipe.AddShader(&fs);
12582 pipe.AddColorAttachment();
12583 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12584
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012586
Tony Barbour552f6c02016-12-21 14:34:07 -070012587 m_commandBuffer->BeginCommandBuffer();
12588 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012589 // Bind pipeline to cmd buffer
12590 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12591 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12592 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012593
12594 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12595 VkRect2D scissor = {{0, 0}, {16, 16}};
12596 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12597 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12598
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012599 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012600 m_commandBuffer->EndRenderPass();
12601 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012602 // Submit cmd buffer then destroy sampler
12603 VkSubmitInfo submit_info = {};
12604 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12605 submit_info.commandBufferCount = 1;
12606 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12607 // Submit cmd buffer and then destroy imageView while in-flight
12608 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12609
12610 vkDestroyImageView(m_device->device(), view, nullptr);
12611 m_errorMonitor->VerifyFound();
12612 vkQueueWaitIdle(m_device->m_queue);
12613 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012614 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12615 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012616 vkDestroyImageView(m_device->device(), view, NULL);
12617 vkDestroySampler(m_device->device(), sampler, nullptr);
12618 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12619 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12620 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12621}
12622
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012623TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12624 TEST_DESCRIPTION("Delete in-use bufferView.");
12625
12626 ASSERT_NO_FATAL_FAILURE(InitState());
12627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12628
12629 VkDescriptorPoolSize ds_type_count;
12630 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12631 ds_type_count.descriptorCount = 1;
12632
12633 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12634 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12635 ds_pool_ci.maxSets = 1;
12636 ds_pool_ci.poolSizeCount = 1;
12637 ds_pool_ci.pPoolSizes = &ds_type_count;
12638
12639 VkDescriptorPool ds_pool;
12640 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12641 ASSERT_VK_SUCCESS(err);
12642
12643 VkDescriptorSetLayoutBinding layout_binding;
12644 layout_binding.binding = 0;
12645 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12646 layout_binding.descriptorCount = 1;
12647 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12648 layout_binding.pImmutableSamplers = NULL;
12649
12650 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12651 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12652 ds_layout_ci.bindingCount = 1;
12653 ds_layout_ci.pBindings = &layout_binding;
12654 VkDescriptorSetLayout ds_layout;
12655 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12656 ASSERT_VK_SUCCESS(err);
12657
12658 VkDescriptorSetAllocateInfo alloc_info = {};
12659 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12660 alloc_info.descriptorSetCount = 1;
12661 alloc_info.descriptorPool = ds_pool;
12662 alloc_info.pSetLayouts = &ds_layout;
12663 VkDescriptorSet descriptor_set;
12664 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12665 ASSERT_VK_SUCCESS(err);
12666
12667 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12668 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12669 pipeline_layout_ci.pNext = NULL;
12670 pipeline_layout_ci.setLayoutCount = 1;
12671 pipeline_layout_ci.pSetLayouts = &ds_layout;
12672
12673 VkPipelineLayout pipeline_layout;
12674 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12675 ASSERT_VK_SUCCESS(err);
12676
12677 VkBuffer buffer;
12678 uint32_t queue_family_index = 0;
12679 VkBufferCreateInfo buffer_create_info = {};
12680 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12681 buffer_create_info.size = 1024;
12682 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12683 buffer_create_info.queueFamilyIndexCount = 1;
12684 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12685
12686 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12687 ASSERT_VK_SUCCESS(err);
12688
12689 VkMemoryRequirements memory_reqs;
12690 VkDeviceMemory buffer_memory;
12691
12692 VkMemoryAllocateInfo memory_info = {};
12693 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12694 memory_info.allocationSize = 0;
12695 memory_info.memoryTypeIndex = 0;
12696
12697 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12698 memory_info.allocationSize = memory_reqs.size;
12699 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12700 ASSERT_TRUE(pass);
12701
12702 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12703 ASSERT_VK_SUCCESS(err);
12704 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12705 ASSERT_VK_SUCCESS(err);
12706
12707 VkBufferView view;
12708 VkBufferViewCreateInfo bvci = {};
12709 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12710 bvci.buffer = buffer;
12711 bvci.format = VK_FORMAT_R8_UNORM;
12712 bvci.range = VK_WHOLE_SIZE;
12713
12714 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12715 ASSERT_VK_SUCCESS(err);
12716
12717 VkWriteDescriptorSet descriptor_write = {};
12718 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12719 descriptor_write.dstSet = descriptor_set;
12720 descriptor_write.dstBinding = 0;
12721 descriptor_write.descriptorCount = 1;
12722 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12723 descriptor_write.pTexelBufferView = &view;
12724
12725 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12726
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012727 char const *vsSource =
12728 "#version 450\n"
12729 "\n"
12730 "out gl_PerVertex { \n"
12731 " vec4 gl_Position;\n"
12732 "};\n"
12733 "void main(){\n"
12734 " gl_Position = vec4(1);\n"
12735 "}\n";
12736 char const *fsSource =
12737 "#version 450\n"
12738 "\n"
12739 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12740 "layout(location=0) out vec4 x;\n"
12741 "void main(){\n"
12742 " x = imageLoad(s, 0);\n"
12743 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012744 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12745 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12746 VkPipelineObj pipe(m_device);
12747 pipe.AddShader(&vs);
12748 pipe.AddShader(&fs);
12749 pipe.AddColorAttachment();
12750 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12751
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012753
Tony Barbour552f6c02016-12-21 14:34:07 -070012754 m_commandBuffer->BeginCommandBuffer();
12755 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012756 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12757 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12758 VkRect2D scissor = {{0, 0}, {16, 16}};
12759 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12760 // Bind pipeline to cmd buffer
12761 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12762 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12763 &descriptor_set, 0, nullptr);
12764 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012765 m_commandBuffer->EndRenderPass();
12766 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012767
12768 VkSubmitInfo submit_info = {};
12769 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12770 submit_info.commandBufferCount = 1;
12771 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12772 // Submit cmd buffer and then destroy bufferView while in-flight
12773 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12774
12775 vkDestroyBufferView(m_device->device(), view, nullptr);
12776 m_errorMonitor->VerifyFound();
12777 vkQueueWaitIdle(m_device->m_queue);
12778 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012779 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12780 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012781 vkDestroyBufferView(m_device->device(), view, NULL);
12782 vkDestroyBuffer(m_device->device(), buffer, NULL);
12783 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12784 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12785 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12786 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12787}
12788
Tobin Ehlis209532e2016-09-07 13:52:18 -060012789TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12790 TEST_DESCRIPTION("Delete in-use sampler.");
12791
12792 ASSERT_NO_FATAL_FAILURE(InitState());
12793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12794
12795 VkDescriptorPoolSize ds_type_count;
12796 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12797 ds_type_count.descriptorCount = 1;
12798
12799 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12800 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12801 ds_pool_ci.maxSets = 1;
12802 ds_pool_ci.poolSizeCount = 1;
12803 ds_pool_ci.pPoolSizes = &ds_type_count;
12804
12805 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012806 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012807 ASSERT_VK_SUCCESS(err);
12808
12809 VkSamplerCreateInfo sampler_ci = {};
12810 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12811 sampler_ci.pNext = NULL;
12812 sampler_ci.magFilter = VK_FILTER_NEAREST;
12813 sampler_ci.minFilter = VK_FILTER_NEAREST;
12814 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12815 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12816 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12817 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12818 sampler_ci.mipLodBias = 1.0;
12819 sampler_ci.anisotropyEnable = VK_FALSE;
12820 sampler_ci.maxAnisotropy = 1;
12821 sampler_ci.compareEnable = VK_FALSE;
12822 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12823 sampler_ci.minLod = 1.0;
12824 sampler_ci.maxLod = 1.0;
12825 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12826 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12827 VkSampler sampler;
12828
12829 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12830 ASSERT_VK_SUCCESS(err);
12831
12832 VkDescriptorSetLayoutBinding layout_binding;
12833 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012834 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012835 layout_binding.descriptorCount = 1;
12836 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12837 layout_binding.pImmutableSamplers = NULL;
12838
12839 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12840 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12841 ds_layout_ci.bindingCount = 1;
12842 ds_layout_ci.pBindings = &layout_binding;
12843 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012844 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012845 ASSERT_VK_SUCCESS(err);
12846
12847 VkDescriptorSetAllocateInfo alloc_info = {};
12848 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12849 alloc_info.descriptorSetCount = 1;
12850 alloc_info.descriptorPool = ds_pool;
12851 alloc_info.pSetLayouts = &ds_layout;
12852 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012853 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012854 ASSERT_VK_SUCCESS(err);
12855
12856 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12857 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12858 pipeline_layout_ci.pNext = NULL;
12859 pipeline_layout_ci.setLayoutCount = 1;
12860 pipeline_layout_ci.pSetLayouts = &ds_layout;
12861
12862 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012863 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012864 ASSERT_VK_SUCCESS(err);
12865
12866 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012867 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 -060012868 ASSERT_TRUE(image.initialized());
12869
12870 VkImageView view;
12871 VkImageViewCreateInfo ivci = {};
12872 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12873 ivci.image = image.handle();
12874 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12875 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12876 ivci.subresourceRange.layerCount = 1;
12877 ivci.subresourceRange.baseMipLevel = 0;
12878 ivci.subresourceRange.levelCount = 1;
12879 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12880
12881 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12882 ASSERT_VK_SUCCESS(err);
12883
12884 VkDescriptorImageInfo image_info{};
12885 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12886 image_info.imageView = view;
12887 image_info.sampler = sampler;
12888
12889 VkWriteDescriptorSet descriptor_write = {};
12890 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12891 descriptor_write.dstSet = descriptor_set;
12892 descriptor_write.dstBinding = 0;
12893 descriptor_write.descriptorCount = 1;
12894 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12895 descriptor_write.pImageInfo = &image_info;
12896
12897 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12898
12899 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012900 char const *vsSource =
12901 "#version 450\n"
12902 "\n"
12903 "out gl_PerVertex { \n"
12904 " vec4 gl_Position;\n"
12905 "};\n"
12906 "void main(){\n"
12907 " gl_Position = vec4(1);\n"
12908 "}\n";
12909 char const *fsSource =
12910 "#version 450\n"
12911 "\n"
12912 "layout(set=0, binding=0) uniform sampler2D s;\n"
12913 "layout(location=0) out vec4 x;\n"
12914 "void main(){\n"
12915 " x = texture(s, vec2(1));\n"
12916 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12919 VkPipelineObj pipe(m_device);
12920 pipe.AddShader(&vs);
12921 pipe.AddShader(&fs);
12922 pipe.AddColorAttachment();
12923 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12924
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012926
Tony Barbour552f6c02016-12-21 14:34:07 -070012927 m_commandBuffer->BeginCommandBuffer();
12928 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012929 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012930 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12931 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12932 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012933
12934 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12935 VkRect2D scissor = {{0, 0}, {16, 16}};
12936 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12937 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12938
Tobin Ehlis209532e2016-09-07 13:52:18 -060012939 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012940 m_commandBuffer->EndRenderPass();
12941 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012942 // Submit cmd buffer then destroy sampler
12943 VkSubmitInfo submit_info = {};
12944 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12945 submit_info.commandBufferCount = 1;
12946 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12947 // Submit cmd buffer and then destroy sampler while in-flight
12948 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12949
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012950 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012951 m_errorMonitor->VerifyFound();
12952 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012953
Tobin Ehlis209532e2016-09-07 13:52:18 -060012954 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012955 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12956 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012957 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012958 vkDestroyImageView(m_device->device(), view, NULL);
12959 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12960 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12961 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12962}
12963
Mark Mueller1cd9f412016-08-25 13:23:52 -060012964TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012965 TEST_DESCRIPTION(
12966 "Call VkQueueSubmit with a semaphore that is already "
12967 "signaled but not waited on by the queue. Wait on a "
12968 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012969
12970 ASSERT_NO_FATAL_FAILURE(InitState());
12971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012973 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 -070012974 const char *invalid_fence_wait_message =
12975 " which has not been submitted on a Queue or during "
12976 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012977
Tony Barbour552f6c02016-12-21 14:34:07 -070012978 m_commandBuffer->BeginCommandBuffer();
12979 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012980
12981 VkSemaphoreCreateInfo semaphore_create_info = {};
12982 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12983 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012984 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012985 VkSubmitInfo submit_info = {};
12986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12987 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012988 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012989 submit_info.signalSemaphoreCount = 1;
12990 submit_info.pSignalSemaphores = &semaphore;
12991 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012992 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012993 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012994 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012995 m_commandBuffer->BeginCommandBuffer();
12996 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012998 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12999 m_errorMonitor->VerifyFound();
13000
Mark Mueller1cd9f412016-08-25 13:23:52 -060013001 VkFenceCreateInfo fence_create_info = {};
13002 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13003 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013004 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013007 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13008 m_errorMonitor->VerifyFound();
13009
Mark Mueller4042b652016-09-05 22:52:21 -060013010 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013011 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013012 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13013}
13014
Tobin Ehlis4af23302016-07-19 10:50:30 -060013015TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013016 TEST_DESCRIPTION(
13017 "Bind a secondary command buffer with with a framebuffer "
13018 "that does not match the framebuffer for the active "
13019 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013020 ASSERT_NO_FATAL_FAILURE(InitState());
13021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13022
13023 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013024 VkAttachmentDescription attachment = {0,
13025 VK_FORMAT_B8G8R8A8_UNORM,
13026 VK_SAMPLE_COUNT_1_BIT,
13027 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13028 VK_ATTACHMENT_STORE_OP_STORE,
13029 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13030 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13031 VK_IMAGE_LAYOUT_UNDEFINED,
13032 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013034 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013036 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013038 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013039
13040 VkRenderPass rp;
13041 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13042 ASSERT_VK_SUCCESS(err);
13043
13044 // A compatible framebuffer.
13045 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013046 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 -060013047 ASSERT_TRUE(image.initialized());
13048
13049 VkImageViewCreateInfo ivci = {
13050 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13051 nullptr,
13052 0,
13053 image.handle(),
13054 VK_IMAGE_VIEW_TYPE_2D,
13055 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013056 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13057 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013058 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13059 };
13060 VkImageView view;
13061 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13062 ASSERT_VK_SUCCESS(err);
13063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013064 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013065 VkFramebuffer fb;
13066 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13067 ASSERT_VK_SUCCESS(err);
13068
13069 VkCommandBufferAllocateInfo cbai = {};
13070 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13071 cbai.commandPool = m_commandPool;
13072 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13073 cbai.commandBufferCount = 1;
13074
13075 VkCommandBuffer sec_cb;
13076 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13077 ASSERT_VK_SUCCESS(err);
13078 VkCommandBufferBeginInfo cbbi = {};
13079 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013080 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013081 cbii.renderPass = renderPass();
13082 cbii.framebuffer = fb;
13083 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13084 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013085 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 -060013086 cbbi.pInheritanceInfo = &cbii;
13087 vkBeginCommandBuffer(sec_cb, &cbbi);
13088 vkEndCommandBuffer(sec_cb);
13089
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013090 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013091 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13092 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013095 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013096 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13097 m_errorMonitor->VerifyFound();
13098 // Cleanup
13099 vkDestroyImageView(m_device->device(), view, NULL);
13100 vkDestroyRenderPass(m_device->device(), rp, NULL);
13101 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13102}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013103
13104TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013105 TEST_DESCRIPTION(
13106 "If logicOp is available on the device, set it to an "
13107 "invalid value. If logicOp is not available, attempt to "
13108 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013109 ASSERT_NO_FATAL_FAILURE(InitState());
13110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13111
13112 auto features = m_device->phy().features();
13113 // Set the expected error depending on whether or not logicOp available
13114 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13116 "If logic operations feature not "
13117 "enabled, logicOpEnable must be "
13118 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013119 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013121 }
13122 // Create a pipeline using logicOp
13123 VkResult err;
13124
13125 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13126 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13127
13128 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013129 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013130 ASSERT_VK_SUCCESS(err);
13131
13132 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13133 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13134 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013135 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013136 vp_state_ci.pViewports = &vp;
13137 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013138 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013139 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013140
13141 VkPipelineShaderStageCreateInfo shaderStages[2];
13142 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013144 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13145 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013146 shaderStages[0] = vs.GetStageCreateInfo();
13147 shaderStages[1] = fs.GetStageCreateInfo();
13148
13149 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13150 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13151
13152 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13153 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13154 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13155
13156 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13157 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013158 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013159
13160 VkPipelineColorBlendAttachmentState att = {};
13161 att.blendEnable = VK_FALSE;
13162 att.colorWriteMask = 0xf;
13163
13164 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13165 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13166 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13167 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013168 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013169 cb_ci.attachmentCount = 1;
13170 cb_ci.pAttachments = &att;
13171
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013172 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13173 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13174 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13175
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013176 VkGraphicsPipelineCreateInfo gp_ci = {};
13177 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13178 gp_ci.stageCount = 2;
13179 gp_ci.pStages = shaderStages;
13180 gp_ci.pVertexInputState = &vi_ci;
13181 gp_ci.pInputAssemblyState = &ia_ci;
13182 gp_ci.pViewportState = &vp_state_ci;
13183 gp_ci.pRasterizationState = &rs_ci;
13184 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013185 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013186 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13187 gp_ci.layout = pipeline_layout;
13188 gp_ci.renderPass = renderPass();
13189
13190 VkPipelineCacheCreateInfo pc_ci = {};
13191 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13192
13193 VkPipeline pipeline;
13194 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013195 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013196 ASSERT_VK_SUCCESS(err);
13197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013198 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013199 m_errorMonitor->VerifyFound();
13200 if (VK_SUCCESS == err) {
13201 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13202 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013203 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13204 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13205}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013206
Mike Stroyanaccf7692015-05-12 16:00:45 -060013207#if GTEST_IS_THREADSAFE
13208struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013209 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013210 VkEvent event;
13211 bool bailout;
13212};
13213
Karl Schultz6addd812016-02-02 17:17:23 -070013214extern "C" void *AddToCommandBuffer(void *arg) {
13215 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013216
Mike Stroyana6d14942016-07-13 15:10:05 -060013217 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013218 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013219 if (data->bailout) {
13220 break;
13221 }
13222 }
13223 return NULL;
13224}
13225
Karl Schultz6addd812016-02-02 17:17:23 -070013226TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013227 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013228
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013230
Mike Stroyanaccf7692015-05-12 16:00:45 -060013231 ASSERT_NO_FATAL_FAILURE(InitState());
13232 ASSERT_NO_FATAL_FAILURE(InitViewport());
13233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13234
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013235 // Calls AllocateCommandBuffers
13236 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013237
13238 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013239 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013240
13241 VkEventCreateInfo event_info;
13242 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013243 VkResult err;
13244
13245 memset(&event_info, 0, sizeof(event_info));
13246 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13247
Chia-I Wuf7458c52015-10-26 21:10:41 +080013248 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013249 ASSERT_VK_SUCCESS(err);
13250
Mike Stroyanaccf7692015-05-12 16:00:45 -060013251 err = vkResetEvent(device(), event);
13252 ASSERT_VK_SUCCESS(err);
13253
13254 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013255 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013256 data.event = event;
13257 data.bailout = false;
13258 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013259
13260 // First do some correct operations using multiple threads.
13261 // Add many entries to command buffer from another thread.
13262 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13263 // Make non-conflicting calls from this thread at the same time.
13264 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013265 uint32_t count;
13266 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013267 }
13268 test_platform_thread_join(thread, NULL);
13269
13270 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013271 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013272 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013273 // Add many entries to command buffer from this thread at the same time.
13274 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013275
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013276 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013277 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013278
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013279 m_errorMonitor->SetBailout(NULL);
13280
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013281 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013282
Chia-I Wuf7458c52015-10-26 21:10:41 +080013283 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013284}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013285#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013286
Karl Schultz6addd812016-02-02 17:17:23 -070013287TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013288 TEST_DESCRIPTION(
13289 "Test that an error is produced for a spirv module "
13290 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013293
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013294 ASSERT_NO_FATAL_FAILURE(InitState());
13295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13296
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013297 VkShaderModule module;
13298 VkShaderModuleCreateInfo moduleCreateInfo;
13299 struct icd_spv_header spv;
13300
13301 spv.magic = ICD_SPV_MAGIC;
13302 spv.version = ICD_SPV_VERSION;
13303 spv.gen_magic = 0;
13304
13305 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13306 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013307 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013308 moduleCreateInfo.codeSize = 4;
13309 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013310 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013311
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013312 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013313}
13314
Karl Schultz6addd812016-02-02 17:17:23 -070013315TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013316 TEST_DESCRIPTION(
13317 "Test that an error is produced for a spirv module "
13318 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013321
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013322 ASSERT_NO_FATAL_FAILURE(InitState());
13323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13324
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013325 VkShaderModule module;
13326 VkShaderModuleCreateInfo moduleCreateInfo;
13327 struct icd_spv_header spv;
13328
13329 spv.magic = ~ICD_SPV_MAGIC;
13330 spv.version = ICD_SPV_VERSION;
13331 spv.gen_magic = 0;
13332
13333 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13334 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013335 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013336 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13337 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013338 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013339
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013340 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013341}
13342
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013343#if 0
13344// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013345TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013347 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013348
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013349 ASSERT_NO_FATAL_FAILURE(InitState());
13350 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13351
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013352 VkShaderModule module;
13353 VkShaderModuleCreateInfo moduleCreateInfo;
13354 struct icd_spv_header spv;
13355
13356 spv.magic = ICD_SPV_MAGIC;
13357 spv.version = ~ICD_SPV_VERSION;
13358 spv.gen_magic = 0;
13359
13360 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13361 moduleCreateInfo.pNext = NULL;
13362
Karl Schultz6addd812016-02-02 17:17:23 -070013363 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013364 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13365 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013366 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013367
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013368 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013369}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013370#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013371
Karl Schultz6addd812016-02-02 17:17:23 -070013372TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013373 TEST_DESCRIPTION(
13374 "Test that a warning is produced for a vertex output that "
13375 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013377
Chris Forbes9f7ff632015-05-25 11:13:08 +120013378 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013380
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013381 char const *vsSource =
13382 "#version 450\n"
13383 "\n"
13384 "layout(location=0) out float x;\n"
13385 "out gl_PerVertex {\n"
13386 " vec4 gl_Position;\n"
13387 "};\n"
13388 "void main(){\n"
13389 " gl_Position = vec4(1);\n"
13390 " x = 0;\n"
13391 "}\n";
13392 char const *fsSource =
13393 "#version 450\n"
13394 "\n"
13395 "layout(location=0) out vec4 color;\n"
13396 "void main(){\n"
13397 " color = vec4(1);\n"
13398 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013399
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013400 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13401 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013402
13403 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013404 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013405 pipe.AddShader(&vs);
13406 pipe.AddShader(&fs);
13407
Chris Forbes9f7ff632015-05-25 11:13:08 +120013408 VkDescriptorSetObj descriptorSet(m_device);
13409 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013410 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013411
Tony Barbour5781e8f2015-08-04 16:23:11 -060013412 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013413
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013414 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013415}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013416
Mark Mueller098c9cb2016-09-08 09:01:57 -060013417TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13418 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13419
13420 ASSERT_NO_FATAL_FAILURE(InitState());
13421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13422
13423 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013424 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013425
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013426 char const *vsSource =
13427 "#version 450\n"
13428 "\n"
13429 "out gl_PerVertex {\n"
13430 " vec4 gl_Position;\n"
13431 "};\n"
13432 "void main(){\n"
13433 " gl_Position = vec4(1);\n"
13434 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013435
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013436 char const *fsSource =
13437 "#version 450\n"
13438 "\n"
13439 "layout (constant_id = 0) const float r = 0.0f;\n"
13440 "layout(location = 0) out vec4 uFragColor;\n"
13441 "void main(){\n"
13442 " uFragColor = vec4(r,1,0,1);\n"
13443 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013444
13445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13447
13448 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13449 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13450
13451 VkPipelineLayout pipeline_layout;
13452 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13453
13454 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13455 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13456 vp_state_create_info.viewportCount = 1;
13457 VkViewport viewport = {};
13458 vp_state_create_info.pViewports = &viewport;
13459 vp_state_create_info.scissorCount = 1;
13460 VkRect2D scissors = {};
13461 vp_state_create_info.pScissors = &scissors;
13462
13463 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13464
13465 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13466 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13467 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13468 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13469
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013470 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013471
13472 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13473 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13474
13475 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13476 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13477 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13478
13479 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13480 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13481 rasterization_state_create_info.pNext = nullptr;
13482 rasterization_state_create_info.lineWidth = 1.0f;
13483 rasterization_state_create_info.rasterizerDiscardEnable = true;
13484
13485 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13486 color_blend_attachment_state.blendEnable = VK_FALSE;
13487 color_blend_attachment_state.colorWriteMask = 0xf;
13488
13489 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13490 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13491 color_blend_state_create_info.attachmentCount = 1;
13492 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13493
13494 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13495 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13496 graphicspipe_create_info.stageCount = 2;
13497 graphicspipe_create_info.pStages = shader_stage_create_info;
13498 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13499 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13500 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13501 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13502 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13503 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13504 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13505 graphicspipe_create_info.layout = pipeline_layout;
13506 graphicspipe_create_info.renderPass = renderPass();
13507
13508 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13509 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13510
13511 VkPipelineCache pipelineCache;
13512 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13513
13514 // This structure maps constant ids to data locations.
13515 const VkSpecializationMapEntry entry =
13516 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013517 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013518
13519 uint32_t data = 1;
13520
13521 // Set up the info describing spec map and data
13522 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013523 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013524 };
13525 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13526
13527 VkPipeline pipeline;
13528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13529 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13530 m_errorMonitor->VerifyFound();
13531
13532 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13533 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13534}
13535
13536TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13537 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13538
13539 ASSERT_NO_FATAL_FAILURE(InitState());
13540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13541
13542 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13543
13544 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13545 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13546 descriptor_pool_type_count[0].descriptorCount = 1;
13547 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13548 descriptor_pool_type_count[1].descriptorCount = 1;
13549
13550 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13551 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13552 descriptor_pool_create_info.maxSets = 1;
13553 descriptor_pool_create_info.poolSizeCount = 2;
13554 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13555 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13556
13557 VkDescriptorPool descriptorset_pool;
13558 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13559
13560 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13561 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13562 descriptorset_layout_binding.descriptorCount = 1;
13563 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070013564 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013565
13566 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13567 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13568 descriptorset_layout_create_info.bindingCount = 1;
13569 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13570
13571 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013572 ASSERT_VK_SUCCESS(
13573 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013574
13575 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13576 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13577 descriptorset_allocate_info.descriptorSetCount = 1;
13578 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13579 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13580 VkDescriptorSet descriptorset;
13581 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13582
13583 // Challenge core_validation with a non uniform buffer type.
13584 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13585
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013586 char const *vsSource =
13587 "#version 450\n"
13588 "\n"
13589 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13590 " mat4 mvp;\n"
13591 "} ubuf;\n"
13592 "out gl_PerVertex {\n"
13593 " vec4 gl_Position;\n"
13594 "};\n"
13595 "void main(){\n"
13596 " gl_Position = ubuf.mvp * vec4(1);\n"
13597 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013598
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013599 char const *fsSource =
13600 "#version 450\n"
13601 "\n"
13602 "layout(location = 0) out vec4 uFragColor;\n"
13603 "void main(){\n"
13604 " uFragColor = vec4(0,1,0,1);\n"
13605 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013606
13607 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13608 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13609
13610 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13611 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13612 pipeline_layout_create_info.setLayoutCount = 1;
13613 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13614
13615 VkPipelineLayout pipeline_layout;
13616 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13617
13618 VkPipelineObj pipe(m_device);
13619 pipe.AddColorAttachment();
13620 pipe.AddShader(&vs);
13621 pipe.AddShader(&fs);
13622
13623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13624 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13625 m_errorMonitor->VerifyFound();
13626
13627 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13628 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13629 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13630}
13631
13632TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13633 TEST_DESCRIPTION(
13634 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13635
13636 ASSERT_NO_FATAL_FAILURE(InitState());
13637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13638
13639 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13640
13641 VkDescriptorPoolSize descriptor_pool_type_count = {};
13642 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13643 descriptor_pool_type_count.descriptorCount = 1;
13644
13645 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13646 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13647 descriptor_pool_create_info.maxSets = 1;
13648 descriptor_pool_create_info.poolSizeCount = 1;
13649 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13650 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13651
13652 VkDescriptorPool descriptorset_pool;
13653 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13654
13655 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13656 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13657 descriptorset_layout_binding.descriptorCount = 1;
13658 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13659 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070013660 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013661
13662 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13663 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13664 descriptorset_layout_create_info.bindingCount = 1;
13665 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13666
13667 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013668 ASSERT_VK_SUCCESS(
13669 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013670
13671 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13672 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13673 descriptorset_allocate_info.descriptorSetCount = 1;
13674 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13675 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13676 VkDescriptorSet descriptorset;
13677 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13678
13679 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13680
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013681 char const *vsSource =
13682 "#version 450\n"
13683 "\n"
13684 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13685 " mat4 mvp;\n"
13686 "} ubuf;\n"
13687 "out gl_PerVertex {\n"
13688 " vec4 gl_Position;\n"
13689 "};\n"
13690 "void main(){\n"
13691 " gl_Position = ubuf.mvp * vec4(1);\n"
13692 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013693
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013694 char const *fsSource =
13695 "#version 450\n"
13696 "\n"
13697 "layout(location = 0) out vec4 uFragColor;\n"
13698 "void main(){\n"
13699 " uFragColor = vec4(0,1,0,1);\n"
13700 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013701
13702 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13703 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13704
13705 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13706 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13707 pipeline_layout_create_info.setLayoutCount = 1;
13708 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13709
13710 VkPipelineLayout pipeline_layout;
13711 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13712
13713 VkPipelineObj pipe(m_device);
13714 pipe.AddColorAttachment();
13715 pipe.AddShader(&vs);
13716 pipe.AddShader(&fs);
13717
13718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13719 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13720 m_errorMonitor->VerifyFound();
13721
13722 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13723 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13724 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13725}
13726
13727TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013728 TEST_DESCRIPTION(
13729 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13730 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013731
13732 ASSERT_NO_FATAL_FAILURE(InitState());
13733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13734
13735 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013736 "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 -060013737
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013738 char const *vsSource =
13739 "#version 450\n"
13740 "\n"
13741 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13742 "out gl_PerVertex {\n"
13743 " vec4 gl_Position;\n"
13744 "};\n"
13745 "void main(){\n"
13746 " gl_Position = vec4(consts.x);\n"
13747 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013748
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013749 char const *fsSource =
13750 "#version 450\n"
13751 "\n"
13752 "layout(location = 0) out vec4 uFragColor;\n"
13753 "void main(){\n"
13754 " uFragColor = vec4(0,1,0,1);\n"
13755 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013756
13757 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13758 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13759
13760 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13761 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13762
13763 // Set up a push constant range
13764 VkPushConstantRange push_constant_ranges = {};
13765 // Set to the wrong stage to challenge core_validation
13766 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13767 push_constant_ranges.size = 4;
13768
13769 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13770 pipeline_layout_create_info.pushConstantRangeCount = 1;
13771
13772 VkPipelineLayout pipeline_layout;
13773 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13774
13775 VkPipelineObj pipe(m_device);
13776 pipe.AddColorAttachment();
13777 pipe.AddShader(&vs);
13778 pipe.AddShader(&fs);
13779
13780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13781 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13782 m_errorMonitor->VerifyFound();
13783
13784 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13785}
13786
13787TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13788 TEST_DESCRIPTION(
13789 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13790
13791 ASSERT_NO_FATAL_FAILURE(InitState());
13792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13793
13794 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013795 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013796
13797 // Some awkward steps are required to test with custom device features.
13798 std::vector<const char *> device_extension_names;
13799 auto features = m_device->phy().features();
13800 // Disable support for 64 bit floats
13801 features.shaderFloat64 = false;
13802 // The sacrificial device object
13803 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13804
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013805 char const *vsSource =
13806 "#version 450\n"
13807 "\n"
13808 "out gl_PerVertex {\n"
13809 " vec4 gl_Position;\n"
13810 "};\n"
13811 "void main(){\n"
13812 " gl_Position = vec4(1);\n"
13813 "}\n";
13814 char const *fsSource =
13815 "#version 450\n"
13816 "\n"
13817 "layout(location=0) out vec4 color;\n"
13818 "void main(){\n"
13819 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13820 " color = vec4(green);\n"
13821 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013822
13823 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13824 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13825
13826 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013827
13828 VkPipelineObj pipe(&test_device);
13829 pipe.AddColorAttachment();
13830 pipe.AddShader(&vs);
13831 pipe.AddShader(&fs);
13832
13833 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13834 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13835 VkPipelineLayout pipeline_layout;
13836 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13837
13838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13839 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13840 m_errorMonitor->VerifyFound();
13841
13842 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13843}
13844
13845TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13846 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13847
13848 ASSERT_NO_FATAL_FAILURE(InitState());
13849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13850
13851 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13852
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013853 char const *vsSource =
13854 "#version 450\n"
13855 "\n"
13856 "out gl_PerVertex {\n"
13857 " vec4 gl_Position;\n"
13858 "};\n"
13859 "layout(xfb_buffer = 1) out;"
13860 "void main(){\n"
13861 " gl_Position = vec4(1);\n"
13862 "}\n";
13863 char const *fsSource =
13864 "#version 450\n"
13865 "\n"
13866 "layout(location=0) out vec4 color;\n"
13867 "void main(){\n"
13868 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13869 " color = vec4(green);\n"
13870 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013871
13872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13874
13875 VkPipelineObj pipe(m_device);
13876 pipe.AddColorAttachment();
13877 pipe.AddShader(&vs);
13878 pipe.AddShader(&fs);
13879
13880 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13881 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13882 VkPipelineLayout pipeline_layout;
13883 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13884
13885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13886 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13887 m_errorMonitor->VerifyFound();
13888
13889 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13890}
13891
Karl Schultz6addd812016-02-02 17:17:23 -070013892TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013893 TEST_DESCRIPTION(
13894 "Test that an error is produced for a fragment shader input "
13895 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013898
Chris Forbes59cb88d2015-05-25 11:13:13 +120013899 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013901
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013902 char const *vsSource =
13903 "#version 450\n"
13904 "\n"
13905 "out gl_PerVertex {\n"
13906 " vec4 gl_Position;\n"
13907 "};\n"
13908 "void main(){\n"
13909 " gl_Position = vec4(1);\n"
13910 "}\n";
13911 char const *fsSource =
13912 "#version 450\n"
13913 "\n"
13914 "layout(location=0) in float x;\n"
13915 "layout(location=0) out vec4 color;\n"
13916 "void main(){\n"
13917 " color = vec4(x);\n"
13918 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013919
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013920 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13921 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013922
13923 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013924 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013925 pipe.AddShader(&vs);
13926 pipe.AddShader(&fs);
13927
Chris Forbes59cb88d2015-05-25 11:13:13 +120013928 VkDescriptorSetObj descriptorSet(m_device);
13929 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013930 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013931
Tony Barbour5781e8f2015-08-04 16:23:11 -060013932 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013933
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013934 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013935}
13936
Karl Schultz6addd812016-02-02 17:17:23 -070013937TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013938 TEST_DESCRIPTION(
13939 "Test that an error is produced for a fragment shader input "
13940 "within an interace block, which is not present in the outputs "
13941 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013943
13944 ASSERT_NO_FATAL_FAILURE(InitState());
13945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13946
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013947 char const *vsSource =
13948 "#version 450\n"
13949 "\n"
13950 "out gl_PerVertex {\n"
13951 " vec4 gl_Position;\n"
13952 "};\n"
13953 "void main(){\n"
13954 " gl_Position = vec4(1);\n"
13955 "}\n";
13956 char const *fsSource =
13957 "#version 450\n"
13958 "\n"
13959 "in block { layout(location=0) float x; } ins;\n"
13960 "layout(location=0) out vec4 color;\n"
13961 "void main(){\n"
13962 " color = vec4(ins.x);\n"
13963 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013964
13965 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13966 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13967
13968 VkPipelineObj pipe(m_device);
13969 pipe.AddColorAttachment();
13970 pipe.AddShader(&vs);
13971 pipe.AddShader(&fs);
13972
13973 VkDescriptorSetObj descriptorSet(m_device);
13974 descriptorSet.AppendDummy();
13975 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13976
13977 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13978
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013979 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013980}
13981
Karl Schultz6addd812016-02-02 17:17:23 -070013982TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013983 TEST_DESCRIPTION(
13984 "Test that an error is produced for mismatched array sizes "
13985 "across the vertex->fragment shader interface");
13986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13987 "Type mismatch on location 0.0: 'ptr to "
13988 "output arr[2] of float32' vs 'ptr to "
13989 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013990
13991 ASSERT_NO_FATAL_FAILURE(InitState());
13992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13993
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013994 char const *vsSource =
13995 "#version 450\n"
13996 "\n"
13997 "layout(location=0) out float x[2];\n"
13998 "out gl_PerVertex {\n"
13999 " vec4 gl_Position;\n"
14000 "};\n"
14001 "void main(){\n"
14002 " x[0] = 0; x[1] = 0;\n"
14003 " gl_Position = vec4(1);\n"
14004 "}\n";
14005 char const *fsSource =
14006 "#version 450\n"
14007 "\n"
14008 "layout(location=0) in float x[1];\n"
14009 "layout(location=0) out vec4 color;\n"
14010 "void main(){\n"
14011 " color = vec4(x[0]);\n"
14012 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014013
14014 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14015 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14016
14017 VkPipelineObj pipe(m_device);
14018 pipe.AddColorAttachment();
14019 pipe.AddShader(&vs);
14020 pipe.AddShader(&fs);
14021
14022 VkDescriptorSetObj descriptorSet(m_device);
14023 descriptorSet.AppendDummy();
14024 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14025
14026 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14027
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014028 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014029}
14030
Karl Schultz6addd812016-02-02 17:17:23 -070014031TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014032 TEST_DESCRIPTION(
14033 "Test that an error is produced for mismatched types across "
14034 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014036
Chris Forbesb56af562015-05-25 11:13:17 +120014037 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014039
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014040 char const *vsSource =
14041 "#version 450\n"
14042 "\n"
14043 "layout(location=0) out int x;\n"
14044 "out gl_PerVertex {\n"
14045 " vec4 gl_Position;\n"
14046 "};\n"
14047 "void main(){\n"
14048 " x = 0;\n"
14049 " gl_Position = vec4(1);\n"
14050 "}\n";
14051 char const *fsSource =
14052 "#version 450\n"
14053 "\n"
14054 "layout(location=0) in float x;\n" /* VS writes int */
14055 "layout(location=0) out vec4 color;\n"
14056 "void main(){\n"
14057 " color = vec4(x);\n"
14058 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014059
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014060 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14061 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014062
14063 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014064 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014065 pipe.AddShader(&vs);
14066 pipe.AddShader(&fs);
14067
Chris Forbesb56af562015-05-25 11:13:17 +120014068 VkDescriptorSetObj descriptorSet(m_device);
14069 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014070 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014071
Tony Barbour5781e8f2015-08-04 16:23:11 -060014072 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014073
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014074 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014075}
14076
Karl Schultz6addd812016-02-02 17:17:23 -070014077TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014078 TEST_DESCRIPTION(
14079 "Test that an error is produced for mismatched types across "
14080 "the vertex->fragment shader interface, when the variable is contained within "
14081 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014083
14084 ASSERT_NO_FATAL_FAILURE(InitState());
14085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14086
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014087 char const *vsSource =
14088 "#version 450\n"
14089 "\n"
14090 "out block { layout(location=0) int x; } outs;\n"
14091 "out gl_PerVertex {\n"
14092 " vec4 gl_Position;\n"
14093 "};\n"
14094 "void main(){\n"
14095 " outs.x = 0;\n"
14096 " gl_Position = vec4(1);\n"
14097 "}\n";
14098 char const *fsSource =
14099 "#version 450\n"
14100 "\n"
14101 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14102 "layout(location=0) out vec4 color;\n"
14103 "void main(){\n"
14104 " color = vec4(ins.x);\n"
14105 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014106
14107 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14108 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14109
14110 VkPipelineObj pipe(m_device);
14111 pipe.AddColorAttachment();
14112 pipe.AddShader(&vs);
14113 pipe.AddShader(&fs);
14114
14115 VkDescriptorSetObj descriptorSet(m_device);
14116 descriptorSet.AppendDummy();
14117 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14118
14119 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14120
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014121 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014122}
14123
14124TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014125 TEST_DESCRIPTION(
14126 "Test that an error is produced for location mismatches across "
14127 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14128 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014129 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 +130014130
14131 ASSERT_NO_FATAL_FAILURE(InitState());
14132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14133
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014134 char const *vsSource =
14135 "#version 450\n"
14136 "\n"
14137 "out block { layout(location=1) float x; } outs;\n"
14138 "out gl_PerVertex {\n"
14139 " vec4 gl_Position;\n"
14140 "};\n"
14141 "void main(){\n"
14142 " outs.x = 0;\n"
14143 " gl_Position = vec4(1);\n"
14144 "}\n";
14145 char const *fsSource =
14146 "#version 450\n"
14147 "\n"
14148 "in block { layout(location=0) float x; } ins;\n"
14149 "layout(location=0) out vec4 color;\n"
14150 "void main(){\n"
14151 " color = vec4(ins.x);\n"
14152 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014153
14154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14156
14157 VkPipelineObj pipe(m_device);
14158 pipe.AddColorAttachment();
14159 pipe.AddShader(&vs);
14160 pipe.AddShader(&fs);
14161
14162 VkDescriptorSetObj descriptorSet(m_device);
14163 descriptorSet.AppendDummy();
14164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14165
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014166 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014167 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14168
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014169 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014170}
14171
14172TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014173 TEST_DESCRIPTION(
14174 "Test that an error is produced for component mismatches across the "
14175 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14176 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014177 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 +130014178
14179 ASSERT_NO_FATAL_FAILURE(InitState());
14180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14181
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014182 char const *vsSource =
14183 "#version 450\n"
14184 "\n"
14185 "out block { layout(location=0, component=0) float x; } outs;\n"
14186 "out gl_PerVertex {\n"
14187 " vec4 gl_Position;\n"
14188 "};\n"
14189 "void main(){\n"
14190 " outs.x = 0;\n"
14191 " gl_Position = vec4(1);\n"
14192 "}\n";
14193 char const *fsSource =
14194 "#version 450\n"
14195 "\n"
14196 "in block { layout(location=0, component=1) float x; } ins;\n"
14197 "layout(location=0) out vec4 color;\n"
14198 "void main(){\n"
14199 " color = vec4(ins.x);\n"
14200 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014201
14202 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14203 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14204
14205 VkPipelineObj pipe(m_device);
14206 pipe.AddColorAttachment();
14207 pipe.AddShader(&vs);
14208 pipe.AddShader(&fs);
14209
14210 VkDescriptorSetObj descriptorSet(m_device);
14211 descriptorSet.AppendDummy();
14212 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14213
14214 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14215
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014216 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014217}
14218
Chris Forbes1f3b0152016-11-30 12:48:40 +130014219TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14220 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14221
14222 ASSERT_NO_FATAL_FAILURE(InitState());
14223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14224
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014225 char const *vsSource =
14226 "#version 450\n"
14227 "layout(location=0) out mediump float x;\n"
14228 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14229 char const *fsSource =
14230 "#version 450\n"
14231 "layout(location=0) in highp float x;\n"
14232 "layout(location=0) out vec4 color;\n"
14233 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014234
14235 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14236 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14237
14238 VkPipelineObj pipe(m_device);
14239 pipe.AddColorAttachment();
14240 pipe.AddShader(&vs);
14241 pipe.AddShader(&fs);
14242
14243 VkDescriptorSetObj descriptorSet(m_device);
14244 descriptorSet.AppendDummy();
14245 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14246
14247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14248
14249 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14250
14251 m_errorMonitor->VerifyFound();
14252}
14253
Chris Forbes870a39e2016-11-30 12:55:56 +130014254TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14255 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14256
14257 ASSERT_NO_FATAL_FAILURE(InitState());
14258 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14259
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014260 char const *vsSource =
14261 "#version 450\n"
14262 "out block { layout(location=0) mediump float x; };\n"
14263 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14264 char const *fsSource =
14265 "#version 450\n"
14266 "in block { layout(location=0) highp float x; };\n"
14267 "layout(location=0) out vec4 color;\n"
14268 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014269
14270 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14271 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14272
14273 VkPipelineObj pipe(m_device);
14274 pipe.AddColorAttachment();
14275 pipe.AddShader(&vs);
14276 pipe.AddShader(&fs);
14277
14278 VkDescriptorSetObj descriptorSet(m_device);
14279 descriptorSet.AppendDummy();
14280 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14281
14282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14283
14284 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14285
14286 m_errorMonitor->VerifyFound();
14287}
14288
Karl Schultz6addd812016-02-02 17:17:23 -070014289TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014290 TEST_DESCRIPTION(
14291 "Test that a warning is produced for a vertex attribute which is "
14292 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014294
Chris Forbesde136e02015-05-25 11:13:28 +120014295 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014297
14298 VkVertexInputBindingDescription input_binding;
14299 memset(&input_binding, 0, sizeof(input_binding));
14300
14301 VkVertexInputAttributeDescription input_attrib;
14302 memset(&input_attrib, 0, sizeof(input_attrib));
14303 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14304
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014305 char const *vsSource =
14306 "#version 450\n"
14307 "\n"
14308 "out gl_PerVertex {\n"
14309 " vec4 gl_Position;\n"
14310 "};\n"
14311 "void main(){\n"
14312 " gl_Position = vec4(1);\n"
14313 "}\n";
14314 char const *fsSource =
14315 "#version 450\n"
14316 "\n"
14317 "layout(location=0) out vec4 color;\n"
14318 "void main(){\n"
14319 " color = vec4(1);\n"
14320 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014321
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014322 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14323 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014324
14325 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014326 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014327 pipe.AddShader(&vs);
14328 pipe.AddShader(&fs);
14329
14330 pipe.AddVertexInputBindings(&input_binding, 1);
14331 pipe.AddVertexInputAttribs(&input_attrib, 1);
14332
Chris Forbesde136e02015-05-25 11:13:28 +120014333 VkDescriptorSetObj descriptorSet(m_device);
14334 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014335 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014336
Tony Barbour5781e8f2015-08-04 16:23:11 -060014337 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014338
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014339 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014340}
14341
Karl Schultz6addd812016-02-02 17:17:23 -070014342TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014343 TEST_DESCRIPTION(
14344 "Test that a warning is produced for a location mismatch on "
14345 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014347
14348 ASSERT_NO_FATAL_FAILURE(InitState());
14349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14350
14351 VkVertexInputBindingDescription input_binding;
14352 memset(&input_binding, 0, sizeof(input_binding));
14353
14354 VkVertexInputAttributeDescription input_attrib;
14355 memset(&input_attrib, 0, sizeof(input_attrib));
14356 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14357
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014358 char const *vsSource =
14359 "#version 450\n"
14360 "\n"
14361 "layout(location=1) in float x;\n"
14362 "out gl_PerVertex {\n"
14363 " vec4 gl_Position;\n"
14364 "};\n"
14365 "void main(){\n"
14366 " gl_Position = vec4(x);\n"
14367 "}\n";
14368 char const *fsSource =
14369 "#version 450\n"
14370 "\n"
14371 "layout(location=0) out vec4 color;\n"
14372 "void main(){\n"
14373 " color = vec4(1);\n"
14374 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014375
14376 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14377 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14378
14379 VkPipelineObj pipe(m_device);
14380 pipe.AddColorAttachment();
14381 pipe.AddShader(&vs);
14382 pipe.AddShader(&fs);
14383
14384 pipe.AddVertexInputBindings(&input_binding, 1);
14385 pipe.AddVertexInputAttribs(&input_attrib, 1);
14386
14387 VkDescriptorSetObj descriptorSet(m_device);
14388 descriptorSet.AppendDummy();
14389 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14390
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014391 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014392 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14393
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014394 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014395}
14396
Karl Schultz6addd812016-02-02 17:17:23 -070014397TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014398 TEST_DESCRIPTION(
14399 "Test that an error is produced for a vertex shader input which is not "
14400 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14402 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014403
Chris Forbes62e8e502015-05-25 11:13:29 +120014404 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014406
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014407 char const *vsSource =
14408 "#version 450\n"
14409 "\n"
14410 "layout(location=0) in vec4 x;\n" /* not provided */
14411 "out gl_PerVertex {\n"
14412 " vec4 gl_Position;\n"
14413 "};\n"
14414 "void main(){\n"
14415 " gl_Position = x;\n"
14416 "}\n";
14417 char const *fsSource =
14418 "#version 450\n"
14419 "\n"
14420 "layout(location=0) out vec4 color;\n"
14421 "void main(){\n"
14422 " color = vec4(1);\n"
14423 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014424
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014427
14428 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014429 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014430 pipe.AddShader(&vs);
14431 pipe.AddShader(&fs);
14432
Chris Forbes62e8e502015-05-25 11:13:29 +120014433 VkDescriptorSetObj descriptorSet(m_device);
14434 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014435 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014436
Tony Barbour5781e8f2015-08-04 16:23:11 -060014437 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014438
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014439 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014440}
14441
Karl Schultz6addd812016-02-02 17:17:23 -070014442TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014443 TEST_DESCRIPTION(
14444 "Test that an error is produced for a mismatch between the "
14445 "fundamental type (float/int/uint) of an attribute and the "
14446 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014447 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 -060014448
Chris Forbesc97d98e2015-05-25 11:13:31 +120014449 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014451
14452 VkVertexInputBindingDescription input_binding;
14453 memset(&input_binding, 0, sizeof(input_binding));
14454
14455 VkVertexInputAttributeDescription input_attrib;
14456 memset(&input_attrib, 0, sizeof(input_attrib));
14457 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14458
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014459 char const *vsSource =
14460 "#version 450\n"
14461 "\n"
14462 "layout(location=0) in int x;\n" /* attrib provided float */
14463 "out gl_PerVertex {\n"
14464 " vec4 gl_Position;\n"
14465 "};\n"
14466 "void main(){\n"
14467 " gl_Position = vec4(x);\n"
14468 "}\n";
14469 char const *fsSource =
14470 "#version 450\n"
14471 "\n"
14472 "layout(location=0) out vec4 color;\n"
14473 "void main(){\n"
14474 " color = vec4(1);\n"
14475 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014476
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014477 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14478 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014479
14480 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014481 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014482 pipe.AddShader(&vs);
14483 pipe.AddShader(&fs);
14484
14485 pipe.AddVertexInputBindings(&input_binding, 1);
14486 pipe.AddVertexInputAttribs(&input_attrib, 1);
14487
Chris Forbesc97d98e2015-05-25 11:13:31 +120014488 VkDescriptorSetObj descriptorSet(m_device);
14489 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014490 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014491
Tony Barbour5781e8f2015-08-04 16:23:11 -060014492 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014493
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014494 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014495}
14496
Chris Forbesc68b43c2016-04-06 11:18:47 +120014497TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014498 TEST_DESCRIPTION(
14499 "Test that an error is produced for a pipeline containing multiple "
14500 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14502 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014503
14504 ASSERT_NO_FATAL_FAILURE(InitState());
14505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014507 char const *vsSource =
14508 "#version 450\n"
14509 "\n"
14510 "out gl_PerVertex {\n"
14511 " vec4 gl_Position;\n"
14512 "};\n"
14513 "void main(){\n"
14514 " gl_Position = vec4(1);\n"
14515 "}\n";
14516 char const *fsSource =
14517 "#version 450\n"
14518 "\n"
14519 "layout(location=0) out vec4 color;\n"
14520 "void main(){\n"
14521 " color = vec4(1);\n"
14522 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014523
14524 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14525 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14526
14527 VkPipelineObj pipe(m_device);
14528 pipe.AddColorAttachment();
14529 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014530 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014531 pipe.AddShader(&fs);
14532
14533 VkDescriptorSetObj descriptorSet(m_device);
14534 descriptorSet.AppendDummy();
14535 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14536
14537 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14538
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014539 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014540}
14541
Chris Forbes82ff92a2016-09-09 10:50:24 +120014542TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014544
14545 ASSERT_NO_FATAL_FAILURE(InitState());
14546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14547
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014548 char const *vsSource =
14549 "#version 450\n"
14550 "out gl_PerVertex {\n"
14551 " vec4 gl_Position;\n"
14552 "};\n"
14553 "void main(){\n"
14554 " gl_Position = vec4(0);\n"
14555 "}\n";
14556 char const *fsSource =
14557 "#version 450\n"
14558 "\n"
14559 "layout(location=0) out vec4 color;\n"
14560 "void main(){\n"
14561 " color = vec4(1);\n"
14562 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014563
14564 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14565 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14566
14567 VkPipelineObj pipe(m_device);
14568 pipe.AddColorAttachment();
14569 pipe.AddShader(&vs);
14570 pipe.AddShader(&fs);
14571
14572 VkDescriptorSetObj descriptorSet(m_device);
14573 descriptorSet.AppendDummy();
14574 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14575
14576 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14577
14578 m_errorMonitor->VerifyFound();
14579}
14580
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014581TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14583 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14584 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014585
14586 ASSERT_NO_FATAL_FAILURE(InitState());
14587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14588
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014589 char const *vsSource =
14590 "#version 450\n"
14591 "void main(){ gl_Position = vec4(0); }\n";
14592 char const *fsSource =
14593 "#version 450\n"
14594 "\n"
14595 "layout(location=0) out vec4 color;\n"
14596 "void main(){\n"
14597 " color = vec4(1);\n"
14598 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014599
14600 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14601 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14602
14603 VkPipelineObj pipe(m_device);
14604 pipe.AddColorAttachment();
14605 pipe.AddShader(&vs);
14606 pipe.AddShader(&fs);
14607
14608 VkDescriptorSetObj descriptorSet(m_device);
14609 descriptorSet.AppendDummy();
14610 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14611
14612 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014613 {
14614 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14615 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14616 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014617 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014618 {
14619 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14620 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14621 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014622 },
14623 };
14624 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014625 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014626 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014627 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14628 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014629 VkRenderPass rp;
14630 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14631 ASSERT_VK_SUCCESS(err);
14632
14633 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14634
14635 m_errorMonitor->VerifyFound();
14636
14637 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14638}
14639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014640TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014641 TEST_DESCRIPTION(
14642 "Test that an error is produced for a variable output from "
14643 "the TCS without the patch decoration, but consumed in the TES "
14644 "with the decoration.");
14645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14646 "is per-vertex in tessellation control shader stage "
14647 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014648
14649 ASSERT_NO_FATAL_FAILURE(InitState());
14650 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14651
Chris Forbesc1e852d2016-04-04 19:26:42 +120014652 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014653 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014654 return;
14655 }
14656
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014657 char const *vsSource =
14658 "#version 450\n"
14659 "void main(){}\n";
14660 char const *tcsSource =
14661 "#version 450\n"
14662 "layout(location=0) out int x[];\n"
14663 "layout(vertices=3) out;\n"
14664 "void main(){\n"
14665 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14666 " gl_TessLevelInner[0] = 1;\n"
14667 " x[gl_InvocationID] = gl_InvocationID;\n"
14668 "}\n";
14669 char const *tesSource =
14670 "#version 450\n"
14671 "layout(triangles, equal_spacing, cw) in;\n"
14672 "layout(location=0) patch in int x;\n"
14673 "out gl_PerVertex { vec4 gl_Position; };\n"
14674 "void main(){\n"
14675 " gl_Position.xyz = gl_TessCoord;\n"
14676 " gl_Position.w = x;\n"
14677 "}\n";
14678 char const *fsSource =
14679 "#version 450\n"
14680 "layout(location=0) out vec4 color;\n"
14681 "void main(){\n"
14682 " color = vec4(1);\n"
14683 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014684
14685 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14686 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14687 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14688 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14689
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014690 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14691 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014693 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014694
14695 VkPipelineObj pipe(m_device);
14696 pipe.SetInputAssembly(&iasci);
14697 pipe.SetTessellation(&tsci);
14698 pipe.AddColorAttachment();
14699 pipe.AddShader(&vs);
14700 pipe.AddShader(&tcs);
14701 pipe.AddShader(&tes);
14702 pipe.AddShader(&fs);
14703
14704 VkDescriptorSetObj descriptorSet(m_device);
14705 descriptorSet.AppendDummy();
14706 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14707
14708 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14709
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014710 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014711}
14712
Karl Schultz6addd812016-02-02 17:17:23 -070014713TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014714 TEST_DESCRIPTION(
14715 "Test that an error is produced for a vertex attribute setup where multiple "
14716 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14718 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014719
Chris Forbes280ba2c2015-06-12 11:16:41 +120014720 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014722
14723 /* Two binding descriptions for binding 0 */
14724 VkVertexInputBindingDescription input_bindings[2];
14725 memset(input_bindings, 0, sizeof(input_bindings));
14726
14727 VkVertexInputAttributeDescription input_attrib;
14728 memset(&input_attrib, 0, sizeof(input_attrib));
14729 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14730
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014731 char const *vsSource =
14732 "#version 450\n"
14733 "\n"
14734 "layout(location=0) in float x;\n" /* attrib provided float */
14735 "out gl_PerVertex {\n"
14736 " vec4 gl_Position;\n"
14737 "};\n"
14738 "void main(){\n"
14739 " gl_Position = vec4(x);\n"
14740 "}\n";
14741 char const *fsSource =
14742 "#version 450\n"
14743 "\n"
14744 "layout(location=0) out vec4 color;\n"
14745 "void main(){\n"
14746 " color = vec4(1);\n"
14747 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014748
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014749 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14750 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014751
14752 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014753 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014754 pipe.AddShader(&vs);
14755 pipe.AddShader(&fs);
14756
14757 pipe.AddVertexInputBindings(input_bindings, 2);
14758 pipe.AddVertexInputAttribs(&input_attrib, 1);
14759
Chris Forbes280ba2c2015-06-12 11:16:41 +120014760 VkDescriptorSetObj descriptorSet(m_device);
14761 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014762 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014763
Tony Barbour5781e8f2015-08-04 16:23:11 -060014764 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014765
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014766 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014767}
Chris Forbes8f68b562015-05-25 11:13:32 +120014768
Karl Schultz6addd812016-02-02 17:17:23 -070014769TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014770 TEST_DESCRIPTION(
14771 "Test that an error is produced for a fragment shader which does not "
14772 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014774
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014775 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014776
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014777 char const *vsSource =
14778 "#version 450\n"
14779 "\n"
14780 "out gl_PerVertex {\n"
14781 " vec4 gl_Position;\n"
14782 "};\n"
14783 "void main(){\n"
14784 " gl_Position = vec4(1);\n"
14785 "}\n";
14786 char const *fsSource =
14787 "#version 450\n"
14788 "\n"
14789 "void main(){\n"
14790 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014791
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014792 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14793 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014794
14795 VkPipelineObj pipe(m_device);
14796 pipe.AddShader(&vs);
14797 pipe.AddShader(&fs);
14798
Chia-I Wu08accc62015-07-07 11:50:03 +080014799 /* set up CB 0, not written */
14800 pipe.AddColorAttachment();
14801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014802
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014803 VkDescriptorSetObj descriptorSet(m_device);
14804 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014805 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014806
Tony Barbour5781e8f2015-08-04 16:23:11 -060014807 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014808
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014809 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014810}
14811
Karl Schultz6addd812016-02-02 17:17:23 -070014812TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014813 TEST_DESCRIPTION(
14814 "Test that a warning is produced for a fragment shader which provides a spurious "
14815 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014817 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014818
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014819 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014820
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014821 char const *vsSource =
14822 "#version 450\n"
14823 "\n"
14824 "out gl_PerVertex {\n"
14825 " vec4 gl_Position;\n"
14826 "};\n"
14827 "void main(){\n"
14828 " gl_Position = vec4(1);\n"
14829 "}\n";
14830 char const *fsSource =
14831 "#version 450\n"
14832 "\n"
14833 "layout(location=0) out vec4 x;\n"
14834 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14835 "void main(){\n"
14836 " x = vec4(1);\n"
14837 " y = vec4(1);\n"
14838 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014839
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014840 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14841 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014842
14843 VkPipelineObj pipe(m_device);
14844 pipe.AddShader(&vs);
14845 pipe.AddShader(&fs);
14846
Chia-I Wu08accc62015-07-07 11:50:03 +080014847 /* set up CB 0, not written */
14848 pipe.AddColorAttachment();
14849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014850 /* FS writes CB 1, but we don't configure it */
14851
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014852 VkDescriptorSetObj descriptorSet(m_device);
14853 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014854 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014855
Tony Barbour5781e8f2015-08-04 16:23:11 -060014856 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014857
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014858 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014859}
14860
Karl Schultz6addd812016-02-02 17:17:23 -070014861TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014862 TEST_DESCRIPTION(
14863 "Test that an error is produced for a mismatch between the fundamental "
14864 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014866
Chris Forbesa36d69e2015-05-25 11:13:44 +120014867 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014868
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014869 char const *vsSource =
14870 "#version 450\n"
14871 "\n"
14872 "out gl_PerVertex {\n"
14873 " vec4 gl_Position;\n"
14874 "};\n"
14875 "void main(){\n"
14876 " gl_Position = vec4(1);\n"
14877 "}\n";
14878 char const *fsSource =
14879 "#version 450\n"
14880 "\n"
14881 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14882 "void main(){\n"
14883 " x = ivec4(1);\n"
14884 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014885
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014886 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14887 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014888
14889 VkPipelineObj pipe(m_device);
14890 pipe.AddShader(&vs);
14891 pipe.AddShader(&fs);
14892
Chia-I Wu08accc62015-07-07 11:50:03 +080014893 /* set up CB 0; type is UNORM by default */
14894 pipe.AddColorAttachment();
14895 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014896
Chris Forbesa36d69e2015-05-25 11:13:44 +120014897 VkDescriptorSetObj descriptorSet(m_device);
14898 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014899 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014900
Tony Barbour5781e8f2015-08-04 16:23:11 -060014901 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014902
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014903 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014904}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014905
Karl Schultz6addd812016-02-02 17:17:23 -070014906TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014907 TEST_DESCRIPTION(
14908 "Test that an error is produced for a shader consuming a uniform "
14909 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014911
Chris Forbes556c76c2015-08-14 12:04:59 +120014912 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014913
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014914 char const *vsSource =
14915 "#version 450\n"
14916 "\n"
14917 "out gl_PerVertex {\n"
14918 " vec4 gl_Position;\n"
14919 "};\n"
14920 "void main(){\n"
14921 " gl_Position = vec4(1);\n"
14922 "}\n";
14923 char const *fsSource =
14924 "#version 450\n"
14925 "\n"
14926 "layout(location=0) out vec4 x;\n"
14927 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14928 "void main(){\n"
14929 " x = vec4(bar.y);\n"
14930 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014931
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014932 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14933 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014934
Chris Forbes556c76c2015-08-14 12:04:59 +120014935 VkPipelineObj pipe(m_device);
14936 pipe.AddShader(&vs);
14937 pipe.AddShader(&fs);
14938
14939 /* set up CB 0; type is UNORM by default */
14940 pipe.AddColorAttachment();
14941 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14942
14943 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014944 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014945
14946 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014948 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014949}
14950
Chris Forbes5c59e902016-02-26 16:56:09 +130014951TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014952 TEST_DESCRIPTION(
14953 "Test that an error is produced for a shader consuming push constants "
14954 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014956
14957 ASSERT_NO_FATAL_FAILURE(InitState());
14958
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014959 char const *vsSource =
14960 "#version 450\n"
14961 "\n"
14962 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14963 "out gl_PerVertex {\n"
14964 " vec4 gl_Position;\n"
14965 "};\n"
14966 "void main(){\n"
14967 " gl_Position = vec4(consts.x);\n"
14968 "}\n";
14969 char const *fsSource =
14970 "#version 450\n"
14971 "\n"
14972 "layout(location=0) out vec4 x;\n"
14973 "void main(){\n"
14974 " x = vec4(1);\n"
14975 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014976
14977 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14978 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14979
14980 VkPipelineObj pipe(m_device);
14981 pipe.AddShader(&vs);
14982 pipe.AddShader(&fs);
14983
14984 /* set up CB 0; type is UNORM by default */
14985 pipe.AddColorAttachment();
14986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14987
14988 VkDescriptorSetObj descriptorSet(m_device);
14989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14990
14991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14992
14993 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014994 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014995}
14996
Chris Forbes3fb17902016-08-22 14:57:55 +120014997TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014998 TEST_DESCRIPTION(
14999 "Test that an error is produced for a shader consuming an input attachment "
15000 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15002 "consumes input attachment index 0 but not provided in subpass");
15003
15004 ASSERT_NO_FATAL_FAILURE(InitState());
15005
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015006 char const *vsSource =
15007 "#version 450\n"
15008 "\n"
15009 "out gl_PerVertex {\n"
15010 " vec4 gl_Position;\n"
15011 "};\n"
15012 "void main(){\n"
15013 " gl_Position = vec4(1);\n"
15014 "}\n";
15015 char const *fsSource =
15016 "#version 450\n"
15017 "\n"
15018 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15019 "layout(location=0) out vec4 color;\n"
15020 "void main() {\n"
15021 " color = subpassLoad(x);\n"
15022 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015023
15024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15026
15027 VkPipelineObj pipe(m_device);
15028 pipe.AddShader(&vs);
15029 pipe.AddShader(&fs);
15030 pipe.AddColorAttachment();
15031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015033 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15034 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015035 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015036 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015037 ASSERT_VK_SUCCESS(err);
15038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015039 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015040 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015042 ASSERT_VK_SUCCESS(err);
15043
15044 // error here.
15045 pipe.CreateVKPipeline(pl, renderPass());
15046
15047 m_errorMonitor->VerifyFound();
15048
15049 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15050 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15051}
15052
Chris Forbes5a9a0472016-08-22 16:02:09 +120015053TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015054 TEST_DESCRIPTION(
15055 "Test that an error is produced for a shader consuming an input attachment "
15056 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15058 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15059
15060 ASSERT_NO_FATAL_FAILURE(InitState());
15061
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015062 char const *vsSource =
15063 "#version 450\n"
15064 "\n"
15065 "out gl_PerVertex {\n"
15066 " vec4 gl_Position;\n"
15067 "};\n"
15068 "void main(){\n"
15069 " gl_Position = vec4(1);\n"
15070 "}\n";
15071 char const *fsSource =
15072 "#version 450\n"
15073 "\n"
15074 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15075 "layout(location=0) out vec4 color;\n"
15076 "void main() {\n"
15077 " color = subpassLoad(x);\n"
15078 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015079
15080 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15081 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15082
15083 VkPipelineObj pipe(m_device);
15084 pipe.AddShader(&vs);
15085 pipe.AddShader(&fs);
15086 pipe.AddColorAttachment();
15087 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015089 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15090 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015091 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015092 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015093 ASSERT_VK_SUCCESS(err);
15094
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015095 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015096 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015097 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015098 ASSERT_VK_SUCCESS(err);
15099
15100 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015101 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15102 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15103 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15104 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15105 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 +120015106 };
15107 VkAttachmentReference color = {
15108 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15109 };
15110 VkAttachmentReference input = {
15111 1, VK_IMAGE_LAYOUT_GENERAL,
15112 };
15113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015114 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015116 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015117 VkRenderPass rp;
15118 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15119 ASSERT_VK_SUCCESS(err);
15120
15121 // error here.
15122 pipe.CreateVKPipeline(pl, rp);
15123
15124 m_errorMonitor->VerifyFound();
15125
15126 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15127 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15128 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15129}
15130
Chris Forbes541f7b02016-08-22 15:30:27 +120015131TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015132 TEST_DESCRIPTION(
15133 "Test that an error is produced for a shader consuming an input attachment "
15134 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015136 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015137
15138 ASSERT_NO_FATAL_FAILURE(InitState());
15139
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015140 char const *vsSource =
15141 "#version 450\n"
15142 "\n"
15143 "out gl_PerVertex {\n"
15144 " vec4 gl_Position;\n"
15145 "};\n"
15146 "void main(){\n"
15147 " gl_Position = vec4(1);\n"
15148 "}\n";
15149 char const *fsSource =
15150 "#version 450\n"
15151 "\n"
15152 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15153 "layout(location=0) out vec4 color;\n"
15154 "void main() {\n"
15155 " color = subpassLoad(xs[0]);\n"
15156 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015157
15158 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15159 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15160
15161 VkPipelineObj pipe(m_device);
15162 pipe.AddShader(&vs);
15163 pipe.AddShader(&fs);
15164 pipe.AddColorAttachment();
15165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015167 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15168 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015169 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015170 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015171 ASSERT_VK_SUCCESS(err);
15172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015173 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015174 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015176 ASSERT_VK_SUCCESS(err);
15177
15178 // error here.
15179 pipe.CreateVKPipeline(pl, renderPass());
15180
15181 m_errorMonitor->VerifyFound();
15182
15183 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15184 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15185}
15186
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015187TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015188 TEST_DESCRIPTION(
15189 "Test that an error is produced for a compute pipeline consuming a "
15190 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015192
15193 ASSERT_NO_FATAL_FAILURE(InitState());
15194
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015195 char const *csSource =
15196 "#version 450\n"
15197 "\n"
15198 "layout(local_size_x=1) in;\n"
15199 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15200 "void main(){\n"
15201 " x = vec4(1);\n"
15202 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015203
15204 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15205
15206 VkDescriptorSetObj descriptorSet(m_device);
15207 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15208
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015209 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15210 nullptr,
15211 0,
15212 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15213 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15214 descriptorSet.GetPipelineLayout(),
15215 VK_NULL_HANDLE,
15216 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015217
15218 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015219 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015220
15221 m_errorMonitor->VerifyFound();
15222
15223 if (err == VK_SUCCESS) {
15224 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15225 }
15226}
15227
Chris Forbes22a9b092016-07-19 14:34:05 +120015228TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015229 TEST_DESCRIPTION(
15230 "Test that an error is produced for a pipeline consuming a "
15231 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15233 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015234
15235 ASSERT_NO_FATAL_FAILURE(InitState());
15236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015237 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15238 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015239 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015240 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015241 ASSERT_VK_SUCCESS(err);
15242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015243 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015244 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015245 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015246 ASSERT_VK_SUCCESS(err);
15247
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015248 char const *csSource =
15249 "#version 450\n"
15250 "\n"
15251 "layout(local_size_x=1) in;\n"
15252 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15253 "void main() {\n"
15254 " x.x = 1.0f;\n"
15255 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015256 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015258 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15259 nullptr,
15260 0,
15261 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15262 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15263 pl,
15264 VK_NULL_HANDLE,
15265 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015266
15267 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015268 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015269
15270 m_errorMonitor->VerifyFound();
15271
15272 if (err == VK_SUCCESS) {
15273 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15274 }
15275
15276 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15277 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15278}
15279
Chris Forbes50020592016-07-27 13:52:41 +120015280TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015281 TEST_DESCRIPTION(
15282 "Test that an error is produced when an image view type "
15283 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015285 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 +120015286
15287 ASSERT_NO_FATAL_FAILURE(InitState());
15288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15289
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015290 char const *vsSource =
15291 "#version 450\n"
15292 "\n"
15293 "out gl_PerVertex { vec4 gl_Position; };\n"
15294 "void main() { gl_Position = vec4(0); }\n";
15295 char const *fsSource =
15296 "#version 450\n"
15297 "\n"
15298 "layout(set=0, binding=0) uniform sampler3D s;\n"
15299 "layout(location=0) out vec4 color;\n"
15300 "void main() {\n"
15301 " color = texture(s, vec3(0));\n"
15302 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015303 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15304 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15305
15306 VkPipelineObj pipe(m_device);
15307 pipe.AddShader(&vs);
15308 pipe.AddShader(&fs);
15309 pipe.AddColorAttachment();
15310
15311 VkTextureObj texture(m_device, nullptr);
15312 VkSamplerObj sampler(m_device);
15313
15314 VkDescriptorSetObj descriptorSet(m_device);
15315 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15316 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15317
15318 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15319 ASSERT_VK_SUCCESS(err);
15320
Tony Barbour552f6c02016-12-21 14:34:07 -070015321 m_commandBuffer->BeginCommandBuffer();
15322 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015323
15324 m_commandBuffer->BindPipeline(pipe);
15325 m_commandBuffer->BindDescriptorSet(descriptorSet);
15326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015327 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015328 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015329 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015330 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15331
15332 // error produced here.
15333 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15334
15335 m_errorMonitor->VerifyFound();
15336
Tony Barbour552f6c02016-12-21 14:34:07 -070015337 m_commandBuffer->EndRenderPass();
15338 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015339}
15340
Chris Forbes5533bfc2016-07-27 14:12:34 +120015341TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015342 TEST_DESCRIPTION(
15343 "Test that an error is produced when a multisampled images "
15344 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015347
15348 ASSERT_NO_FATAL_FAILURE(InitState());
15349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15350
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015351 char const *vsSource =
15352 "#version 450\n"
15353 "\n"
15354 "out gl_PerVertex { vec4 gl_Position; };\n"
15355 "void main() { gl_Position = vec4(0); }\n";
15356 char const *fsSource =
15357 "#version 450\n"
15358 "\n"
15359 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15360 "layout(location=0) out vec4 color;\n"
15361 "void main() {\n"
15362 " color = texelFetch(s, ivec2(0), 0);\n"
15363 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015364 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15365 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15366
15367 VkPipelineObj pipe(m_device);
15368 pipe.AddShader(&vs);
15369 pipe.AddShader(&fs);
15370 pipe.AddColorAttachment();
15371
15372 VkTextureObj texture(m_device, nullptr);
15373 VkSamplerObj sampler(m_device);
15374
15375 VkDescriptorSetObj descriptorSet(m_device);
15376 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15377 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15378
15379 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15380 ASSERT_VK_SUCCESS(err);
15381
Tony Barbour552f6c02016-12-21 14:34:07 -070015382 m_commandBuffer->BeginCommandBuffer();
15383 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015384
15385 m_commandBuffer->BindPipeline(pipe);
15386 m_commandBuffer->BindDescriptorSet(descriptorSet);
15387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015388 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015389 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015390 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015391 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15392
15393 // error produced here.
15394 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15395
15396 m_errorMonitor->VerifyFound();
15397
Tony Barbour552f6c02016-12-21 14:34:07 -070015398 m_commandBuffer->EndRenderPass();
15399 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015400}
15401
Mark Youngc48c4c12016-04-11 14:26:49 -060015402TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015404
15405 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015406
15407 // Create an image
15408 VkImage image;
15409
Karl Schultz6addd812016-02-02 17:17:23 -070015410 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15411 const int32_t tex_width = 32;
15412 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015413
15414 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015415 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15416 image_create_info.pNext = NULL;
15417 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15418 image_create_info.format = tex_format;
15419 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015420 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015421 image_create_info.extent.depth = 1;
15422 image_create_info.mipLevels = 1;
15423 image_create_info.arrayLayers = 1;
15424 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15425 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15426 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15427 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015428
15429 // Introduce error by sending down a bogus width extent
15430 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015431 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015432
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015433 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015434}
15435
Mark Youngc48c4c12016-04-11 14:26:49 -060015436TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015438
15439 ASSERT_NO_FATAL_FAILURE(InitState());
15440
15441 // Create an image
15442 VkImage image;
15443
15444 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15445 const int32_t tex_width = 32;
15446 const int32_t tex_height = 32;
15447
15448 VkImageCreateInfo image_create_info = {};
15449 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15450 image_create_info.pNext = NULL;
15451 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15452 image_create_info.format = tex_format;
15453 image_create_info.extent.width = tex_width;
15454 image_create_info.extent.height = tex_height;
15455 image_create_info.extent.depth = 1;
15456 image_create_info.mipLevels = 1;
15457 image_create_info.arrayLayers = 1;
15458 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15459 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15460 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15461 image_create_info.flags = 0;
15462
15463 // Introduce error by sending down a bogus width extent
15464 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015465 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015466 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15467
15468 m_errorMonitor->VerifyFound();
15469}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015470
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015471TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015472 TEST_DESCRIPTION(
15473 "Create a render pass with an attachment description "
15474 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015475
15476 ASSERT_NO_FATAL_FAILURE(InitState());
15477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15478
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015480
15481 VkAttachmentReference color_attach = {};
15482 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15483 color_attach.attachment = 0;
15484 VkSubpassDescription subpass = {};
15485 subpass.colorAttachmentCount = 1;
15486 subpass.pColorAttachments = &color_attach;
15487
15488 VkRenderPassCreateInfo rpci = {};
15489 rpci.subpassCount = 1;
15490 rpci.pSubpasses = &subpass;
15491 rpci.attachmentCount = 1;
15492 VkAttachmentDescription attach_desc = {};
15493 attach_desc.format = VK_FORMAT_UNDEFINED;
15494 rpci.pAttachments = &attach_desc;
15495 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15496 VkRenderPass rp;
15497 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15498
15499 m_errorMonitor->VerifyFound();
15500
15501 if (result == VK_SUCCESS) {
15502 vkDestroyRenderPass(m_device->device(), rp, NULL);
15503 }
15504}
15505
Karl Schultz6addd812016-02-02 17:17:23 -070015506TEST_F(VkLayerTest, InvalidImageView) {
15507 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015508
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015510
Tobin Ehliscde08892015-09-22 10:11:37 -060015511 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015512
Mike Stroyana3082432015-09-25 13:39:21 -060015513 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015514 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015515
Karl Schultz6addd812016-02-02 17:17:23 -070015516 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15517 const int32_t tex_width = 32;
15518 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015519
15520 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015521 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15522 image_create_info.pNext = NULL;
15523 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15524 image_create_info.format = tex_format;
15525 image_create_info.extent.width = tex_width;
15526 image_create_info.extent.height = tex_height;
15527 image_create_info.extent.depth = 1;
15528 image_create_info.mipLevels = 1;
15529 image_create_info.arrayLayers = 1;
15530 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15531 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15532 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15533 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015534
Chia-I Wuf7458c52015-10-26 21:10:41 +080015535 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015536 ASSERT_VK_SUCCESS(err);
15537
15538 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015539 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015540 image_view_create_info.image = image;
15541 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15542 image_view_create_info.format = tex_format;
15543 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015544 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015545 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015546 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015547
15548 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015549 m_errorMonitor->SetUnexpectedError(
15550 "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 -060015551 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015552
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015553 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015554 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015555}
Mike Stroyana3082432015-09-25 13:39:21 -060015556
Mark Youngd339ba32016-05-30 13:28:35 -060015557TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15558 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015560 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015561
15562 ASSERT_NO_FATAL_FAILURE(InitState());
15563
15564 // Create an image and try to create a view with no memory backing the image
15565 VkImage image;
15566
15567 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15568 const int32_t tex_width = 32;
15569 const int32_t tex_height = 32;
15570
15571 VkImageCreateInfo image_create_info = {};
15572 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15573 image_create_info.pNext = NULL;
15574 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15575 image_create_info.format = tex_format;
15576 image_create_info.extent.width = tex_width;
15577 image_create_info.extent.height = tex_height;
15578 image_create_info.extent.depth = 1;
15579 image_create_info.mipLevels = 1;
15580 image_create_info.arrayLayers = 1;
15581 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15582 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15583 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15584 image_create_info.flags = 0;
15585
15586 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15587 ASSERT_VK_SUCCESS(err);
15588
15589 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015590 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015591 image_view_create_info.image = image;
15592 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15593 image_view_create_info.format = tex_format;
15594 image_view_create_info.subresourceRange.layerCount = 1;
15595 image_view_create_info.subresourceRange.baseMipLevel = 0;
15596 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015597 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015598
15599 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015600 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015601
15602 m_errorMonitor->VerifyFound();
15603 vkDestroyImage(m_device->device(), image, NULL);
15604 // If last error is success, it still created the view, so delete it.
15605 if (err == VK_SUCCESS) {
15606 vkDestroyImageView(m_device->device(), view, NULL);
15607 }
Mark Youngd339ba32016-05-30 13:28:35 -060015608}
15609
Karl Schultz6addd812016-02-02 17:17:23 -070015610TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015611 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015613
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015614 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015615
Karl Schultz6addd812016-02-02 17:17:23 -070015616 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015617 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015618 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015619 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015620
15621 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015622 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015623 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015624 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15625 image_view_create_info.format = tex_format;
15626 image_view_create_info.subresourceRange.baseMipLevel = 0;
15627 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015628 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015629 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015630 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015631
15632 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015633 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015634
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015635 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015636}
15637
Mike Weiblena1e13f42017-02-09 21:25:59 -070015638TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15639 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15640
15641 ASSERT_NO_FATAL_FAILURE(InitState());
15642 VkSubresourceLayout subres_layout = {};
15643
15644 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15645 {
15646 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15647 VkImageObj img(m_device);
15648 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15649 ASSERT_TRUE(img.initialized());
15650
15651 VkImageSubresource subres = {};
15652 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15653 subres.mipLevel = 0;
15654 subres.arrayLayer = 0;
15655
15656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15657 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15658 m_errorMonitor->VerifyFound();
15659 }
15660
15661 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15662 {
15663 VkImageObj img(m_device);
15664 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15665 ASSERT_TRUE(img.initialized());
15666
15667 VkImageSubresource subres = {};
15668 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15669 subres.mipLevel = 0;
15670 subres.arrayLayer = 0;
15671
15672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15674 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15675 m_errorMonitor->VerifyFound();
15676 }
15677
15678 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15679 {
15680 VkImageObj img(m_device);
15681 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15682 ASSERT_TRUE(img.initialized());
15683
15684 VkImageSubresource subres = {};
15685 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15686 subres.mipLevel = 1; // ERROR: triggers VU 00739
15687 subres.arrayLayer = 0;
15688
15689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15690 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15691 m_errorMonitor->VerifyFound();
15692 }
15693
15694 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15695 {
15696 VkImageObj img(m_device);
15697 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15698 ASSERT_TRUE(img.initialized());
15699
15700 VkImageSubresource subres = {};
15701 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15702 subres.mipLevel = 0;
15703 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15704
15705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15706 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15707 m_errorMonitor->VerifyFound();
15708 }
15709}
15710
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015711TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015712 VkResult err;
15713 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015714
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015716
Mike Stroyana3082432015-09-25 13:39:21 -060015717 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015718
15719 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015720 VkImage srcImage;
15721 VkImage dstImage;
15722 VkDeviceMemory srcMem;
15723 VkDeviceMemory destMem;
15724 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015725
15726 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015727 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15728 image_create_info.pNext = NULL;
15729 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15730 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15731 image_create_info.extent.width = 32;
15732 image_create_info.extent.height = 32;
15733 image_create_info.extent.depth = 1;
15734 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015735 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015736 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15737 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15738 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15739 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015741 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015742 ASSERT_VK_SUCCESS(err);
15743
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015744 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015745 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015746 ASSERT_VK_SUCCESS(err);
15747
15748 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015749 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015750 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15751 memAlloc.pNext = NULL;
15752 memAlloc.allocationSize = 0;
15753 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015754
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015755 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015756 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015757 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015758 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015759 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015760 ASSERT_VK_SUCCESS(err);
15761
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015762 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015763 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015764 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015765 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015766 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015767 ASSERT_VK_SUCCESS(err);
15768
15769 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15770 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015771 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015772 ASSERT_VK_SUCCESS(err);
15773
Tony Barbour552f6c02016-12-21 14:34:07 -070015774 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015775 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015776 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015777 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015778 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015779 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015780 copyRegion.srcOffset.x = 0;
15781 copyRegion.srcOffset.y = 0;
15782 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015783 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015784 copyRegion.dstSubresource.mipLevel = 0;
15785 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015786 // Introduce failure by forcing the dst layerCount to differ from src
15787 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015788 copyRegion.dstOffset.x = 0;
15789 copyRegion.dstOffset.y = 0;
15790 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015791 copyRegion.extent.width = 1;
15792 copyRegion.extent.height = 1;
15793 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015794 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015795 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015796
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015797 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015798
Chia-I Wuf7458c52015-10-26 21:10:41 +080015799 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015800 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015801 vkFreeMemory(m_device->device(), srcMem, NULL);
15802 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015803}
15804
Tony Barbourd6673642016-05-05 14:46:39 -060015805TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015806 TEST_DESCRIPTION("Creating images with unsuported formats ");
15807
15808 ASSERT_NO_FATAL_FAILURE(InitState());
15809 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15810 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015811 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 -060015812 VK_IMAGE_TILING_OPTIMAL, 0);
15813 ASSERT_TRUE(image.initialized());
15814
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015815 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015816 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015817 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015818 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15819 image_create_info.format = VK_FORMAT_UNDEFINED;
15820 image_create_info.extent.width = 32;
15821 image_create_info.extent.height = 32;
15822 image_create_info.extent.depth = 1;
15823 image_create_info.mipLevels = 1;
15824 image_create_info.arrayLayers = 1;
15825 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15826 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15827 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15830 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015831
15832 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015833 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15834 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15835 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15836 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015837 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15838 m_errorMonitor->VerifyFound();
15839
Tony Barbourd6673642016-05-05 14:46:39 -060015840 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015841 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015842 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15843 VkFormat format = static_cast<VkFormat>(f);
15844 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015845 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015846 unsupported = format;
15847 break;
15848 }
15849 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015850
Tony Barbourd6673642016-05-05 14:46:39 -060015851 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015852 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015854
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015855 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15856 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15857 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15858 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15859 m_errorMonitor->SetUnexpectedError(
15860 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15861 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15862 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015863 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015864 m_errorMonitor->VerifyFound();
15865 }
15866}
15867
15868TEST_F(VkLayerTest, ImageLayerViewTests) {
15869 VkResult ret;
15870 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15871
15872 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070015873 auto depth_format = find_depth_stencil_format(m_device);
15874 if (!depth_format) {
15875 return;
15876 }
Tony Barbourd6673642016-05-05 14:46:39 -060015877
15878 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015879 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 -060015880 VK_IMAGE_TILING_OPTIMAL, 0);
15881 ASSERT_TRUE(image.initialized());
15882
15883 VkImageView imgView;
15884 VkImageViewCreateInfo imgViewInfo = {};
15885 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15886 imgViewInfo.image = image.handle();
15887 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15888 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15889 imgViewInfo.subresourceRange.layerCount = 1;
15890 imgViewInfo.subresourceRange.baseMipLevel = 0;
15891 imgViewInfo.subresourceRange.levelCount = 1;
15892 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15893
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015895 // View can't have baseMipLevel >= image's mipLevels - Expect
15896 // VIEW_CREATE_ERROR
15897 imgViewInfo.subresourceRange.baseMipLevel = 1;
15898 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15899 m_errorMonitor->VerifyFound();
15900 imgViewInfo.subresourceRange.baseMipLevel = 0;
15901
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015903 // View can't have baseArrayLayer >= image's arraySize - Expect
15904 // VIEW_CREATE_ERROR
15905 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15906 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15907 m_errorMonitor->VerifyFound();
15908 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15909
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015911 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15912 imgViewInfo.subresourceRange.levelCount = 0;
15913 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15914 m_errorMonitor->VerifyFound();
15915 imgViewInfo.subresourceRange.levelCount = 1;
15916
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015917 m_errorMonitor->SetDesiredFailureMsg(
15918 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15919 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015920 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15921 imgViewInfo.subresourceRange.layerCount = 0;
15922 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15923 m_errorMonitor->VerifyFound();
15924 imgViewInfo.subresourceRange.layerCount = 1;
15925
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15927 "Formats MUST be IDENTICAL unless "
15928 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15929 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015930 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070015931 imgViewInfo.format = depth_format;
Tony Barbourd6673642016-05-05 14:46:39 -060015932 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15933 m_errorMonitor->VerifyFound();
15934 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15935
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015937 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15938 // VIEW_CREATE_ERROR
15939 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15940 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15941 m_errorMonitor->VerifyFound();
15942 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15943
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015945 // TODO: Update framework to easily passing mutable flag into ImageObj init
15946 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015947 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15948 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15949 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015950 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15951 // VIEW_CREATE_ERROR
15952 VkImageCreateInfo mutImgInfo = image.create_info();
15953 VkImage mutImage;
15954 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015955 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015956 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15957 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15958 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15959 ASSERT_VK_SUCCESS(ret);
15960 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015961 m_errorMonitor->SetUnexpectedError(
15962 "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 -060015963 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15964 m_errorMonitor->VerifyFound();
15965 imgViewInfo.image = image.handle();
15966 vkDestroyImage(m_device->handle(), mutImage, NULL);
15967}
15968
Dave Houlton75967fc2017-03-06 17:21:16 -070015969TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
15970 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
15971
15972 ASSERT_NO_FATAL_FAILURE(InitState());
15973
15974 VkPhysicalDeviceFeatures device_features;
15975 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
15976 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
15977 if (device_features.textureCompressionBC) {
15978 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
15979 } else if (device_features.textureCompressionETC2) {
15980 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
15981 } else if (device_features.textureCompressionASTC_LDR) {
15982 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
15983 } else {
15984 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
15985 return;
15986 }
15987
15988 VkImageCreateInfo ci;
15989 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15990 ci.pNext = NULL;
15991 ci.flags = 0;
15992 ci.imageType = VK_IMAGE_TYPE_2D;
15993 ci.format = compressed_format;
15994 ci.extent = {32, 32, 1};
15995 ci.mipLevels = 6;
15996 ci.arrayLayers = 1;
15997 ci.samples = VK_SAMPLE_COUNT_1_BIT;
15998 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
15999 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16000 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16001 ci.queueFamilyIndexCount = 0;
16002 ci.pQueueFamilyIndices = NULL;
16003 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16004
16005 VkImageObj image(m_device);
16006 image.init(&ci);
16007 ASSERT_TRUE(image.initialized());
16008
16009 VkImageObj odd_image(m_device);
16010 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16011 odd_image.init(&ci);
16012 ASSERT_TRUE(odd_image.initialized());
16013
16014 // Allocate buffers
16015 VkMemoryPropertyFlags reqs = 0;
16016 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16017 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16018 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16019 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16020 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16021
16022 VkBufferImageCopy region = {};
16023 region.bufferRowLength = 0;
16024 region.bufferImageHeight = 0;
16025 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16026 region.imageSubresource.layerCount = 1;
16027 region.imageOffset = {0, 0, 0};
16028 region.bufferOffset = 0;
16029
16030 // start recording
16031 m_commandBuffer->BeginCommandBuffer();
16032
16033 // Mip level copies that work - 5 levels
16034 m_errorMonitor->ExpectSuccess();
16035
16036 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
16037 region.imageExtent = {32, 32, 1};
16038 region.imageSubresource.mipLevel = 0;
16039 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
16040 &region);
16041 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16042 &region);
16043
16044 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
16045 region.imageExtent = {8, 8, 1};
16046 region.imageSubresource.mipLevel = 2;
16047 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
16048 &region);
16049 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16050 &region);
16051
16052 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
16053 region.imageExtent = {4, 4, 1};
16054 region.imageSubresource.mipLevel = 3;
16055 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16056 &region);
16057 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16058 &region);
16059
16060 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
16061 region.imageExtent = {2, 2, 1};
16062 region.imageSubresource.mipLevel = 4;
16063 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16064 &region);
16065 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16066 &region);
16067
16068 region.imageExtent = {1, 1, 1};
16069 region.imageSubresource.mipLevel = 5;
16070 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16071 &region);
16072 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16073 &region);
16074 m_errorMonitor->VerifyNotFound();
16075
16076 // Buffer must accomodate a full compressed block, regardless of texel count
16077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16078 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
16079 &region);
16080 m_errorMonitor->VerifyFound();
16081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
16082 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16083 &region);
16084 m_errorMonitor->VerifyFound();
16085
16086 // Copy width < compressed block size, but not the full mip width
16087 region.imageExtent = {1, 2, 1};
16088 region.imageSubresource.mipLevel = 4;
16089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16090 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16091 &region);
16092 m_errorMonitor->VerifyFound();
16093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16094 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16095 &region);
16096 m_errorMonitor->VerifyFound();
16097
16098 // Copy height < compressed block size but not the full mip height
16099 region.imageExtent = {2, 1, 1};
16100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16101 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16102 &region);
16103 m_errorMonitor->VerifyFound();
16104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16105 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16106 &region);
16107 m_errorMonitor->VerifyFound();
16108
16109 // Offsets must be multiple of compressed block size
16110 region.imageOffset = {1, 1, 0};
16111 region.imageExtent = {1, 1, 1};
16112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16113 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16114 &region);
16115 m_errorMonitor->VerifyFound();
16116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16117 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16118 &region);
16119 m_errorMonitor->VerifyFound();
16120
16121 // Offset + extent width = mip width - should succeed
16122 region.imageOffset = {4, 4, 0};
16123 region.imageExtent = {3, 4, 1};
16124 region.imageSubresource.mipLevel = 2;
16125 m_errorMonitor->ExpectSuccess();
16126 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16127 &region);
16128 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16129 &region);
16130 m_errorMonitor->VerifyNotFound();
16131
16132 // Offset + extent width > mip width, but still within the final compressed block - should succeed
16133 region.imageExtent = {4, 4, 1};
16134 m_errorMonitor->ExpectSuccess();
16135 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16136 &region);
16137 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16138 &region);
16139 m_errorMonitor->VerifyNotFound();
16140
16141 // Offset + extent width < mip width and not a multiple of block width - should fail
16142 region.imageExtent = {3, 3, 1};
16143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16144 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16145 &region);
16146 m_errorMonitor->VerifyFound();
16147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16148 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16149 &region);
16150 m_errorMonitor->VerifyFound();
16151}
16152
Dave Houlton59a20702017-02-02 17:26:23 -070016153TEST_F(VkLayerTest, ImageBufferCopyTests) {
16154 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
16155
16156 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016157 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
16158 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
16159 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
16160 return;
16161 }
Dave Houlton584d51e2017-02-16 12:52:54 -070016162
16163 // Bail if any dimension of transfer granularity is 0.
16164 auto index = m_device->graphics_queue_node_index_;
16165 auto queue_family_properties = m_device->phy().queue_properties();
16166 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
16167 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
16168 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
16169 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
16170 return;
16171 }
16172
Dave Houlton59a20702017-02-02 17:26:23 -070016173 VkImageObj image_64k(m_device); // 128^2 texels, 64k
16174 VkImageObj image_16k(m_device); // 64^2 texels, 16k
16175 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070016176 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
16177 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
16178 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
16179 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
16180
Dave Houlton59a20702017-02-02 17:26:23 -070016181 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
16182 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16183 VK_IMAGE_TILING_OPTIMAL, 0);
16184 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16185 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16186 VK_IMAGE_TILING_OPTIMAL, 0);
16187 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16188 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016189 ASSERT_TRUE(image_64k.initialized());
16190 ASSERT_TRUE(image_16k.initialized());
16191 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016192
Dave Houltonf3229d52017-02-21 15:59:08 -070016193 // Verify all needed Depth/Stencil formats are supported
16194 bool missing_ds_support = false;
16195 VkFormatProperties props = {0, 0, 0};
16196 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16197 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16198 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16199 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16200 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16201 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16202 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16203 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16204
16205 if (!missing_ds_support) {
16206 ds_image_4D_1S.init(
16207 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16208 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16209 VK_IMAGE_TILING_OPTIMAL, 0);
16210 ASSERT_TRUE(ds_image_4D_1S.initialized());
16211
16212 ds_image_3D_1S.init(
16213 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16214 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16215 VK_IMAGE_TILING_OPTIMAL, 0);
16216 ASSERT_TRUE(ds_image_3D_1S.initialized());
16217
16218 ds_image_2D.init(
16219 256, 256, VK_FORMAT_D16_UNORM,
16220 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16221 VK_IMAGE_TILING_OPTIMAL, 0);
16222 ASSERT_TRUE(ds_image_2D.initialized());
16223
16224 ds_image_1S.init(
16225 256, 256, VK_FORMAT_S8_UINT,
16226 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16227 VK_IMAGE_TILING_OPTIMAL, 0);
16228 ASSERT_TRUE(ds_image_1S.initialized());
16229 }
16230
16231 // Allocate buffers
16232 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016233 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016234 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16235 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16236 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16237 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016238
16239 VkBufferImageCopy region = {};
16240 region.bufferRowLength = 0;
16241 region.bufferImageHeight = 0;
16242 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16243 region.imageSubresource.layerCount = 1;
16244 region.imageOffset = {0, 0, 0};
16245 region.imageExtent = {64, 64, 1};
16246 region.bufferOffset = 0;
16247
16248 // attempt copies before putting command buffer in recording state
16249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16250 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16251 &region);
16252 m_errorMonitor->VerifyFound();
16253
16254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16255 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16256 &region);
16257 m_errorMonitor->VerifyFound();
16258
16259 // start recording
16260 m_commandBuffer->BeginCommandBuffer();
16261
16262 // successful copies
16263 m_errorMonitor->ExpectSuccess();
16264 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16265 &region);
16266 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16267 &region);
16268 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16269 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16270 &region);
16271 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16272 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16273 &region);
16274 region.imageOffset.x = 0;
16275 region.imageExtent.height = 64;
16276 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16277 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16278 &region);
16279 m_errorMonitor->VerifyNotFound();
16280
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016281 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070016282 region.imageExtent = {65, 64, 1};
16283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16284 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16285 &region);
16286 m_errorMonitor->VerifyFound();
16287
16288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16289 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16290 &region);
16291 m_errorMonitor->VerifyFound();
16292
16293 // image/buffer too small (offset) on copy to image
16294 region.imageExtent = {64, 64, 1};
16295 region.imageOffset = {0, 4, 0};
16296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16297 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16298 &region);
16299 m_errorMonitor->VerifyFound();
16300
16301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16302 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16303 &region);
16304 m_errorMonitor->VerifyFound();
16305
16306 // image/buffer too small on copy to buffer
16307 region.imageExtent = {64, 64, 1};
16308 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016309 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16311 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16312 &region);
16313 m_errorMonitor->VerifyFound();
16314
16315 region.imageExtent = {64, 65, 1};
16316 region.bufferOffset = 0;
16317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16318 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16319 &region);
16320 m_errorMonitor->VerifyFound();
16321
16322 // buffer size ok but rowlength causes loose packing
16323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16324 region.imageExtent = {64, 64, 1};
16325 region.bufferRowLength = 68;
16326 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16327 &region);
16328 m_errorMonitor->VerifyFound();
16329
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016330 // An extent with zero area should produce a warning, but no error
16331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
16332 region.imageExtent.width = 0;
16333 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16334 &region);
16335 m_errorMonitor->VerifyFound();
16336
Dave Houlton59a20702017-02-02 17:26:23 -070016337 // aspect bits
16338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16339 region.imageExtent = {64, 64, 1};
16340 region.bufferRowLength = 0;
16341 region.bufferImageHeight = 0;
16342 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16343 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16344 buffer_16k.handle(), 1, &region);
16345 m_errorMonitor->VerifyFound();
16346
16347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16348 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16349 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16350 &region);
16351 m_errorMonitor->VerifyFound();
16352
16353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16354 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16355 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16356 buffer_16k.handle(), 1, &region);
16357 m_errorMonitor->VerifyFound();
16358
Dave Houltonf3229d52017-02-21 15:59:08 -070016359 // Test Depth/Stencil copies
16360 if (missing_ds_support) {
16361 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16362 } else {
16363 VkBufferImageCopy ds_region = {};
16364 ds_region.bufferOffset = 0;
16365 ds_region.bufferRowLength = 0;
16366 ds_region.bufferImageHeight = 0;
16367 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16368 ds_region.imageSubresource.mipLevel = 0;
16369 ds_region.imageSubresource.baseArrayLayer = 0;
16370 ds_region.imageSubresource.layerCount = 1;
16371 ds_region.imageOffset = {0, 0, 0};
16372 ds_region.imageExtent = {256, 256, 1};
16373
16374 // Depth copies that should succeed
16375 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16376 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16377 buffer_256k.handle(), 1, &ds_region);
16378 m_errorMonitor->VerifyNotFound();
16379
16380 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16381 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16382 buffer_256k.handle(), 1, &ds_region);
16383 m_errorMonitor->VerifyNotFound();
16384
16385 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16386 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16387 buffer_128k.handle(), 1, &ds_region);
16388 m_errorMonitor->VerifyNotFound();
16389
16390 // Depth copies that should fail
16391 ds_region.bufferOffset = 4;
16392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16393 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16394 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16395 buffer_256k.handle(), 1, &ds_region);
16396 m_errorMonitor->VerifyFound();
16397
16398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16399 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16400 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16401 buffer_256k.handle(), 1, &ds_region);
16402 m_errorMonitor->VerifyFound();
16403
16404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16405 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16406 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16407 buffer_128k.handle(), 1, &ds_region);
16408 m_errorMonitor->VerifyFound();
16409
16410 // Stencil copies that should succeed
16411 ds_region.bufferOffset = 0;
16412 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16413 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16414 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16415 buffer_64k.handle(), 1, &ds_region);
16416 m_errorMonitor->VerifyNotFound();
16417
16418 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16419 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16420 buffer_64k.handle(), 1, &ds_region);
16421 m_errorMonitor->VerifyNotFound();
16422
16423 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16424 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16425 buffer_64k.handle(), 1, &ds_region);
16426 m_errorMonitor->VerifyNotFound();
16427
16428 // Stencil copies that should fail
16429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16430 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16431 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16432 buffer_16k.handle(), 1, &ds_region);
16433 m_errorMonitor->VerifyFound();
16434
16435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16436 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16437 ds_region.bufferRowLength = 260;
16438 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16439 buffer_64k.handle(), 1, &ds_region);
16440 m_errorMonitor->VerifyFound();
16441
16442 ds_region.bufferRowLength = 0;
16443 ds_region.bufferOffset = 4;
16444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16445 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16446 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16447 buffer_64k.handle(), 1, &ds_region);
16448 m_errorMonitor->VerifyFound();
16449 }
16450
Dave Houlton584d51e2017-02-16 12:52:54 -070016451 // Test compressed formats, if supported
16452 VkPhysicalDeviceFeatures device_features;
16453 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016454 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16455 device_features.textureCompressionASTC_LDR)) {
16456 printf(" No compressed formats supported - block compression tests skipped.\n");
16457 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070016458 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16459 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070016460 if (device_features.textureCompressionBC) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016461 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 -070016462 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16463 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016464 } else if (device_features.textureCompressionETC2) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016465 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 -070016466 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016467 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16468 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016469 } else {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016470 image_16k_4x4comp.init(128, 128, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16471 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016472 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16473 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016474 }
16475 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016476
Dave Houlton584d51e2017-02-16 12:52:54 -070016477 // Just fits
16478 m_errorMonitor->ExpectSuccess();
16479 region.imageExtent = {128, 128, 1};
16480 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16481 buffer_16k.handle(), 1, &region);
16482 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016483
Dave Houlton584d51e2017-02-16 12:52:54 -070016484 // with offset, too big for buffer
16485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16486 region.bufferOffset = 16;
16487 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16488 buffer_16k.handle(), 1, &region);
16489 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016490 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016491
Dave Houlton67e9b532017-03-02 17:00:10 -070016492 // extents that are not a multiple of compressed block size
16493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16494 region.imageExtent.width = 66;
16495 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16496 buffer_16k.handle(), 1, &region);
16497 m_errorMonitor->VerifyFound();
16498 region.imageExtent.width = 128;
16499
16500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016501 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070016502 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16503 buffer_16k.handle(), 1, &region);
16504 m_errorMonitor->VerifyFound();
16505 region.imageExtent.height = 128;
16506
16507 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
16508
16509 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
16510 m_errorMonitor->ExpectSuccess();
16511 region.imageExtent.width = 66;
16512 region.imageOffset.x = 64;
16513 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16514 buffer_16k.handle(), 1, &region);
16515 region.imageExtent.width = 16;
16516 region.imageOffset.x = 0;
16517 region.imageExtent.height = 2;
16518 region.imageOffset.y = 128;
16519 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016520 buffer_16k.handle(), 1, &region);
16521 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016522 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016523
Dave Houlton584d51e2017-02-16 12:52:54 -070016524 // buffer offset must be a multiple of texel block size (16)
16525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16527 region.imageExtent = {64, 64, 1};
16528 region.bufferOffset = 24;
16529 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16530 buffer_16k.handle(), 1, &region);
16531 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016532
Dave Houlton584d51e2017-02-16 12:52:54 -070016533 // rowlength not a multiple of block width (4)
16534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16535 region.bufferOffset = 0;
16536 region.bufferRowLength = 130;
16537 region.bufferImageHeight = 0;
16538 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16539 buffer_64k.handle(), 1, &region);
16540 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016541
Dave Houlton584d51e2017-02-16 12:52:54 -070016542 // imageheight not a multiple of block height (4)
16543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16544 region.bufferRowLength = 0;
16545 region.bufferImageHeight = 130;
16546 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16547 buffer_64k.handle(), 1, &region);
16548 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070016549 }
Dave Houlton59a20702017-02-02 17:26:23 -070016550}
16551
Tony Barbourd6673642016-05-05 14:46:39 -060016552TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016553 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016554
16555 ASSERT_NO_FATAL_FAILURE(InitState());
16556
Rene Lindsay135204f2016-12-22 17:11:09 -070016557 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016558 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016559 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 -070016560 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016561 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016562 vk_testing::Buffer buffer;
16563 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016564 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016565 VkBufferImageCopy region = {};
16566 region.bufferRowLength = 128;
16567 region.bufferImageHeight = 128;
16568 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16569 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016570 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016571 region.imageExtent.height = 4;
16572 region.imageExtent.width = 4;
16573 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016574
16575 VkImageObj image2(m_device);
16576 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 -070016577 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016578 ASSERT_TRUE(image2.initialized());
16579 vk_testing::Buffer buffer2;
16580 VkMemoryPropertyFlags reqs2 = 0;
16581 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16582 VkBufferImageCopy region2 = {};
16583 region2.bufferRowLength = 128;
16584 region2.bufferImageHeight = 128;
16585 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16586 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16587 region2.imageSubresource.layerCount = 1;
16588 region2.imageExtent.height = 4;
16589 region2.imageExtent.width = 4;
16590 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016591 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016592
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016593 // Image must have offset.z of 0 and extent.depth of 1
16594 // Introduce failure by setting imageExtent.depth to 0
16595 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016597 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016598 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016599 m_errorMonitor->VerifyFound();
16600
16601 region.imageExtent.depth = 1;
16602
16603 // Image must have offset.z of 0 and extent.depth of 1
16604 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016605 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016606 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016609 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016610 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016611 m_errorMonitor->VerifyFound();
16612
16613 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016614 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16615 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016616 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016618 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16619 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016620 m_errorMonitor->VerifyFound();
16621
16622 // BufferOffset must be a multiple of 4
16623 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016624 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016626 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16627 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016628 m_errorMonitor->VerifyFound();
16629
16630 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16631 region.bufferOffset = 0;
16632 region.imageExtent.height = 128;
16633 region.imageExtent.width = 128;
16634 // Introduce failure by setting bufferRowLength > 0 but less than width
16635 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016637 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16638 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016639 m_errorMonitor->VerifyFound();
16640
16641 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16642 region.bufferRowLength = 128;
16643 // Introduce failure by setting bufferRowHeight > 0 but less than height
16644 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016646 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16647 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016648 m_errorMonitor->VerifyFound();
16649
16650 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016651 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016652 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16653 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016654 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016655 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16656 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016657 VkImageBlit blitRegion = {};
16658 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16659 blitRegion.srcSubresource.baseArrayLayer = 0;
16660 blitRegion.srcSubresource.layerCount = 1;
16661 blitRegion.srcSubresource.mipLevel = 0;
16662 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16663 blitRegion.dstSubresource.baseArrayLayer = 0;
16664 blitRegion.dstSubresource.layerCount = 1;
16665 blitRegion.dstSubresource.mipLevel = 0;
16666
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016667 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016669 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016670 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16671 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016672 m_errorMonitor->VerifyFound();
16673
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016675 VkImageMemoryBarrier img_barrier;
16676 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16677 img_barrier.pNext = NULL;
16678 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16679 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16680 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16681 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16682 img_barrier.image = image.handle();
16683 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16684 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16685 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16686 img_barrier.subresourceRange.baseArrayLayer = 0;
16687 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016688 img_barrier.subresourceRange.layerCount = 0;
16689 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016690 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16691 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016692 m_errorMonitor->VerifyFound();
16693 img_barrier.subresourceRange.layerCount = 1;
16694}
16695
16696TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016697 TEST_DESCRIPTION("Exceed the limits of image format ");
16698
Cody Northropc31a84f2016-08-22 10:41:47 -060016699 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016701 VkImageCreateInfo image_create_info = {};
16702 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16703 image_create_info.pNext = NULL;
16704 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16705 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16706 image_create_info.extent.width = 32;
16707 image_create_info.extent.height = 32;
16708 image_create_info.extent.depth = 1;
16709 image_create_info.mipLevels = 1;
16710 image_create_info.arrayLayers = 1;
16711 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16712 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16713 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16714 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16715 image_create_info.flags = 0;
16716
16717 VkImage nullImg;
16718 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016719 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16720 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016721 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016722 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16723 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16724 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016725 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016726
Tony Barbour0907e362017-03-09 15:05:30 -070016727 uint32_t maxDim =
16728 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
16729 // If max mip levels exceeds image extents, skip the max mip levels test
16730 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
16731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
16732 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16733 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16734 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16735 m_errorMonitor->VerifyFound();
16736 image_create_info.mipLevels = 1;
16737 }
Tony Barbourd6673642016-05-05 14:46:39 -060016738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016740 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16741 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16742 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16743 m_errorMonitor->VerifyFound();
16744 image_create_info.arrayLayers = 1;
16745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016747 int samples = imgFmtProps.sampleCounts >> 1;
16748 image_create_info.samples = (VkSampleCountFlagBits)samples;
16749 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16750 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16751 m_errorMonitor->VerifyFound();
16752 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16753
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16755 "pCreateInfo->initialLayout, must be "
16756 "VK_IMAGE_LAYOUT_UNDEFINED or "
16757 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016758 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16759 // Expect INVALID_LAYOUT
16760 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16761 m_errorMonitor->VerifyFound();
16762 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16763}
16764
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016765TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016766 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016768
16769 ASSERT_NO_FATAL_FAILURE(InitState());
16770
16771 VkImageObj src_image(m_device);
16772 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16773 VkImageObj dst_image(m_device);
16774 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16775
Tony Barbour552f6c02016-12-21 14:34:07 -070016776 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016777 VkImageCopy copy_region;
16778 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16779 copy_region.srcSubresource.mipLevel = 0;
16780 copy_region.srcSubresource.baseArrayLayer = 0;
16781 copy_region.srcSubresource.layerCount = 0;
16782 copy_region.srcOffset.x = 0;
16783 copy_region.srcOffset.y = 0;
16784 copy_region.srcOffset.z = 0;
16785 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16786 copy_region.dstSubresource.mipLevel = 0;
16787 copy_region.dstSubresource.baseArrayLayer = 0;
16788 copy_region.dstSubresource.layerCount = 0;
16789 copy_region.dstOffset.x = 0;
16790 copy_region.dstOffset.y = 0;
16791 copy_region.dstOffset.z = 0;
16792 copy_region.extent.width = 64;
16793 copy_region.extent.height = 64;
16794 copy_region.extent.depth = 1;
16795 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16796 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016797 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016798
16799 m_errorMonitor->VerifyFound();
16800}
16801
16802TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016803 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016805
16806 ASSERT_NO_FATAL_FAILURE(InitState());
16807
16808 VkImageObj src_image(m_device);
16809 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16810 VkImageObj dst_image(m_device);
16811 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16812
Tony Barbour552f6c02016-12-21 14:34:07 -070016813 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016814 VkImageCopy copy_region;
16815 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16816 copy_region.srcSubresource.mipLevel = 0;
16817 copy_region.srcSubresource.baseArrayLayer = 0;
16818 copy_region.srcSubresource.layerCount = 0;
16819 copy_region.srcOffset.x = 0;
16820 copy_region.srcOffset.y = 0;
16821 copy_region.srcOffset.z = 0;
16822 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16823 copy_region.dstSubresource.mipLevel = 0;
16824 copy_region.dstSubresource.baseArrayLayer = 0;
16825 copy_region.dstSubresource.layerCount = 0;
16826 copy_region.dstOffset.x = 0;
16827 copy_region.dstOffset.y = 0;
16828 copy_region.dstOffset.z = 0;
16829 copy_region.extent.width = 64;
16830 copy_region.extent.height = 64;
16831 copy_region.extent.depth = 1;
16832 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16833 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016834 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016835
16836 m_errorMonitor->VerifyFound();
16837}
16838
Karl Schultz6addd812016-02-02 17:17:23 -070016839TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016840 VkResult err;
16841 bool pass;
16842
16843 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016845
16846 ASSERT_NO_FATAL_FAILURE(InitState());
16847
16848 // Create two images of different types and try to copy between them
16849 VkImage srcImage;
16850 VkImage dstImage;
16851 VkDeviceMemory srcMem;
16852 VkDeviceMemory destMem;
16853 VkMemoryRequirements memReqs;
16854
16855 VkImageCreateInfo image_create_info = {};
16856 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16857 image_create_info.pNext = NULL;
16858 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16859 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16860 image_create_info.extent.width = 32;
16861 image_create_info.extent.height = 32;
16862 image_create_info.extent.depth = 1;
16863 image_create_info.mipLevels = 1;
16864 image_create_info.arrayLayers = 1;
16865 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16866 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16867 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16868 image_create_info.flags = 0;
16869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016870 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016871 ASSERT_VK_SUCCESS(err);
16872
16873 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16874 // Introduce failure by creating second image with a different-sized format.
16875 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016877 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016878 ASSERT_VK_SUCCESS(err);
16879
16880 // Allocate memory
16881 VkMemoryAllocateInfo memAlloc = {};
16882 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16883 memAlloc.pNext = NULL;
16884 memAlloc.allocationSize = 0;
16885 memAlloc.memoryTypeIndex = 0;
16886
16887 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16888 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016889 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016890 ASSERT_TRUE(pass);
16891 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16892 ASSERT_VK_SUCCESS(err);
16893
16894 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16895 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016896 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016897 ASSERT_TRUE(pass);
16898 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16899 ASSERT_VK_SUCCESS(err);
16900
16901 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16902 ASSERT_VK_SUCCESS(err);
16903 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16904 ASSERT_VK_SUCCESS(err);
16905
Tony Barbour552f6c02016-12-21 14:34:07 -070016906 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016907 VkImageCopy copyRegion;
16908 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16909 copyRegion.srcSubresource.mipLevel = 0;
16910 copyRegion.srcSubresource.baseArrayLayer = 0;
16911 copyRegion.srcSubresource.layerCount = 0;
16912 copyRegion.srcOffset.x = 0;
16913 copyRegion.srcOffset.y = 0;
16914 copyRegion.srcOffset.z = 0;
16915 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16916 copyRegion.dstSubresource.mipLevel = 0;
16917 copyRegion.dstSubresource.baseArrayLayer = 0;
16918 copyRegion.dstSubresource.layerCount = 0;
16919 copyRegion.dstOffset.x = 0;
16920 copyRegion.dstOffset.y = 0;
16921 copyRegion.dstOffset.z = 0;
16922 copyRegion.extent.width = 1;
16923 copyRegion.extent.height = 1;
16924 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016925 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016926 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016927
16928 m_errorMonitor->VerifyFound();
16929
16930 vkDestroyImage(m_device->device(), srcImage, NULL);
16931 vkDestroyImage(m_device->device(), dstImage, NULL);
16932 vkFreeMemory(m_device->device(), srcMem, NULL);
16933 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016934}
16935
Karl Schultz6addd812016-02-02 17:17:23 -070016936TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16937 VkResult err;
16938 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016939
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016940 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16942 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016943
Mike Stroyana3082432015-09-25 13:39:21 -060016944 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016945 auto depth_format = find_depth_stencil_format(m_device);
16946 if (!depth_format) {
16947 return;
16948 }
Mike Stroyana3082432015-09-25 13:39:21 -060016949
16950 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016951 VkImage srcImage;
16952 VkImage dstImage;
16953 VkDeviceMemory srcMem;
16954 VkDeviceMemory destMem;
16955 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016956
16957 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016958 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16959 image_create_info.pNext = NULL;
16960 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16961 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16962 image_create_info.extent.width = 32;
16963 image_create_info.extent.height = 32;
16964 image_create_info.extent.depth = 1;
16965 image_create_info.mipLevels = 1;
16966 image_create_info.arrayLayers = 1;
16967 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16968 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16969 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16970 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016972 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016973 ASSERT_VK_SUCCESS(err);
16974
Karl Schultzbdb75952016-04-19 11:36:49 -060016975 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16976
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016977 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016978 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070016979 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016980 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016982 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016983 ASSERT_VK_SUCCESS(err);
16984
16985 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016986 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016987 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16988 memAlloc.pNext = NULL;
16989 memAlloc.allocationSize = 0;
16990 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016991
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016992 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016993 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016994 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016995 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016996 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016997 ASSERT_VK_SUCCESS(err);
16998
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016999 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017000 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017001 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017002 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017003 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017004 ASSERT_VK_SUCCESS(err);
17005
17006 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17007 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017008 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017009 ASSERT_VK_SUCCESS(err);
17010
Tony Barbour552f6c02016-12-21 14:34:07 -070017011 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017012 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017013 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017014 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017015 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017016 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017017 copyRegion.srcOffset.x = 0;
17018 copyRegion.srcOffset.y = 0;
17019 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017020 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017021 copyRegion.dstSubresource.mipLevel = 0;
17022 copyRegion.dstSubresource.baseArrayLayer = 0;
17023 copyRegion.dstSubresource.layerCount = 0;
17024 copyRegion.dstOffset.x = 0;
17025 copyRegion.dstOffset.y = 0;
17026 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017027 copyRegion.extent.width = 1;
17028 copyRegion.extent.height = 1;
17029 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017030 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017031 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017032
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017033 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017034
Chia-I Wuf7458c52015-10-26 21:10:41 +080017035 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017036 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017037 vkFreeMemory(m_device->device(), srcMem, NULL);
17038 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017039}
17040
Karl Schultz6addd812016-02-02 17:17:23 -070017041TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
17042 VkResult err;
17043 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17046 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017047
Mike Stroyana3082432015-09-25 13:39:21 -060017048 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017049
17050 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017051 VkImage srcImage;
17052 VkImage dstImage;
17053 VkDeviceMemory srcMem;
17054 VkDeviceMemory destMem;
17055 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017056
17057 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017058 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17059 image_create_info.pNext = NULL;
17060 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17061 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17062 image_create_info.extent.width = 32;
17063 image_create_info.extent.height = 1;
17064 image_create_info.extent.depth = 1;
17065 image_create_info.mipLevels = 1;
17066 image_create_info.arrayLayers = 1;
17067 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17068 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17069 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17070 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017072 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017073 ASSERT_VK_SUCCESS(err);
17074
Karl Schultz6addd812016-02-02 17:17:23 -070017075 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017077 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017078 ASSERT_VK_SUCCESS(err);
17079
17080 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017081 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017082 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17083 memAlloc.pNext = NULL;
17084 memAlloc.allocationSize = 0;
17085 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017086
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017087 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017088 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017089 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017090 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017091 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017092 ASSERT_VK_SUCCESS(err);
17093
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017094 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017095 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017096 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017097 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017098 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017099 ASSERT_VK_SUCCESS(err);
17100
17101 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17102 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017103 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017104 ASSERT_VK_SUCCESS(err);
17105
Tony Barbour552f6c02016-12-21 14:34:07 -070017106 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017107 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017108 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17109 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017110 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017111 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017112 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017113 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017114 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017115 resolveRegion.srcOffset.x = 0;
17116 resolveRegion.srcOffset.y = 0;
17117 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017118 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017119 resolveRegion.dstSubresource.mipLevel = 0;
17120 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017121 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017122 resolveRegion.dstOffset.x = 0;
17123 resolveRegion.dstOffset.y = 0;
17124 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017125 resolveRegion.extent.width = 1;
17126 resolveRegion.extent.height = 1;
17127 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017128 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017129 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017130
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017131 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017132
Chia-I Wuf7458c52015-10-26 21:10:41 +080017133 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017134 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017135 vkFreeMemory(m_device->device(), srcMem, NULL);
17136 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017137}
17138
Karl Schultz6addd812016-02-02 17:17:23 -070017139TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
17140 VkResult err;
17141 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17144 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017145
Mike Stroyana3082432015-09-25 13:39:21 -060017146 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017147
Chris Forbesa7530692016-05-08 12:35:39 +120017148 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017149 VkImage srcImage;
17150 VkImage dstImage;
17151 VkDeviceMemory srcMem;
17152 VkDeviceMemory destMem;
17153 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017154
17155 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017156 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17157 image_create_info.pNext = NULL;
17158 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17159 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17160 image_create_info.extent.width = 32;
17161 image_create_info.extent.height = 1;
17162 image_create_info.extent.depth = 1;
17163 image_create_info.mipLevels = 1;
17164 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017165 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017166 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17167 // Note: Some implementations expect color attachment usage for any
17168 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017169 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017170 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017172 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017173 ASSERT_VK_SUCCESS(err);
17174
Karl Schultz6addd812016-02-02 17:17:23 -070017175 // Note: Some implementations expect color attachment usage for any
17176 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017177 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017179 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017180 ASSERT_VK_SUCCESS(err);
17181
17182 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017183 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017184 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17185 memAlloc.pNext = NULL;
17186 memAlloc.allocationSize = 0;
17187 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017188
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017189 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017190 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017191 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017192 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017193 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017194 ASSERT_VK_SUCCESS(err);
17195
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017196 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017197 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017198 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017199 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017200 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017201 ASSERT_VK_SUCCESS(err);
17202
17203 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17204 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017205 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017206 ASSERT_VK_SUCCESS(err);
17207
Tony Barbour552f6c02016-12-21 14:34:07 -070017208 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017209 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017210 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17211 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017212 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017213 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017214 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017215 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017216 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017217 resolveRegion.srcOffset.x = 0;
17218 resolveRegion.srcOffset.y = 0;
17219 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017220 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017221 resolveRegion.dstSubresource.mipLevel = 0;
17222 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017223 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017224 resolveRegion.dstOffset.x = 0;
17225 resolveRegion.dstOffset.y = 0;
17226 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017227 resolveRegion.extent.width = 1;
17228 resolveRegion.extent.height = 1;
17229 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017230 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017231 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017232
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017233 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017234
Chia-I Wuf7458c52015-10-26 21:10:41 +080017235 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017236 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017237 vkFreeMemory(m_device->device(), srcMem, NULL);
17238 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017239}
17240
Karl Schultz6addd812016-02-02 17:17:23 -070017241TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17242 VkResult err;
17243 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017244
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017246 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017247
Mike Stroyana3082432015-09-25 13:39:21 -060017248 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017249
17250 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017251 VkImage srcImage;
17252 VkImage dstImage;
17253 VkDeviceMemory srcMem;
17254 VkDeviceMemory destMem;
17255 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017256
17257 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017258 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17259 image_create_info.pNext = NULL;
17260 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17261 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17262 image_create_info.extent.width = 32;
17263 image_create_info.extent.height = 1;
17264 image_create_info.extent.depth = 1;
17265 image_create_info.mipLevels = 1;
17266 image_create_info.arrayLayers = 1;
17267 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17268 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17269 // Note: Some implementations expect color attachment usage for any
17270 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017271 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017272 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017274 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017275 ASSERT_VK_SUCCESS(err);
17276
Karl Schultz6addd812016-02-02 17:17:23 -070017277 // Set format to something other than source image
17278 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17279 // Note: Some implementations expect color attachment usage for any
17280 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017281 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017282 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017284 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017285 ASSERT_VK_SUCCESS(err);
17286
17287 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017288 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017289 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17290 memAlloc.pNext = NULL;
17291 memAlloc.allocationSize = 0;
17292 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017293
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017294 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017295 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017296 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017297 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017298 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017299 ASSERT_VK_SUCCESS(err);
17300
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017301 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017302 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017303 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017304 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017305 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017306 ASSERT_VK_SUCCESS(err);
17307
17308 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17309 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017310 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017311 ASSERT_VK_SUCCESS(err);
17312
Tony Barbour552f6c02016-12-21 14:34:07 -070017313 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017314 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017315 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17316 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017317 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017318 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017319 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017320 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017321 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017322 resolveRegion.srcOffset.x = 0;
17323 resolveRegion.srcOffset.y = 0;
17324 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017325 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017326 resolveRegion.dstSubresource.mipLevel = 0;
17327 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017328 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017329 resolveRegion.dstOffset.x = 0;
17330 resolveRegion.dstOffset.y = 0;
17331 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017332 resolveRegion.extent.width = 1;
17333 resolveRegion.extent.height = 1;
17334 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017335 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017336 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017337
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017338 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017339
Chia-I Wuf7458c52015-10-26 21:10:41 +080017340 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017341 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017342 vkFreeMemory(m_device->device(), srcMem, NULL);
17343 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017344}
17345
Karl Schultz6addd812016-02-02 17:17:23 -070017346TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17347 VkResult err;
17348 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017349
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017351 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017352
Mike Stroyana3082432015-09-25 13:39:21 -060017353 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017354
17355 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017356 VkImage srcImage;
17357 VkImage dstImage;
17358 VkDeviceMemory srcMem;
17359 VkDeviceMemory destMem;
17360 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017361
17362 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017363 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17364 image_create_info.pNext = NULL;
17365 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17366 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17367 image_create_info.extent.width = 32;
17368 image_create_info.extent.height = 1;
17369 image_create_info.extent.depth = 1;
17370 image_create_info.mipLevels = 1;
17371 image_create_info.arrayLayers = 1;
17372 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17373 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17374 // Note: Some implementations expect color attachment usage for any
17375 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017376 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017377 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017379 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017380 ASSERT_VK_SUCCESS(err);
17381
Karl Schultz6addd812016-02-02 17:17:23 -070017382 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17383 // Note: Some implementations expect color attachment usage for any
17384 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017385 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017386 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017388 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017389 ASSERT_VK_SUCCESS(err);
17390
17391 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017392 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017393 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17394 memAlloc.pNext = NULL;
17395 memAlloc.allocationSize = 0;
17396 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017397
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017398 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017399 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017400 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017401 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017402 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017403 ASSERT_VK_SUCCESS(err);
17404
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017405 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017406 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017407 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017408 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017409 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017410 ASSERT_VK_SUCCESS(err);
17411
17412 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17413 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017414 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017415 ASSERT_VK_SUCCESS(err);
17416
Tony Barbour552f6c02016-12-21 14:34:07 -070017417 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017418 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017419 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17420 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017421 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017422 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017423 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017424 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017425 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017426 resolveRegion.srcOffset.x = 0;
17427 resolveRegion.srcOffset.y = 0;
17428 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017429 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017430 resolveRegion.dstSubresource.mipLevel = 0;
17431 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017432 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017433 resolveRegion.dstOffset.x = 0;
17434 resolveRegion.dstOffset.y = 0;
17435 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017436 resolveRegion.extent.width = 1;
17437 resolveRegion.extent.height = 1;
17438 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017439 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017440 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017441
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017442 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017443
Chia-I Wuf7458c52015-10-26 21:10:41 +080017444 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017445 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017446 vkFreeMemory(m_device->device(), srcMem, NULL);
17447 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017448}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017449
Karl Schultz6addd812016-02-02 17:17:23 -070017450TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017451 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017452 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17453 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017454 // The image format check comes 2nd in validation so we trigger it first,
17455 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017456 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017457
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17459 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017460
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017461 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017462 auto depth_format = find_depth_stencil_format(m_device);
17463 if (!depth_format) {
17464 return;
17465 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017466
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017467 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017468 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17469 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017470
17471 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017472 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17473 ds_pool_ci.pNext = NULL;
17474 ds_pool_ci.maxSets = 1;
17475 ds_pool_ci.poolSizeCount = 1;
17476 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017477
17478 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017479 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017480 ASSERT_VK_SUCCESS(err);
17481
17482 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017483 dsl_binding.binding = 0;
17484 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17485 dsl_binding.descriptorCount = 1;
17486 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17487 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017488
17489 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017490 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17491 ds_layout_ci.pNext = NULL;
17492 ds_layout_ci.bindingCount = 1;
17493 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017494 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017496 ASSERT_VK_SUCCESS(err);
17497
17498 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017499 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017500 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017501 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017502 alloc_info.descriptorPool = ds_pool;
17503 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017504 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017505 ASSERT_VK_SUCCESS(err);
17506
Karl Schultz6addd812016-02-02 17:17:23 -070017507 VkImage image_bad;
17508 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017509 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070017510 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017511 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017512 const int32_t tex_width = 32;
17513 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017514
17515 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017516 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17517 image_create_info.pNext = NULL;
17518 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17519 image_create_info.format = tex_format_bad;
17520 image_create_info.extent.width = tex_width;
17521 image_create_info.extent.height = tex_height;
17522 image_create_info.extent.depth = 1;
17523 image_create_info.mipLevels = 1;
17524 image_create_info.arrayLayers = 1;
17525 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17526 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017527 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017528 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017530 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017531 ASSERT_VK_SUCCESS(err);
17532 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017533 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17534 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017535 ASSERT_VK_SUCCESS(err);
17536
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017537 // ---Bind image memory---
17538 VkMemoryRequirements img_mem_reqs;
17539 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17540 VkMemoryAllocateInfo image_alloc_info = {};
17541 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17542 image_alloc_info.pNext = NULL;
17543 image_alloc_info.memoryTypeIndex = 0;
17544 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017545 bool pass =
17546 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 -070017547 ASSERT_TRUE(pass);
17548 VkDeviceMemory mem;
17549 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17550 ASSERT_VK_SUCCESS(err);
17551 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17552 ASSERT_VK_SUCCESS(err);
17553 // -----------------------
17554
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017555 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017556 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017557 image_view_create_info.image = image_bad;
17558 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17559 image_view_create_info.format = tex_format_bad;
17560 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17561 image_view_create_info.subresourceRange.baseMipLevel = 0;
17562 image_view_create_info.subresourceRange.layerCount = 1;
17563 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017564 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017565
17566 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017567 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017568
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017569 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017570
Chia-I Wuf7458c52015-10-26 21:10:41 +080017571 vkDestroyImage(m_device->device(), image_bad, NULL);
17572 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017573 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17574 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017575
17576 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017577}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017578
17579TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017580 TEST_DESCRIPTION(
17581 "Call ClearColorImage w/ a depth|stencil image and "
17582 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017583
17584 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017585 auto depth_format = find_depth_stencil_format(m_device);
17586 if (!depth_format) {
17587 return;
17588 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17590
Tony Barbour552f6c02016-12-21 14:34:07 -070017591 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017592
17593 // Color image
17594 VkClearColorValue clear_color;
17595 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17596 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17597 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17598 const int32_t img_width = 32;
17599 const int32_t img_height = 32;
17600 VkImageCreateInfo image_create_info = {};
17601 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17602 image_create_info.pNext = NULL;
17603 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17604 image_create_info.format = color_format;
17605 image_create_info.extent.width = img_width;
17606 image_create_info.extent.height = img_height;
17607 image_create_info.extent.depth = 1;
17608 image_create_info.mipLevels = 1;
17609 image_create_info.arrayLayers = 1;
17610 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17611 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17612 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17613
17614 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017615 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017617 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017618
17619 // Depth/Stencil image
17620 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017621 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017622 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17623 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070017624 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017625 ds_image_create_info.extent.width = 64;
17626 ds_image_create_info.extent.height = 64;
17627 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017628 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 -060017629
17630 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017631 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017632
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017633 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 -060017634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017636
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017637 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017638 &color_range);
17639
17640 m_errorMonitor->VerifyFound();
17641
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17643 "vkCmdClearColorImage called with "
17644 "image created without "
17645 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017646
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017647 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017648 &color_range);
17649
17650 m_errorMonitor->VerifyFound();
17651
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017652 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17654 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017655
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017656 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17657 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017658
17659 m_errorMonitor->VerifyFound();
17660}
Tobin Ehliscde08892015-09-22 10:11:37 -060017661
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017662// WSI Enabled Tests
17663//
Chris Forbes09368e42016-10-13 11:59:22 +130017664#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017665TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17666
17667#if defined(VK_USE_PLATFORM_XCB_KHR)
17668 VkSurfaceKHR surface = VK_NULL_HANDLE;
17669
17670 VkResult err;
17671 bool pass;
17672 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17673 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17674 // uint32_t swapchain_image_count = 0;
17675 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17676 // uint32_t image_index = 0;
17677 // VkPresentInfoKHR present_info = {};
17678
17679 ASSERT_NO_FATAL_FAILURE(InitState());
17680
17681 // Use the create function from one of the VK_KHR_*_surface extension in
17682 // order to create a surface, testing all known errors in the process,
17683 // before successfully creating a surface:
17684 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17686 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17687 pass = (err != VK_SUCCESS);
17688 ASSERT_TRUE(pass);
17689 m_errorMonitor->VerifyFound();
17690
17691 // Next, try to create a surface with the wrong
17692 // VkXcbSurfaceCreateInfoKHR::sType:
17693 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17694 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17696 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17697 pass = (err != VK_SUCCESS);
17698 ASSERT_TRUE(pass);
17699 m_errorMonitor->VerifyFound();
17700
17701 // Create a native window, and then correctly create a surface:
17702 xcb_connection_t *connection;
17703 xcb_screen_t *screen;
17704 xcb_window_t xcb_window;
17705 xcb_intern_atom_reply_t *atom_wm_delete_window;
17706
17707 const xcb_setup_t *setup;
17708 xcb_screen_iterator_t iter;
17709 int scr;
17710 uint32_t value_mask, value_list[32];
17711 int width = 1;
17712 int height = 1;
17713
17714 connection = xcb_connect(NULL, &scr);
17715 ASSERT_TRUE(connection != NULL);
17716 setup = xcb_get_setup(connection);
17717 iter = xcb_setup_roots_iterator(setup);
17718 while (scr-- > 0)
17719 xcb_screen_next(&iter);
17720 screen = iter.data;
17721
17722 xcb_window = xcb_generate_id(connection);
17723
17724 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17725 value_list[0] = screen->black_pixel;
17726 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17727
17728 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17729 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17730
17731 /* Magic code that will send notification when window is destroyed */
17732 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17733 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17734
17735 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17736 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17737 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17738 free(reply);
17739
17740 xcb_map_window(connection, xcb_window);
17741
17742 // Force the x/y coordinates to 100,100 results are identical in consecutive
17743 // runs
17744 const uint32_t coords[] = { 100, 100 };
17745 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17746
17747 // Finally, try to correctly create a surface:
17748 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17749 xcb_create_info.pNext = NULL;
17750 xcb_create_info.flags = 0;
17751 xcb_create_info.connection = connection;
17752 xcb_create_info.window = xcb_window;
17753 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17754 pass = (err == VK_SUCCESS);
17755 ASSERT_TRUE(pass);
17756
17757 // Check if surface supports presentation:
17758
17759 // 1st, do so without having queried the queue families:
17760 VkBool32 supported = false;
17761 // TODO: Get the following error to come out:
17762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17763 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17764 "function");
17765 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17766 pass = (err != VK_SUCCESS);
17767 // ASSERT_TRUE(pass);
17768 // m_errorMonitor->VerifyFound();
17769
17770 // Next, query a queue family index that's too large:
17771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17772 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17773 pass = (err != VK_SUCCESS);
17774 ASSERT_TRUE(pass);
17775 m_errorMonitor->VerifyFound();
17776
17777 // Finally, do so correctly:
17778 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17779 // SUPPORTED
17780 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17781 pass = (err == VK_SUCCESS);
17782 ASSERT_TRUE(pass);
17783
17784 // Before proceeding, try to create a swapchain without having called
17785 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17786 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17787 swapchain_create_info.pNext = NULL;
17788 swapchain_create_info.flags = 0;
17789 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17790 swapchain_create_info.surface = surface;
17791 swapchain_create_info.imageArrayLayers = 1;
17792 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17793 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17795 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17796 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17797 pass = (err != VK_SUCCESS);
17798 ASSERT_TRUE(pass);
17799 m_errorMonitor->VerifyFound();
17800
17801 // Get the surface capabilities:
17802 VkSurfaceCapabilitiesKHR surface_capabilities;
17803
17804 // Do so correctly (only error logged by this entrypoint is if the
17805 // extension isn't enabled):
17806 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17807 pass = (err == VK_SUCCESS);
17808 ASSERT_TRUE(pass);
17809
17810 // Get the surface formats:
17811 uint32_t surface_format_count;
17812
17813 // First, try without a pointer to surface_format_count:
17814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17815 "specified as NULL");
17816 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17817 pass = (err == VK_SUCCESS);
17818 ASSERT_TRUE(pass);
17819 m_errorMonitor->VerifyFound();
17820
17821 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17822 // correctly done a 1st try (to get the count):
17823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17824 surface_format_count = 0;
17825 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17826 pass = (err == VK_SUCCESS);
17827 ASSERT_TRUE(pass);
17828 m_errorMonitor->VerifyFound();
17829
17830 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17831 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17832 pass = (err == VK_SUCCESS);
17833 ASSERT_TRUE(pass);
17834
17835 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17836 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17837
17838 // Next, do a 2nd try with surface_format_count being set too high:
17839 surface_format_count += 5;
17840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17841 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17842 pass = (err == VK_SUCCESS);
17843 ASSERT_TRUE(pass);
17844 m_errorMonitor->VerifyFound();
17845
17846 // Finally, do a correct 1st and 2nd try:
17847 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17848 pass = (err == VK_SUCCESS);
17849 ASSERT_TRUE(pass);
17850 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17851 pass = (err == VK_SUCCESS);
17852 ASSERT_TRUE(pass);
17853
17854 // Get the surface present modes:
17855 uint32_t surface_present_mode_count;
17856
17857 // First, try without a pointer to surface_format_count:
17858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17859 "specified as NULL");
17860
17861 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17862 pass = (err == VK_SUCCESS);
17863 ASSERT_TRUE(pass);
17864 m_errorMonitor->VerifyFound();
17865
17866 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17867 // correctly done a 1st try (to get the count):
17868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17869 surface_present_mode_count = 0;
17870 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17871 (VkPresentModeKHR *)&surface_present_mode_count);
17872 pass = (err == VK_SUCCESS);
17873 ASSERT_TRUE(pass);
17874 m_errorMonitor->VerifyFound();
17875
17876 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17877 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17878 pass = (err == VK_SUCCESS);
17879 ASSERT_TRUE(pass);
17880
17881 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17882 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17883
17884 // Next, do a 2nd try with surface_format_count being set too high:
17885 surface_present_mode_count += 5;
17886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17887 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17888 pass = (err == VK_SUCCESS);
17889 ASSERT_TRUE(pass);
17890 m_errorMonitor->VerifyFound();
17891
17892 // Finally, do a correct 1st and 2nd try:
17893 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17894 pass = (err == VK_SUCCESS);
17895 ASSERT_TRUE(pass);
17896 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17897 pass = (err == VK_SUCCESS);
17898 ASSERT_TRUE(pass);
17899
17900 // Create a swapchain:
17901
17902 // First, try without a pointer to swapchain_create_info:
17903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17904 "specified as NULL");
17905
17906 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17907 pass = (err != VK_SUCCESS);
17908 ASSERT_TRUE(pass);
17909 m_errorMonitor->VerifyFound();
17910
17911 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17912 // sType:
17913 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17915
17916 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17917 pass = (err != VK_SUCCESS);
17918 ASSERT_TRUE(pass);
17919 m_errorMonitor->VerifyFound();
17920
17921 // Next, call with a NULL swapchain pointer:
17922 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17923 swapchain_create_info.pNext = NULL;
17924 swapchain_create_info.flags = 0;
17925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17926 "specified as NULL");
17927
17928 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17929 pass = (err != VK_SUCCESS);
17930 ASSERT_TRUE(pass);
17931 m_errorMonitor->VerifyFound();
17932
17933 // TODO: Enhance swapchain layer so that
17934 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17935
17936 // Next, call with a queue family index that's too large:
17937 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17938 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17939 swapchain_create_info.queueFamilyIndexCount = 2;
17940 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17942 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17943 pass = (err != VK_SUCCESS);
17944 ASSERT_TRUE(pass);
17945 m_errorMonitor->VerifyFound();
17946
17947 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17948 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17949 swapchain_create_info.queueFamilyIndexCount = 1;
17950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17951 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17952 "pCreateInfo->pQueueFamilyIndices).");
17953 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17954 pass = (err != VK_SUCCESS);
17955 ASSERT_TRUE(pass);
17956 m_errorMonitor->VerifyFound();
17957
17958 // Next, call with an invalid imageSharingMode:
17959 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17960 swapchain_create_info.queueFamilyIndexCount = 1;
17961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17962 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17963 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17964 pass = (err != VK_SUCCESS);
17965 ASSERT_TRUE(pass);
17966 m_errorMonitor->VerifyFound();
17967 // Fix for the future:
17968 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17969 // SUPPORTED
17970 swapchain_create_info.queueFamilyIndexCount = 0;
17971 queueFamilyIndex[0] = 0;
17972 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17973
17974 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17975 // Get the images from a swapchain:
17976 // Acquire an image from a swapchain:
17977 // Present an image to a swapchain:
17978 // Destroy the swapchain:
17979
17980 // TODOs:
17981 //
17982 // - Try destroying the device without first destroying the swapchain
17983 //
17984 // - Try destroying the device without first destroying the surface
17985 //
17986 // - Try destroying the surface without first destroying the swapchain
17987
17988 // Destroy the surface:
17989 vkDestroySurfaceKHR(instance(), surface, NULL);
17990
17991 // Tear down the window:
17992 xcb_destroy_window(connection, xcb_window);
17993 xcb_disconnect(connection);
17994
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017995#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017996 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017997#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017998}
Chris Forbes09368e42016-10-13 11:59:22 +130017999#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018000
18001//
18002// POSITIVE VALIDATION TESTS
18003//
18004// These tests do not expect to encounter ANY validation errors pass only if this is true
18005
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070018006TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
18007 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
18008 ASSERT_NO_FATAL_FAILURE(InitState());
18009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18010
18011 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18012 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18013 command_buffer_allocate_info.commandPool = m_commandPool;
18014 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18015 command_buffer_allocate_info.commandBufferCount = 1;
18016
18017 VkCommandBuffer secondary_command_buffer;
18018 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18019 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18020 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18021 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18022 command_buffer_inheritance_info.renderPass = m_renderPass;
18023 command_buffer_inheritance_info.framebuffer = m_framebuffer;
18024
18025 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18026 command_buffer_begin_info.flags =
18027 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
18028 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18029
18030 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18031 VkClearAttachment color_attachment;
18032 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18033 color_attachment.clearValue.color.float32[0] = 0;
18034 color_attachment.clearValue.color.float32[1] = 0;
18035 color_attachment.clearValue.color.float32[2] = 0;
18036 color_attachment.clearValue.color.float32[3] = 0;
18037 color_attachment.colorAttachment = 0;
18038 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
18039 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
18040}
18041
Tobin Ehlise0006882016-11-03 10:14:28 -060018042TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018043 TEST_DESCRIPTION(
18044 "Perform an image layout transition in a secondary command buffer followed "
18045 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060018046 VkResult err;
18047 m_errorMonitor->ExpectSuccess();
18048 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070018049 auto depth_format = find_depth_stencil_format(m_device);
18050 if (!depth_format) {
18051 return;
18052 }
Tobin Ehlise0006882016-11-03 10:14:28 -060018053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18054 // Allocate a secondary and primary cmd buffer
18055 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18056 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18057 command_buffer_allocate_info.commandPool = m_commandPool;
18058 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18059 command_buffer_allocate_info.commandBufferCount = 1;
18060
18061 VkCommandBuffer secondary_command_buffer;
18062 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18063 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18064 VkCommandBuffer primary_command_buffer;
18065 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
18066 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18067 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18068 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18069 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18070 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
18071 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18072
18073 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18074 ASSERT_VK_SUCCESS(err);
18075 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070018076 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 -060018077 ASSERT_TRUE(image.initialized());
18078 VkImageMemoryBarrier img_barrier = {};
18079 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18080 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18081 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18082 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18083 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18084 img_barrier.image = image.handle();
18085 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18086 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18087 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18088 img_barrier.subresourceRange.baseArrayLayer = 0;
18089 img_barrier.subresourceRange.baseMipLevel = 0;
18090 img_barrier.subresourceRange.layerCount = 1;
18091 img_barrier.subresourceRange.levelCount = 1;
18092 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
18093 0, nullptr, 1, &img_barrier);
18094 err = vkEndCommandBuffer(secondary_command_buffer);
18095 ASSERT_VK_SUCCESS(err);
18096
18097 // Now update primary cmd buffer to execute secondary and transitions image
18098 command_buffer_begin_info.pInheritanceInfo = nullptr;
18099 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
18100 ASSERT_VK_SUCCESS(err);
18101 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
18102 VkImageMemoryBarrier img_barrier2 = {};
18103 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18104 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18105 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18106 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18107 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18108 img_barrier2.image = image.handle();
18109 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18110 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18111 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18112 img_barrier2.subresourceRange.baseArrayLayer = 0;
18113 img_barrier2.subresourceRange.baseMipLevel = 0;
18114 img_barrier2.subresourceRange.layerCount = 1;
18115 img_barrier2.subresourceRange.levelCount = 1;
18116 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
18117 nullptr, 1, &img_barrier2);
18118 err = vkEndCommandBuffer(primary_command_buffer);
18119 ASSERT_VK_SUCCESS(err);
18120 VkSubmitInfo submit_info = {};
18121 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18122 submit_info.commandBufferCount = 1;
18123 submit_info.pCommandBuffers = &primary_command_buffer;
18124 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18125 ASSERT_VK_SUCCESS(err);
18126 m_errorMonitor->VerifyNotFound();
18127 err = vkDeviceWaitIdle(m_device->device());
18128 ASSERT_VK_SUCCESS(err);
18129 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
18130 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
18131}
18132
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018133// This is a positive test. No failures are expected.
18134TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018135 TEST_DESCRIPTION(
18136 "Ensure that the vkUpdateDescriptorSets validation code "
18137 "is ignoring VkWriteDescriptorSet members that are not "
18138 "related to the descriptor type specified by "
18139 "VkWriteDescriptorSet::descriptorType. Correct "
18140 "validation behavior will result in the test running to "
18141 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018142
18143 const uintptr_t invalid_ptr = 0xcdcdcdcd;
18144
18145 ASSERT_NO_FATAL_FAILURE(InitState());
18146
18147 // Image Case
18148 {
18149 m_errorMonitor->ExpectSuccess();
18150
18151 VkImage image;
18152 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
18153 const int32_t tex_width = 32;
18154 const int32_t tex_height = 32;
18155 VkImageCreateInfo image_create_info = {};
18156 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18157 image_create_info.pNext = NULL;
18158 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18159 image_create_info.format = tex_format;
18160 image_create_info.extent.width = tex_width;
18161 image_create_info.extent.height = tex_height;
18162 image_create_info.extent.depth = 1;
18163 image_create_info.mipLevels = 1;
18164 image_create_info.arrayLayers = 1;
18165 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18166 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18167 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18168 image_create_info.flags = 0;
18169 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18170 ASSERT_VK_SUCCESS(err);
18171
18172 VkMemoryRequirements memory_reqs;
18173 VkDeviceMemory image_memory;
18174 bool pass;
18175 VkMemoryAllocateInfo memory_info = {};
18176 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18177 memory_info.pNext = NULL;
18178 memory_info.allocationSize = 0;
18179 memory_info.memoryTypeIndex = 0;
18180 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18181 memory_info.allocationSize = memory_reqs.size;
18182 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18183 ASSERT_TRUE(pass);
18184 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
18185 ASSERT_VK_SUCCESS(err);
18186 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
18187 ASSERT_VK_SUCCESS(err);
18188
18189 VkImageViewCreateInfo image_view_create_info = {};
18190 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18191 image_view_create_info.image = image;
18192 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18193 image_view_create_info.format = tex_format;
18194 image_view_create_info.subresourceRange.layerCount = 1;
18195 image_view_create_info.subresourceRange.baseMipLevel = 0;
18196 image_view_create_info.subresourceRange.levelCount = 1;
18197 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18198
18199 VkImageView view;
18200 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
18201 ASSERT_VK_SUCCESS(err);
18202
18203 VkDescriptorPoolSize ds_type_count = {};
18204 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18205 ds_type_count.descriptorCount = 1;
18206
18207 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18208 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18209 ds_pool_ci.pNext = NULL;
18210 ds_pool_ci.maxSets = 1;
18211 ds_pool_ci.poolSizeCount = 1;
18212 ds_pool_ci.pPoolSizes = &ds_type_count;
18213
18214 VkDescriptorPool ds_pool;
18215 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18216 ASSERT_VK_SUCCESS(err);
18217
18218 VkDescriptorSetLayoutBinding dsl_binding = {};
18219 dsl_binding.binding = 0;
18220 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18221 dsl_binding.descriptorCount = 1;
18222 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18223 dsl_binding.pImmutableSamplers = NULL;
18224
18225 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18226 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18227 ds_layout_ci.pNext = NULL;
18228 ds_layout_ci.bindingCount = 1;
18229 ds_layout_ci.pBindings = &dsl_binding;
18230 VkDescriptorSetLayout ds_layout;
18231 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18232 ASSERT_VK_SUCCESS(err);
18233
18234 VkDescriptorSet descriptor_set;
18235 VkDescriptorSetAllocateInfo alloc_info = {};
18236 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18237 alloc_info.descriptorSetCount = 1;
18238 alloc_info.descriptorPool = ds_pool;
18239 alloc_info.pSetLayouts = &ds_layout;
18240 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18241 ASSERT_VK_SUCCESS(err);
18242
18243 VkDescriptorImageInfo image_info = {};
18244 image_info.imageView = view;
18245 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18246
18247 VkWriteDescriptorSet descriptor_write;
18248 memset(&descriptor_write, 0, sizeof(descriptor_write));
18249 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18250 descriptor_write.dstSet = descriptor_set;
18251 descriptor_write.dstBinding = 0;
18252 descriptor_write.descriptorCount = 1;
18253 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18254 descriptor_write.pImageInfo = &image_info;
18255
18256 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18257 // be
18258 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18259 // This will most likely produce a crash if the parameter_validation
18260 // layer
18261 // does not correctly ignore pBufferInfo.
18262 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18263 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18264
18265 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18266
18267 m_errorMonitor->VerifyNotFound();
18268
18269 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18270 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18271 vkDestroyImageView(m_device->device(), view, NULL);
18272 vkDestroyImage(m_device->device(), image, NULL);
18273 vkFreeMemory(m_device->device(), image_memory, NULL);
18274 }
18275
18276 // Buffer Case
18277 {
18278 m_errorMonitor->ExpectSuccess();
18279
18280 VkBuffer buffer;
18281 uint32_t queue_family_index = 0;
18282 VkBufferCreateInfo buffer_create_info = {};
18283 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18284 buffer_create_info.size = 1024;
18285 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18286 buffer_create_info.queueFamilyIndexCount = 1;
18287 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18288
18289 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18290 ASSERT_VK_SUCCESS(err);
18291
18292 VkMemoryRequirements memory_reqs;
18293 VkDeviceMemory buffer_memory;
18294 bool pass;
18295 VkMemoryAllocateInfo memory_info = {};
18296 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18297 memory_info.pNext = NULL;
18298 memory_info.allocationSize = 0;
18299 memory_info.memoryTypeIndex = 0;
18300
18301 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18302 memory_info.allocationSize = memory_reqs.size;
18303 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18304 ASSERT_TRUE(pass);
18305
18306 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18307 ASSERT_VK_SUCCESS(err);
18308 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18309 ASSERT_VK_SUCCESS(err);
18310
18311 VkDescriptorPoolSize ds_type_count = {};
18312 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18313 ds_type_count.descriptorCount = 1;
18314
18315 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18316 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18317 ds_pool_ci.pNext = NULL;
18318 ds_pool_ci.maxSets = 1;
18319 ds_pool_ci.poolSizeCount = 1;
18320 ds_pool_ci.pPoolSizes = &ds_type_count;
18321
18322 VkDescriptorPool ds_pool;
18323 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18324 ASSERT_VK_SUCCESS(err);
18325
18326 VkDescriptorSetLayoutBinding dsl_binding = {};
18327 dsl_binding.binding = 0;
18328 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18329 dsl_binding.descriptorCount = 1;
18330 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18331 dsl_binding.pImmutableSamplers = NULL;
18332
18333 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18334 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18335 ds_layout_ci.pNext = NULL;
18336 ds_layout_ci.bindingCount = 1;
18337 ds_layout_ci.pBindings = &dsl_binding;
18338 VkDescriptorSetLayout ds_layout;
18339 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18340 ASSERT_VK_SUCCESS(err);
18341
18342 VkDescriptorSet descriptor_set;
18343 VkDescriptorSetAllocateInfo alloc_info = {};
18344 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18345 alloc_info.descriptorSetCount = 1;
18346 alloc_info.descriptorPool = ds_pool;
18347 alloc_info.pSetLayouts = &ds_layout;
18348 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18349 ASSERT_VK_SUCCESS(err);
18350
18351 VkDescriptorBufferInfo buffer_info = {};
18352 buffer_info.buffer = buffer;
18353 buffer_info.offset = 0;
18354 buffer_info.range = 1024;
18355
18356 VkWriteDescriptorSet descriptor_write;
18357 memset(&descriptor_write, 0, sizeof(descriptor_write));
18358 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18359 descriptor_write.dstSet = descriptor_set;
18360 descriptor_write.dstBinding = 0;
18361 descriptor_write.descriptorCount = 1;
18362 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18363 descriptor_write.pBufferInfo = &buffer_info;
18364
18365 // Set pImageInfo and pTexelBufferView to invalid values, which should
18366 // be
18367 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18368 // This will most likely produce a crash if the parameter_validation
18369 // layer
18370 // does not correctly ignore pImageInfo.
18371 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18372 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18373
18374 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18375
18376 m_errorMonitor->VerifyNotFound();
18377
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018378 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18379 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18380 vkDestroyBuffer(m_device->device(), buffer, NULL);
18381 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18382 }
18383
18384 // Texel Buffer Case
18385 {
18386 m_errorMonitor->ExpectSuccess();
18387
18388 VkBuffer buffer;
18389 uint32_t queue_family_index = 0;
18390 VkBufferCreateInfo buffer_create_info = {};
18391 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18392 buffer_create_info.size = 1024;
18393 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18394 buffer_create_info.queueFamilyIndexCount = 1;
18395 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18396
18397 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18398 ASSERT_VK_SUCCESS(err);
18399
18400 VkMemoryRequirements memory_reqs;
18401 VkDeviceMemory buffer_memory;
18402 bool pass;
18403 VkMemoryAllocateInfo memory_info = {};
18404 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18405 memory_info.pNext = NULL;
18406 memory_info.allocationSize = 0;
18407 memory_info.memoryTypeIndex = 0;
18408
18409 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18410 memory_info.allocationSize = memory_reqs.size;
18411 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18412 ASSERT_TRUE(pass);
18413
18414 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18415 ASSERT_VK_SUCCESS(err);
18416 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18417 ASSERT_VK_SUCCESS(err);
18418
18419 VkBufferViewCreateInfo buff_view_ci = {};
18420 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18421 buff_view_ci.buffer = buffer;
18422 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18423 buff_view_ci.range = VK_WHOLE_SIZE;
18424 VkBufferView buffer_view;
18425 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18426
18427 VkDescriptorPoolSize ds_type_count = {};
18428 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18429 ds_type_count.descriptorCount = 1;
18430
18431 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18432 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18433 ds_pool_ci.pNext = NULL;
18434 ds_pool_ci.maxSets = 1;
18435 ds_pool_ci.poolSizeCount = 1;
18436 ds_pool_ci.pPoolSizes = &ds_type_count;
18437
18438 VkDescriptorPool ds_pool;
18439 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18440 ASSERT_VK_SUCCESS(err);
18441
18442 VkDescriptorSetLayoutBinding dsl_binding = {};
18443 dsl_binding.binding = 0;
18444 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18445 dsl_binding.descriptorCount = 1;
18446 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18447 dsl_binding.pImmutableSamplers = NULL;
18448
18449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18451 ds_layout_ci.pNext = NULL;
18452 ds_layout_ci.bindingCount = 1;
18453 ds_layout_ci.pBindings = &dsl_binding;
18454 VkDescriptorSetLayout ds_layout;
18455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18456 ASSERT_VK_SUCCESS(err);
18457
18458 VkDescriptorSet descriptor_set;
18459 VkDescriptorSetAllocateInfo alloc_info = {};
18460 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18461 alloc_info.descriptorSetCount = 1;
18462 alloc_info.descriptorPool = ds_pool;
18463 alloc_info.pSetLayouts = &ds_layout;
18464 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18465 ASSERT_VK_SUCCESS(err);
18466
18467 VkWriteDescriptorSet descriptor_write;
18468 memset(&descriptor_write, 0, sizeof(descriptor_write));
18469 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18470 descriptor_write.dstSet = descriptor_set;
18471 descriptor_write.dstBinding = 0;
18472 descriptor_write.descriptorCount = 1;
18473 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18474 descriptor_write.pTexelBufferView = &buffer_view;
18475
18476 // Set pImageInfo and pBufferInfo to invalid values, which should be
18477 // ignored for descriptorType ==
18478 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18479 // This will most likely produce a crash if the parameter_validation
18480 // layer
18481 // does not correctly ignore pImageInfo and pBufferInfo.
18482 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18483 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18484
18485 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18486
18487 m_errorMonitor->VerifyNotFound();
18488
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018489 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18490 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18491 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18492 vkDestroyBuffer(m_device->device(), buffer, NULL);
18493 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18494 }
18495}
18496
Tobin Ehlisf7428442016-10-25 07:58:24 -060018497TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18498 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18499
18500 ASSERT_NO_FATAL_FAILURE(InitState());
18501 // Create layout where two binding #s are "1"
18502 static const uint32_t NUM_BINDINGS = 3;
18503 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18504 dsl_binding[0].binding = 1;
18505 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18506 dsl_binding[0].descriptorCount = 1;
18507 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18508 dsl_binding[0].pImmutableSamplers = NULL;
18509 dsl_binding[1].binding = 0;
18510 dsl_binding[1].descriptorCount = 1;
18511 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18512 dsl_binding[1].descriptorCount = 1;
18513 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18514 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018515 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018516 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18517 dsl_binding[2].descriptorCount = 1;
18518 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18519 dsl_binding[2].pImmutableSamplers = NULL;
18520
18521 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18522 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18523 ds_layout_ci.pNext = NULL;
18524 ds_layout_ci.bindingCount = NUM_BINDINGS;
18525 ds_layout_ci.pBindings = dsl_binding;
18526 VkDescriptorSetLayout ds_layout;
18527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18528 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18529 m_errorMonitor->VerifyFound();
18530}
18531
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018532TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018533 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18534
18535 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018536
Tony Barbour552f6c02016-12-21 14:34:07 -070018537 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018538
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018539 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18540
18541 {
18542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18543 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18544 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18545 m_errorMonitor->VerifyFound();
18546 }
18547
18548 {
18549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18550 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18551 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18552 m_errorMonitor->VerifyFound();
18553 }
18554
18555 {
18556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18557 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18558 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18559 m_errorMonitor->VerifyFound();
18560 }
18561
18562 {
18563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18564 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18565 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18566 m_errorMonitor->VerifyFound();
18567 }
18568
18569 {
18570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18571 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18572 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18573 m_errorMonitor->VerifyFound();
18574 }
18575
18576 {
18577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18578 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18579 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18580 m_errorMonitor->VerifyFound();
18581 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018582
18583 {
18584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18585 VkRect2D scissor = {{-1, 0}, {16, 16}};
18586 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18587 m_errorMonitor->VerifyFound();
18588 }
18589
18590 {
18591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18592 VkRect2D scissor = {{0, -2}, {16, 16}};
18593 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18594 m_errorMonitor->VerifyFound();
18595 }
18596
18597 {
18598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18599 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18600 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18601 m_errorMonitor->VerifyFound();
18602 }
18603
18604 {
18605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18606 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18607 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18608 m_errorMonitor->VerifyFound();
18609 }
18610
Tony Barbour552f6c02016-12-21 14:34:07 -070018611 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018612}
18613
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018614// This is a positive test. No failures are expected.
18615TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18616 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18617 VkResult err;
18618
18619 ASSERT_NO_FATAL_FAILURE(InitState());
18620 m_errorMonitor->ExpectSuccess();
18621 VkDescriptorPoolSize ds_type_count = {};
18622 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18623 ds_type_count.descriptorCount = 2;
18624
18625 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18626 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18627 ds_pool_ci.pNext = NULL;
18628 ds_pool_ci.maxSets = 1;
18629 ds_pool_ci.poolSizeCount = 1;
18630 ds_pool_ci.pPoolSizes = &ds_type_count;
18631
18632 VkDescriptorPool ds_pool;
18633 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18634 ASSERT_VK_SUCCESS(err);
18635
18636 // Create layout with two uniform buffer descriptors w/ empty binding between them
18637 static const uint32_t NUM_BINDINGS = 3;
18638 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18639 dsl_binding[0].binding = 0;
18640 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18641 dsl_binding[0].descriptorCount = 1;
18642 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18643 dsl_binding[0].pImmutableSamplers = NULL;
18644 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018645 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018646 dsl_binding[2].binding = 2;
18647 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18648 dsl_binding[2].descriptorCount = 1;
18649 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18650 dsl_binding[2].pImmutableSamplers = NULL;
18651
18652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18653 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18654 ds_layout_ci.pNext = NULL;
18655 ds_layout_ci.bindingCount = NUM_BINDINGS;
18656 ds_layout_ci.pBindings = dsl_binding;
18657 VkDescriptorSetLayout ds_layout;
18658 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18659 ASSERT_VK_SUCCESS(err);
18660
18661 VkDescriptorSet descriptor_set = {};
18662 VkDescriptorSetAllocateInfo alloc_info = {};
18663 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18664 alloc_info.descriptorSetCount = 1;
18665 alloc_info.descriptorPool = ds_pool;
18666 alloc_info.pSetLayouts = &ds_layout;
18667 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18668 ASSERT_VK_SUCCESS(err);
18669
18670 // Create a buffer to be used for update
18671 VkBufferCreateInfo buff_ci = {};
18672 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18673 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18674 buff_ci.size = 256;
18675 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18676 VkBuffer buffer;
18677 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18678 ASSERT_VK_SUCCESS(err);
18679 // Have to bind memory to buffer before descriptor update
18680 VkMemoryAllocateInfo mem_alloc = {};
18681 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18682 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018683 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018684 mem_alloc.memoryTypeIndex = 0;
18685
18686 VkMemoryRequirements mem_reqs;
18687 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18688 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18689 if (!pass) {
18690 vkDestroyBuffer(m_device->device(), buffer, NULL);
18691 return;
18692 }
18693
18694 VkDeviceMemory mem;
18695 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18696 ASSERT_VK_SUCCESS(err);
18697 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18698 ASSERT_VK_SUCCESS(err);
18699
18700 // Only update the descriptor at binding 2
18701 VkDescriptorBufferInfo buff_info = {};
18702 buff_info.buffer = buffer;
18703 buff_info.offset = 0;
18704 buff_info.range = VK_WHOLE_SIZE;
18705 VkWriteDescriptorSet descriptor_write = {};
18706 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18707 descriptor_write.dstBinding = 2;
18708 descriptor_write.descriptorCount = 1;
18709 descriptor_write.pTexelBufferView = nullptr;
18710 descriptor_write.pBufferInfo = &buff_info;
18711 descriptor_write.pImageInfo = nullptr;
18712 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18713 descriptor_write.dstSet = descriptor_set;
18714
18715 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18716
18717 m_errorMonitor->VerifyNotFound();
18718 // Cleanup
18719 vkFreeMemory(m_device->device(), mem, NULL);
18720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18721 vkDestroyBuffer(m_device->device(), buffer, NULL);
18722 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18723}
18724
18725// This is a positive test. No failures are expected.
18726TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18727 VkResult err;
18728 bool pass;
18729
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018730 TEST_DESCRIPTION(
18731 "Create a buffer, allocate memory, bind memory, destroy "
18732 "the buffer, create an image, and bind the same memory to "
18733 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018734
18735 m_errorMonitor->ExpectSuccess();
18736
18737 ASSERT_NO_FATAL_FAILURE(InitState());
18738
18739 VkBuffer buffer;
18740 VkImage image;
18741 VkDeviceMemory mem;
18742 VkMemoryRequirements mem_reqs;
18743
18744 VkBufferCreateInfo buf_info = {};
18745 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18746 buf_info.pNext = NULL;
18747 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18748 buf_info.size = 256;
18749 buf_info.queueFamilyIndexCount = 0;
18750 buf_info.pQueueFamilyIndices = NULL;
18751 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18752 buf_info.flags = 0;
18753 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18754 ASSERT_VK_SUCCESS(err);
18755
18756 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18757
18758 VkMemoryAllocateInfo alloc_info = {};
18759 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18760 alloc_info.pNext = NULL;
18761 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018762
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018763 // Ensure memory is big enough for both bindings
18764 alloc_info.allocationSize = 0x10000;
18765
18766 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18767 if (!pass) {
18768 vkDestroyBuffer(m_device->device(), buffer, NULL);
18769 return;
18770 }
18771
18772 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18773 ASSERT_VK_SUCCESS(err);
18774
18775 uint8_t *pData;
18776 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18777 ASSERT_VK_SUCCESS(err);
18778
18779 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18780
18781 vkUnmapMemory(m_device->device(), mem);
18782
18783 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18784 ASSERT_VK_SUCCESS(err);
18785
18786 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18787 // memory. In fact, it was never used by the GPU.
18788 // Just be be sure, wait for idle.
18789 vkDestroyBuffer(m_device->device(), buffer, NULL);
18790 vkDeviceWaitIdle(m_device->device());
18791
Tobin Ehlis6a005702016-12-28 15:25:56 -070018792 // Use optimal as some platforms report linear support but then fail image creation
18793 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18794 VkImageFormatProperties image_format_properties;
18795 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18796 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18797 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018798 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018799 vkFreeMemory(m_device->device(), mem, NULL);
18800 return;
18801 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018802 VkImageCreateInfo image_create_info = {};
18803 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18804 image_create_info.pNext = NULL;
18805 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18806 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18807 image_create_info.extent.width = 64;
18808 image_create_info.extent.height = 64;
18809 image_create_info.extent.depth = 1;
18810 image_create_info.mipLevels = 1;
18811 image_create_info.arrayLayers = 1;
18812 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018813 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018814 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18815 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18816 image_create_info.queueFamilyIndexCount = 0;
18817 image_create_info.pQueueFamilyIndices = NULL;
18818 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18819 image_create_info.flags = 0;
18820
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018821 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018822 * to be textures or it will be the staging image if they are not.
18823 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018824 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18825 ASSERT_VK_SUCCESS(err);
18826
18827 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18828
Tobin Ehlis6a005702016-12-28 15:25:56 -070018829 VkMemoryAllocateInfo mem_alloc = {};
18830 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18831 mem_alloc.pNext = NULL;
18832 mem_alloc.allocationSize = 0;
18833 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018834 mem_alloc.allocationSize = mem_reqs.size;
18835
18836 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18837 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018838 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018839 vkDestroyImage(m_device->device(), image, NULL);
18840 return;
18841 }
18842
18843 // VALIDATION FAILURE:
18844 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18845 ASSERT_VK_SUCCESS(err);
18846
18847 m_errorMonitor->VerifyNotFound();
18848
18849 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018850 vkDestroyImage(m_device->device(), image, NULL);
18851}
18852
Tony Barbourab713912017-02-02 14:17:35 -070018853// This is a positive test. No failures are expected.
18854TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18855 VkResult err;
18856
18857 TEST_DESCRIPTION(
18858 "Call all applicable destroy and free routines with NULL"
18859 "handles, expecting no validation errors");
18860
18861 m_errorMonitor->ExpectSuccess();
18862
18863 ASSERT_NO_FATAL_FAILURE(InitState());
18864 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18865 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18866 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18867 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18868 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18869 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18870 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18871 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18872 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18873 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18874 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18875 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18876 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18877 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18878 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18879 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18880 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18881 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18882 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18883 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18884
18885 VkCommandPool command_pool;
18886 VkCommandPoolCreateInfo pool_create_info{};
18887 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18888 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18889 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18890 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18891 VkCommandBuffer command_buffers[3] = {};
18892 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18893 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18894 command_buffer_allocate_info.commandPool = command_pool;
18895 command_buffer_allocate_info.commandBufferCount = 1;
18896 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18897 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18898 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18899 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18900
18901 VkDescriptorPoolSize ds_type_count = {};
18902 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18903 ds_type_count.descriptorCount = 1;
18904
18905 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18906 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18907 ds_pool_ci.pNext = NULL;
18908 ds_pool_ci.maxSets = 1;
18909 ds_pool_ci.poolSizeCount = 1;
18910 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18911 ds_pool_ci.pPoolSizes = &ds_type_count;
18912
18913 VkDescriptorPool ds_pool;
18914 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18915 ASSERT_VK_SUCCESS(err);
18916
18917 VkDescriptorSetLayoutBinding dsl_binding = {};
18918 dsl_binding.binding = 2;
18919 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18920 dsl_binding.descriptorCount = 1;
18921 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18922 dsl_binding.pImmutableSamplers = NULL;
18923 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18924 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18925 ds_layout_ci.pNext = NULL;
18926 ds_layout_ci.bindingCount = 1;
18927 ds_layout_ci.pBindings = &dsl_binding;
18928 VkDescriptorSetLayout ds_layout;
18929 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18930 ASSERT_VK_SUCCESS(err);
18931
18932 VkDescriptorSet descriptor_sets[3] = {};
18933 VkDescriptorSetAllocateInfo alloc_info = {};
18934 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18935 alloc_info.descriptorSetCount = 1;
18936 alloc_info.descriptorPool = ds_pool;
18937 alloc_info.pSetLayouts = &ds_layout;
18938 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18939 ASSERT_VK_SUCCESS(err);
18940 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18941 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18942 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18943
18944 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18945
18946 m_errorMonitor->VerifyNotFound();
18947}
18948
Tony Barbour626994c2017-02-08 15:29:37 -070018949TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018950 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018951
18952 m_errorMonitor->ExpectSuccess();
18953
18954 ASSERT_NO_FATAL_FAILURE(InitState());
18955 VkCommandBuffer cmd_bufs[4];
18956 VkCommandBufferAllocateInfo alloc_info;
18957 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18958 alloc_info.pNext = NULL;
18959 alloc_info.commandBufferCount = 4;
18960 alloc_info.commandPool = m_commandPool;
18961 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18962 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18963 VkImageObj image(m_device);
18964 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18965 ASSERT_TRUE(image.initialized());
18966 VkCommandBufferBeginInfo cb_binfo;
18967 cb_binfo.pNext = NULL;
18968 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18969 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18970 cb_binfo.flags = 0;
18971 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18972 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18973 VkImageMemoryBarrier img_barrier = {};
18974 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18975 img_barrier.pNext = NULL;
18976 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18977 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18978 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18979 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18980 img_barrier.image = image.handle();
18981 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18982 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18983 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18984 img_barrier.subresourceRange.baseArrayLayer = 0;
18985 img_barrier.subresourceRange.baseMipLevel = 0;
18986 img_barrier.subresourceRange.layerCount = 1;
18987 img_barrier.subresourceRange.levelCount = 1;
18988 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18989 &img_barrier);
18990 vkEndCommandBuffer(cmd_bufs[0]);
18991 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18992 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18993 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18994 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18995 &img_barrier);
18996 vkEndCommandBuffer(cmd_bufs[1]);
18997 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18998 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18999 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19000 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19001 &img_barrier);
19002 vkEndCommandBuffer(cmd_bufs[2]);
19003 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
19004 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19005 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19006 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19007 &img_barrier);
19008 vkEndCommandBuffer(cmd_bufs[3]);
19009
19010 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
19011 VkSemaphore semaphore1, semaphore2;
19012 VkSemaphoreCreateInfo semaphore_create_info{};
19013 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19014 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
19015 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
19016 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
19017 VkSubmitInfo submit_info[3];
19018 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19019 submit_info[0].pNext = nullptr;
19020 submit_info[0].commandBufferCount = 1;
19021 submit_info[0].pCommandBuffers = &cmd_bufs[0];
19022 submit_info[0].signalSemaphoreCount = 1;
19023 submit_info[0].pSignalSemaphores = &semaphore1;
19024 submit_info[0].waitSemaphoreCount = 0;
19025 submit_info[0].pWaitDstStageMask = nullptr;
19026 submit_info[0].pWaitDstStageMask = flags;
19027 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19028 submit_info[1].pNext = nullptr;
19029 submit_info[1].commandBufferCount = 1;
19030 submit_info[1].pCommandBuffers = &cmd_bufs[1];
19031 submit_info[1].waitSemaphoreCount = 1;
19032 submit_info[1].pWaitSemaphores = &semaphore1;
19033 submit_info[1].signalSemaphoreCount = 1;
19034 submit_info[1].pSignalSemaphores = &semaphore2;
19035 submit_info[1].pWaitDstStageMask = flags;
19036 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19037 submit_info[2].pNext = nullptr;
19038 submit_info[2].commandBufferCount = 2;
19039 submit_info[2].pCommandBuffers = &cmd_bufs[2];
19040 submit_info[2].waitSemaphoreCount = 1;
19041 submit_info[2].pWaitSemaphores = &semaphore2;
19042 submit_info[2].signalSemaphoreCount = 0;
19043 submit_info[2].pSignalSemaphores = nullptr;
19044 submit_info[2].pWaitDstStageMask = flags;
19045 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
19046 vkQueueWaitIdle(m_device->m_queue);
19047
19048 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
19049 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
19050 m_errorMonitor->VerifyNotFound();
19051}
19052
Tobin Ehlis953e8392016-11-17 10:54:13 -070019053TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
19054 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
19055 // We previously had a bug where dynamic offset of inactive bindings was still being used
19056 VkResult err;
19057 m_errorMonitor->ExpectSuccess();
19058
19059 ASSERT_NO_FATAL_FAILURE(InitState());
19060 ASSERT_NO_FATAL_FAILURE(InitViewport());
19061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19062
19063 VkDescriptorPoolSize ds_type_count = {};
19064 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19065 ds_type_count.descriptorCount = 3;
19066
19067 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19068 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19069 ds_pool_ci.pNext = NULL;
19070 ds_pool_ci.maxSets = 1;
19071 ds_pool_ci.poolSizeCount = 1;
19072 ds_pool_ci.pPoolSizes = &ds_type_count;
19073
19074 VkDescriptorPool ds_pool;
19075 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19076 ASSERT_VK_SUCCESS(err);
19077
19078 const uint32_t BINDING_COUNT = 3;
19079 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019080 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019081 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19082 dsl_binding[0].descriptorCount = 1;
19083 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19084 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019085 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019086 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19087 dsl_binding[1].descriptorCount = 1;
19088 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19089 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019090 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019091 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19092 dsl_binding[2].descriptorCount = 1;
19093 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19094 dsl_binding[2].pImmutableSamplers = NULL;
19095
19096 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19097 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19098 ds_layout_ci.pNext = NULL;
19099 ds_layout_ci.bindingCount = BINDING_COUNT;
19100 ds_layout_ci.pBindings = dsl_binding;
19101 VkDescriptorSetLayout ds_layout;
19102 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19103 ASSERT_VK_SUCCESS(err);
19104
19105 VkDescriptorSet descriptor_set;
19106 VkDescriptorSetAllocateInfo alloc_info = {};
19107 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19108 alloc_info.descriptorSetCount = 1;
19109 alloc_info.descriptorPool = ds_pool;
19110 alloc_info.pSetLayouts = &ds_layout;
19111 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19112 ASSERT_VK_SUCCESS(err);
19113
19114 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19115 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19116 pipeline_layout_ci.pNext = NULL;
19117 pipeline_layout_ci.setLayoutCount = 1;
19118 pipeline_layout_ci.pSetLayouts = &ds_layout;
19119
19120 VkPipelineLayout pipeline_layout;
19121 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19122 ASSERT_VK_SUCCESS(err);
19123
19124 // Create two buffers to update the descriptors with
19125 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
19126 uint32_t qfi = 0;
19127 VkBufferCreateInfo buffCI = {};
19128 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19129 buffCI.size = 2048;
19130 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19131 buffCI.queueFamilyIndexCount = 1;
19132 buffCI.pQueueFamilyIndices = &qfi;
19133
19134 VkBuffer dyub1;
19135 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
19136 ASSERT_VK_SUCCESS(err);
19137 // buffer2
19138 buffCI.size = 1024;
19139 VkBuffer dyub2;
19140 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
19141 ASSERT_VK_SUCCESS(err);
19142 // Allocate memory and bind to buffers
19143 VkMemoryAllocateInfo mem_alloc[2] = {};
19144 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19145 mem_alloc[0].pNext = NULL;
19146 mem_alloc[0].memoryTypeIndex = 0;
19147 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19148 mem_alloc[1].pNext = NULL;
19149 mem_alloc[1].memoryTypeIndex = 0;
19150
19151 VkMemoryRequirements mem_reqs1;
19152 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
19153 VkMemoryRequirements mem_reqs2;
19154 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
19155 mem_alloc[0].allocationSize = mem_reqs1.size;
19156 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
19157 mem_alloc[1].allocationSize = mem_reqs2.size;
19158 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
19159 if (!pass) {
19160 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19161 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19162 return;
19163 }
19164
19165 VkDeviceMemory mem1;
19166 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
19167 ASSERT_VK_SUCCESS(err);
19168 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
19169 ASSERT_VK_SUCCESS(err);
19170 VkDeviceMemory mem2;
19171 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
19172 ASSERT_VK_SUCCESS(err);
19173 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
19174 ASSERT_VK_SUCCESS(err);
19175 // Update descriptors
19176 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
19177 buff_info[0].buffer = dyub1;
19178 buff_info[0].offset = 0;
19179 buff_info[0].range = 256;
19180 buff_info[1].buffer = dyub1;
19181 buff_info[1].offset = 256;
19182 buff_info[1].range = 512;
19183 buff_info[2].buffer = dyub2;
19184 buff_info[2].offset = 0;
19185 buff_info[2].range = 512;
19186
19187 VkWriteDescriptorSet descriptor_write;
19188 memset(&descriptor_write, 0, sizeof(descriptor_write));
19189 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19190 descriptor_write.dstSet = descriptor_set;
19191 descriptor_write.dstBinding = 0;
19192 descriptor_write.descriptorCount = BINDING_COUNT;
19193 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19194 descriptor_write.pBufferInfo = buff_info;
19195
19196 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19197
Tony Barbour552f6c02016-12-21 14:34:07 -070019198 m_commandBuffer->BeginCommandBuffer();
19199 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070019200
19201 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019202 char const *vsSource =
19203 "#version 450\n"
19204 "\n"
19205 "out gl_PerVertex { \n"
19206 " vec4 gl_Position;\n"
19207 "};\n"
19208 "void main(){\n"
19209 " gl_Position = vec4(1);\n"
19210 "}\n";
19211 char const *fsSource =
19212 "#version 450\n"
19213 "\n"
19214 "layout(location=0) out vec4 x;\n"
19215 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
19216 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
19217 "void main(){\n"
19218 " x = vec4(bar1.y) + vec4(bar2.y);\n"
19219 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070019220 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19221 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19222 VkPipelineObj pipe(m_device);
19223 pipe.SetViewport(m_viewports);
19224 pipe.SetScissor(m_scissors);
19225 pipe.AddShader(&vs);
19226 pipe.AddShader(&fs);
19227 pipe.AddColorAttachment();
19228 pipe.CreateVKPipeline(pipeline_layout, renderPass());
19229
19230 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
19231 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
19232 // we used to have a bug in this case.
19233 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
19234 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19235 &descriptor_set, BINDING_COUNT, dyn_off);
19236 Draw(1, 0, 0, 0);
19237 m_errorMonitor->VerifyNotFound();
19238
19239 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19240 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19241 vkFreeMemory(m_device->device(), mem1, NULL);
19242 vkFreeMemory(m_device->device(), mem2, NULL);
19243
19244 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19245 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19246 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19247}
19248
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019249TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019250 TEST_DESCRIPTION(
19251 "Ensure that validations handling of non-coherent memory "
19252 "mapping while using VK_WHOLE_SIZE does not cause access "
19253 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019254 VkResult err;
19255 uint8_t *pData;
19256 ASSERT_NO_FATAL_FAILURE(InitState());
19257
19258 VkDeviceMemory mem;
19259 VkMemoryRequirements mem_reqs;
19260 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019261 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019262 VkMemoryAllocateInfo alloc_info = {};
19263 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19264 alloc_info.pNext = NULL;
19265 alloc_info.memoryTypeIndex = 0;
19266
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019267 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019268 alloc_info.allocationSize = allocation_size;
19269
19270 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19271 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 -070019272 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019273 if (!pass) {
19274 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019275 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19276 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019277 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019278 pass = m_device->phy().set_memory_type(
19279 mem_reqs.memoryTypeBits, &alloc_info,
19280 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19281 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019282 if (!pass) {
19283 return;
19284 }
19285 }
19286 }
19287
19288 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19289 ASSERT_VK_SUCCESS(err);
19290
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019291 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019292 m_errorMonitor->ExpectSuccess();
19293 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19294 ASSERT_VK_SUCCESS(err);
19295 VkMappedMemoryRange mmr = {};
19296 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19297 mmr.memory = mem;
19298 mmr.offset = 0;
19299 mmr.size = VK_WHOLE_SIZE;
19300 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19301 ASSERT_VK_SUCCESS(err);
19302 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19303 ASSERT_VK_SUCCESS(err);
19304 m_errorMonitor->VerifyNotFound();
19305 vkUnmapMemory(m_device->device(), mem);
19306
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019307 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019308 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019309 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019310 ASSERT_VK_SUCCESS(err);
19311 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19312 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019313 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019314 mmr.size = VK_WHOLE_SIZE;
19315 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19316 ASSERT_VK_SUCCESS(err);
19317 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19318 ASSERT_VK_SUCCESS(err);
19319 m_errorMonitor->VerifyNotFound();
19320 vkUnmapMemory(m_device->device(), mem);
19321
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019322 // Map with offset and size
19323 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019324 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019325 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019326 ASSERT_VK_SUCCESS(err);
19327 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19328 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019329 mmr.offset = 4 * atom_size;
19330 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019331 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19332 ASSERT_VK_SUCCESS(err);
19333 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19334 ASSERT_VK_SUCCESS(err);
19335 m_errorMonitor->VerifyNotFound();
19336 vkUnmapMemory(m_device->device(), mem);
19337
19338 // Map without offset and flush WHOLE_SIZE with two separate offsets
19339 m_errorMonitor->ExpectSuccess();
19340 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19341 ASSERT_VK_SUCCESS(err);
19342 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19343 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019344 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019345 mmr.size = VK_WHOLE_SIZE;
19346 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19347 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019348 mmr.offset = allocation_size - (6 * 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);
19352 m_errorMonitor->VerifyNotFound();
19353 vkUnmapMemory(m_device->device(), mem);
19354
19355 vkFreeMemory(m_device->device(), mem, NULL);
19356}
19357
19358// This is a positive test. We used to expect error in this case but spec now allows it
19359TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19360 m_errorMonitor->ExpectSuccess();
19361 vk_testing::Fence testFence;
19362 VkFenceCreateInfo fenceInfo = {};
19363 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19364 fenceInfo.pNext = NULL;
19365
19366 ASSERT_NO_FATAL_FAILURE(InitState());
19367 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019368 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019369 VkResult result = vkResetFences(m_device->device(), 1, fences);
19370 ASSERT_VK_SUCCESS(result);
19371
19372 m_errorMonitor->VerifyNotFound();
19373}
19374
19375TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19376 m_errorMonitor->ExpectSuccess();
19377
19378 ASSERT_NO_FATAL_FAILURE(InitState());
19379 VkResult err;
19380
19381 // Record (empty!) command buffer that can be submitted multiple times
19382 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019383 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19384 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019385 m_commandBuffer->BeginCommandBuffer(&cbbi);
19386 m_commandBuffer->EndCommandBuffer();
19387
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019388 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019389 VkFence fence;
19390 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19391 ASSERT_VK_SUCCESS(err);
19392
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019393 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019394 VkSemaphore s1, s2;
19395 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19396 ASSERT_VK_SUCCESS(err);
19397 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19398 ASSERT_VK_SUCCESS(err);
19399
19400 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019401 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019402 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19403 ASSERT_VK_SUCCESS(err);
19404
19405 // Submit CB again, signaling s2.
19406 si.pSignalSemaphores = &s2;
19407 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19408 ASSERT_VK_SUCCESS(err);
19409
19410 // Wait for fence.
19411 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19412 ASSERT_VK_SUCCESS(err);
19413
19414 // CB is still in flight from second submission, but semaphore s1 is no
19415 // longer in flight. delete it.
19416 vkDestroySemaphore(m_device->device(), s1, nullptr);
19417
19418 m_errorMonitor->VerifyNotFound();
19419
19420 // Force device idle and clean up remaining objects
19421 vkDeviceWaitIdle(m_device->device());
19422 vkDestroySemaphore(m_device->device(), s2, nullptr);
19423 vkDestroyFence(m_device->device(), fence, nullptr);
19424}
19425
19426TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19427 m_errorMonitor->ExpectSuccess();
19428
19429 ASSERT_NO_FATAL_FAILURE(InitState());
19430 VkResult err;
19431
19432 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019433 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019434 VkFence f1;
19435 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19436 ASSERT_VK_SUCCESS(err);
19437
19438 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019439 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019440 VkFence f2;
19441 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19442 ASSERT_VK_SUCCESS(err);
19443
19444 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019445 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019446 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19447
19448 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019449 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019450 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19451
19452 // Should have both retired!
19453 vkDestroyFence(m_device->device(), f1, nullptr);
19454 vkDestroyFence(m_device->device(), f2, nullptr);
19455
19456 m_errorMonitor->VerifyNotFound();
19457}
19458
19459TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019460 TEST_DESCRIPTION(
19461 "Verify that creating an image view from an image with valid usage "
19462 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019463
19464 ASSERT_NO_FATAL_FAILURE(InitState());
19465
19466 m_errorMonitor->ExpectSuccess();
19467 // Verify that we can create a view with usage INPUT_ATTACHMENT
19468 VkImageObj image(m_device);
19469 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19470 ASSERT_TRUE(image.initialized());
19471 VkImageView imageView;
19472 VkImageViewCreateInfo ivci = {};
19473 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19474 ivci.image = image.handle();
19475 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19476 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19477 ivci.subresourceRange.layerCount = 1;
19478 ivci.subresourceRange.baseMipLevel = 0;
19479 ivci.subresourceRange.levelCount = 1;
19480 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19481
19482 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19483 m_errorMonitor->VerifyNotFound();
19484 vkDestroyImageView(m_device->device(), imageView, NULL);
19485}
19486
19487// This is a positive test. No failures are expected.
19488TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019489 TEST_DESCRIPTION(
19490 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19491 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019492
19493 ASSERT_NO_FATAL_FAILURE(InitState());
19494
19495 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019496 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019497
19498 m_errorMonitor->ExpectSuccess();
19499
19500 VkImage image;
19501 VkImageCreateInfo image_create_info = {};
19502 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19503 image_create_info.pNext = NULL;
19504 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19505 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19506 image_create_info.extent.width = 64;
19507 image_create_info.extent.height = 64;
19508 image_create_info.extent.depth = 1;
19509 image_create_info.mipLevels = 1;
19510 image_create_info.arrayLayers = 1;
19511 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19512 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19513 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19514 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19515 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19516 ASSERT_VK_SUCCESS(err);
19517
19518 VkMemoryRequirements memory_reqs;
19519 VkDeviceMemory memory_one, memory_two;
19520 bool pass;
19521 VkMemoryAllocateInfo memory_info = {};
19522 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19523 memory_info.pNext = NULL;
19524 memory_info.allocationSize = 0;
19525 memory_info.memoryTypeIndex = 0;
19526 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19527 // Find an image big enough to allow sparse mapping of 2 memory regions
19528 // Increase the image size until it is at least twice the
19529 // size of the required alignment, to ensure we can bind both
19530 // allocated memory blocks to the image on aligned offsets.
19531 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19532 vkDestroyImage(m_device->device(), image, nullptr);
19533 image_create_info.extent.width *= 2;
19534 image_create_info.extent.height *= 2;
19535 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19536 ASSERT_VK_SUCCESS(err);
19537 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19538 }
19539 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19540 // at the end of the first
19541 memory_info.allocationSize = memory_reqs.alignment;
19542 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19543 ASSERT_TRUE(pass);
19544 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19545 ASSERT_VK_SUCCESS(err);
19546 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19547 ASSERT_VK_SUCCESS(err);
19548 VkSparseMemoryBind binds[2];
19549 binds[0].flags = 0;
19550 binds[0].memory = memory_one;
19551 binds[0].memoryOffset = 0;
19552 binds[0].resourceOffset = 0;
19553 binds[0].size = memory_info.allocationSize;
19554 binds[1].flags = 0;
19555 binds[1].memory = memory_two;
19556 binds[1].memoryOffset = 0;
19557 binds[1].resourceOffset = memory_info.allocationSize;
19558 binds[1].size = memory_info.allocationSize;
19559
19560 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19561 opaqueBindInfo.image = image;
19562 opaqueBindInfo.bindCount = 2;
19563 opaqueBindInfo.pBinds = binds;
19564
19565 VkFence fence = VK_NULL_HANDLE;
19566 VkBindSparseInfo bindSparseInfo = {};
19567 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19568 bindSparseInfo.imageOpaqueBindCount = 1;
19569 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19570
19571 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19572 vkQueueWaitIdle(m_device->m_queue);
19573 vkDestroyImage(m_device->device(), image, NULL);
19574 vkFreeMemory(m_device->device(), memory_one, NULL);
19575 vkFreeMemory(m_device->device(), memory_two, NULL);
19576 m_errorMonitor->VerifyNotFound();
19577}
19578
19579TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019580 TEST_DESCRIPTION(
19581 "Ensure that CmdBeginRenderPass with an attachment's "
19582 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19583 "the command buffer has prior knowledge of that "
19584 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019585
19586 m_errorMonitor->ExpectSuccess();
19587
19588 ASSERT_NO_FATAL_FAILURE(InitState());
19589
19590 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019591 VkAttachmentDescription attachment = {0,
19592 VK_FORMAT_R8G8B8A8_UNORM,
19593 VK_SAMPLE_COUNT_1_BIT,
19594 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19595 VK_ATTACHMENT_STORE_OP_STORE,
19596 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19597 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19598 VK_IMAGE_LAYOUT_UNDEFINED,
19599 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019600
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019601 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019602
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019603 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019604
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019605 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019606
19607 VkRenderPass rp;
19608 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19609 ASSERT_VK_SUCCESS(err);
19610
19611 // A compatible framebuffer.
19612 VkImageObj image(m_device);
19613 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19614 ASSERT_TRUE(image.initialized());
19615
19616 VkImageViewCreateInfo ivci = {
19617 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19618 nullptr,
19619 0,
19620 image.handle(),
19621 VK_IMAGE_VIEW_TYPE_2D,
19622 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019623 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19624 VK_COMPONENT_SWIZZLE_IDENTITY},
19625 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019626 };
19627 VkImageView view;
19628 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19629 ASSERT_VK_SUCCESS(err);
19630
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019631 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019632 VkFramebuffer fb;
19633 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19634 ASSERT_VK_SUCCESS(err);
19635
19636 // Record a single command buffer which uses this renderpass twice. The
19637 // bug is triggered at the beginning of the second renderpass, when the
19638 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019639 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 -070019640 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019641 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19642 vkCmdEndRenderPass(m_commandBuffer->handle());
19643 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19644
19645 m_errorMonitor->VerifyNotFound();
19646
19647 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019648 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019649
19650 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19651 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19652 vkDestroyImageView(m_device->device(), view, nullptr);
19653}
19654
19655TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019656 TEST_DESCRIPTION(
19657 "This test should pass. Create a Framebuffer and "
19658 "command buffer, bind them together, then destroy "
19659 "command pool and framebuffer and verify there are no "
19660 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019661
19662 m_errorMonitor->ExpectSuccess();
19663
19664 ASSERT_NO_FATAL_FAILURE(InitState());
19665
19666 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019667 VkAttachmentDescription attachment = {0,
19668 VK_FORMAT_R8G8B8A8_UNORM,
19669 VK_SAMPLE_COUNT_1_BIT,
19670 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19671 VK_ATTACHMENT_STORE_OP_STORE,
19672 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19673 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19674 VK_IMAGE_LAYOUT_UNDEFINED,
19675 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019676
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019677 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019678
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019679 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019680
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019681 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019682
19683 VkRenderPass rp;
19684 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19685 ASSERT_VK_SUCCESS(err);
19686
19687 // A compatible framebuffer.
19688 VkImageObj image(m_device);
19689 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19690 ASSERT_TRUE(image.initialized());
19691
19692 VkImageViewCreateInfo ivci = {
19693 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19694 nullptr,
19695 0,
19696 image.handle(),
19697 VK_IMAGE_VIEW_TYPE_2D,
19698 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019699 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19700 VK_COMPONENT_SWIZZLE_IDENTITY},
19701 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019702 };
19703 VkImageView view;
19704 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19705 ASSERT_VK_SUCCESS(err);
19706
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019707 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019708 VkFramebuffer fb;
19709 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19710 ASSERT_VK_SUCCESS(err);
19711
19712 // Explicitly create a command buffer to bind the FB to so that we can then
19713 // destroy the command pool in order to implicitly free command buffer
19714 VkCommandPool command_pool;
19715 VkCommandPoolCreateInfo pool_create_info{};
19716 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19717 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19718 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19719 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19720
19721 VkCommandBuffer command_buffer;
19722 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19723 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19724 command_buffer_allocate_info.commandPool = command_pool;
19725 command_buffer_allocate_info.commandBufferCount = 1;
19726 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19727 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19728
19729 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019730 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 -060019731 VkCommandBufferBeginInfo begin_info{};
19732 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19733 vkBeginCommandBuffer(command_buffer, &begin_info);
19734
19735 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19736 vkCmdEndRenderPass(command_buffer);
19737 vkEndCommandBuffer(command_buffer);
19738 vkDestroyImageView(m_device->device(), view, nullptr);
19739 // Destroy command pool to implicitly free command buffer
19740 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19741 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19742 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19743 m_errorMonitor->VerifyNotFound();
19744}
19745
19746TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019747 TEST_DESCRIPTION(
19748 "Ensure that CmdBeginRenderPass applies the layout "
19749 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019750
19751 m_errorMonitor->ExpectSuccess();
19752
19753 ASSERT_NO_FATAL_FAILURE(InitState());
19754
19755 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019756 VkAttachmentDescription attachment = {0,
19757 VK_FORMAT_R8G8B8A8_UNORM,
19758 VK_SAMPLE_COUNT_1_BIT,
19759 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19760 VK_ATTACHMENT_STORE_OP_STORE,
19761 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19762 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19763 VK_IMAGE_LAYOUT_UNDEFINED,
19764 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019765
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019766 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019767
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019768 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019769
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019770 VkSubpassDependency dep = {0,
19771 0,
19772 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19773 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19774 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19775 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19776 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019777
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019778 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019779
19780 VkResult err;
19781 VkRenderPass rp;
19782 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19783 ASSERT_VK_SUCCESS(err);
19784
19785 // A compatible framebuffer.
19786 VkImageObj image(m_device);
19787 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19788 ASSERT_TRUE(image.initialized());
19789
19790 VkImageViewCreateInfo ivci = {
19791 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19792 nullptr,
19793 0,
19794 image.handle(),
19795 VK_IMAGE_VIEW_TYPE_2D,
19796 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019797 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19798 VK_COMPONENT_SWIZZLE_IDENTITY},
19799 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019800 };
19801 VkImageView view;
19802 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19803 ASSERT_VK_SUCCESS(err);
19804
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019805 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019806 VkFramebuffer fb;
19807 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19808 ASSERT_VK_SUCCESS(err);
19809
19810 // Record a single command buffer which issues a pipeline barrier w/
19811 // image memory barrier for the attachment. This detects the previously
19812 // missing tracking of the subpass layout by throwing a validation error
19813 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019814 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 -070019815 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019816 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19817
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019818 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19819 nullptr,
19820 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19821 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19822 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19823 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19824 VK_QUEUE_FAMILY_IGNORED,
19825 VK_QUEUE_FAMILY_IGNORED,
19826 image.handle(),
19827 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019828 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019829 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19830 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019831
19832 vkCmdEndRenderPass(m_commandBuffer->handle());
19833 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019834 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019835
19836 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19837 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19838 vkDestroyImageView(m_device->device(), view, nullptr);
19839}
19840
19841TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019842 TEST_DESCRIPTION(
19843 "Validate that when an imageView of a depth/stencil image "
19844 "is used as a depth/stencil framebuffer attachment, the "
19845 "aspectMask is ignored and both depth and stencil image "
19846 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019847
19848 VkFormatProperties format_properties;
19849 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19850 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19851 return;
19852 }
19853
19854 m_errorMonitor->ExpectSuccess();
19855
19856 ASSERT_NO_FATAL_FAILURE(InitState());
19857
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019858 VkAttachmentDescription attachment = {0,
19859 VK_FORMAT_D32_SFLOAT_S8_UINT,
19860 VK_SAMPLE_COUNT_1_BIT,
19861 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19862 VK_ATTACHMENT_STORE_OP_STORE,
19863 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19864 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19865 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19866 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019867
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019868 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019869
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019870 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019871
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019872 VkSubpassDependency dep = {0,
19873 0,
19874 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19875 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19876 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19877 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19878 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019879
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019880 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019881
19882 VkResult err;
19883 VkRenderPass rp;
19884 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19885 ASSERT_VK_SUCCESS(err);
19886
19887 VkImageObj image(m_device);
19888 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019889 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019890 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019891 ASSERT_TRUE(image.initialized());
19892 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19893
19894 VkImageViewCreateInfo ivci = {
19895 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19896 nullptr,
19897 0,
19898 image.handle(),
19899 VK_IMAGE_VIEW_TYPE_2D,
19900 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019901 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19902 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019903 };
19904 VkImageView view;
19905 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19906 ASSERT_VK_SUCCESS(err);
19907
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019908 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019909 VkFramebuffer fb;
19910 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19911 ASSERT_VK_SUCCESS(err);
19912
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019913 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 -070019914 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019915 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19916
19917 VkImageMemoryBarrier imb = {};
19918 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19919 imb.pNext = nullptr;
19920 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19921 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19922 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19923 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19924 imb.srcQueueFamilyIndex = 0;
19925 imb.dstQueueFamilyIndex = 0;
19926 imb.image = image.handle();
19927 imb.subresourceRange.aspectMask = 0x6;
19928 imb.subresourceRange.baseMipLevel = 0;
19929 imb.subresourceRange.levelCount = 0x1;
19930 imb.subresourceRange.baseArrayLayer = 0;
19931 imb.subresourceRange.layerCount = 0x1;
19932
19933 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019934 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19935 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019936
19937 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019938 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019939 QueueCommandBuffer(false);
19940 m_errorMonitor->VerifyNotFound();
19941
19942 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19943 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19944 vkDestroyImageView(m_device->device(), view, nullptr);
19945}
19946
19947TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019948 TEST_DESCRIPTION(
19949 "Ensure that layout transitions work correctly without "
19950 "errors, when an attachment reference is "
19951 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019952
19953 m_errorMonitor->ExpectSuccess();
19954
19955 ASSERT_NO_FATAL_FAILURE(InitState());
19956
19957 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019958 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019959
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019960 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019961
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019962 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019963
19964 VkRenderPass rp;
19965 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19966 ASSERT_VK_SUCCESS(err);
19967
19968 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019969 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019970 VkFramebuffer fb;
19971 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19972 ASSERT_VK_SUCCESS(err);
19973
19974 // Record a command buffer which just begins and ends the renderpass. The
19975 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019976 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 -070019977 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019978 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19979 vkCmdEndRenderPass(m_commandBuffer->handle());
19980 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019981 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019982
19983 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19984 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19985}
19986
19987// This is a positive test. No errors are expected.
19988TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019989 TEST_DESCRIPTION(
19990 "Create a stencil-only attachment with a LOAD_OP set to "
19991 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019992 VkResult result = VK_SUCCESS;
Tony Barbourf887b162017-03-09 10:06:46 -070019993 ASSERT_NO_FATAL_FAILURE(InitState());
19994 auto depth_format = find_depth_stencil_format(m_device);
19995 if (!depth_format) {
19996 printf(" No Depth + Stencil format found. Skipped.\n");
19997 return;
19998 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019999 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070020000 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020001 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
20002 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020003 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
20004 return;
20005 }
20006
Tony Barbourf887b162017-03-09 10:06:46 -070020007 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020008 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020009 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020010 VkAttachmentDescription att = {};
20011 VkAttachmentReference ref = {};
20012 att.format = depth_stencil_fmt;
20013 att.samples = VK_SAMPLE_COUNT_1_BIT;
20014 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
20015 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20016 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20017 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
20018 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20019 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20020
20021 VkClearValue clear;
20022 clear.depthStencil.depth = 1.0;
20023 clear.depthStencil.stencil = 0;
20024 ref.attachment = 0;
20025 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20026
20027 VkSubpassDescription subpass = {};
20028 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
20029 subpass.flags = 0;
20030 subpass.inputAttachmentCount = 0;
20031 subpass.pInputAttachments = NULL;
20032 subpass.colorAttachmentCount = 0;
20033 subpass.pColorAttachments = NULL;
20034 subpass.pResolveAttachments = NULL;
20035 subpass.pDepthStencilAttachment = &ref;
20036 subpass.preserveAttachmentCount = 0;
20037 subpass.pPreserveAttachments = NULL;
20038
20039 VkRenderPass rp;
20040 VkRenderPassCreateInfo rp_info = {};
20041 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20042 rp_info.attachmentCount = 1;
20043 rp_info.pAttachments = &att;
20044 rp_info.subpassCount = 1;
20045 rp_info.pSubpasses = &subpass;
20046 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
20047 ASSERT_VK_SUCCESS(result);
20048
20049 VkImageView *depthView = m_depthStencil->BindInfo();
20050 VkFramebufferCreateInfo fb_info = {};
20051 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
20052 fb_info.pNext = NULL;
20053 fb_info.renderPass = rp;
20054 fb_info.attachmentCount = 1;
20055 fb_info.pAttachments = depthView;
20056 fb_info.width = 100;
20057 fb_info.height = 100;
20058 fb_info.layers = 1;
20059 VkFramebuffer fb;
20060 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
20061 ASSERT_VK_SUCCESS(result);
20062
20063 VkRenderPassBeginInfo rpbinfo = {};
20064 rpbinfo.clearValueCount = 1;
20065 rpbinfo.pClearValues = &clear;
20066 rpbinfo.pNext = NULL;
20067 rpbinfo.renderPass = rp;
20068 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
20069 rpbinfo.renderArea.extent.width = 100;
20070 rpbinfo.renderArea.extent.height = 100;
20071 rpbinfo.renderArea.offset.x = 0;
20072 rpbinfo.renderArea.offset.y = 0;
20073 rpbinfo.framebuffer = fb;
20074
20075 VkFence fence = {};
20076 VkFenceCreateInfo fence_ci = {};
20077 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20078 fence_ci.pNext = nullptr;
20079 fence_ci.flags = 0;
20080 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
20081 ASSERT_VK_SUCCESS(result);
20082
20083 m_commandBuffer->BeginCommandBuffer();
20084 m_commandBuffer->BeginRenderPass(rpbinfo);
20085 m_commandBuffer->EndRenderPass();
20086 m_commandBuffer->EndCommandBuffer();
20087 m_commandBuffer->QueueCommandBuffer(fence);
20088
20089 VkImageObj destImage(m_device);
20090 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 -070020091 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020092 VkImageMemoryBarrier barrier = {};
20093 VkImageSubresourceRange range;
20094 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20095 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20096 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
20097 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20098 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20099 barrier.image = m_depthStencil->handle();
20100 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20101 range.baseMipLevel = 0;
20102 range.levelCount = 1;
20103 range.baseArrayLayer = 0;
20104 range.layerCount = 1;
20105 barrier.subresourceRange = range;
20106 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20107 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
20108 cmdbuf.BeginCommandBuffer();
20109 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 -070020110 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020111 barrier.srcAccessMask = 0;
20112 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
20113 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20114 barrier.image = destImage.handle();
20115 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20116 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 -070020117 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020118 VkImageCopy cregion;
20119 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20120 cregion.srcSubresource.mipLevel = 0;
20121 cregion.srcSubresource.baseArrayLayer = 0;
20122 cregion.srcSubresource.layerCount = 1;
20123 cregion.srcOffset.x = 0;
20124 cregion.srcOffset.y = 0;
20125 cregion.srcOffset.z = 0;
20126 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20127 cregion.dstSubresource.mipLevel = 0;
20128 cregion.dstSubresource.baseArrayLayer = 0;
20129 cregion.dstSubresource.layerCount = 1;
20130 cregion.dstOffset.x = 0;
20131 cregion.dstOffset.y = 0;
20132 cregion.dstOffset.z = 0;
20133 cregion.extent.width = 100;
20134 cregion.extent.height = 100;
20135 cregion.extent.depth = 1;
20136 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020137 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020138 cmdbuf.EndCommandBuffer();
20139
20140 VkSubmitInfo submit_info;
20141 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20142 submit_info.pNext = NULL;
20143 submit_info.waitSemaphoreCount = 0;
20144 submit_info.pWaitSemaphores = NULL;
20145 submit_info.pWaitDstStageMask = NULL;
20146 submit_info.commandBufferCount = 1;
20147 submit_info.pCommandBuffers = &cmdbuf.handle();
20148 submit_info.signalSemaphoreCount = 0;
20149 submit_info.pSignalSemaphores = NULL;
20150
20151 m_errorMonitor->ExpectSuccess();
20152 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20153 m_errorMonitor->VerifyNotFound();
20154
20155 vkQueueWaitIdle(m_device->m_queue);
20156 vkDestroyFence(m_device->device(), fence, nullptr);
20157 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20158 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20159}
20160
20161// This is a positive test. No errors should be generated.
20162TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
20163 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
20164
20165 m_errorMonitor->ExpectSuccess();
20166 ASSERT_NO_FATAL_FAILURE(InitState());
20167
20168 VkEvent event;
20169 VkEventCreateInfo event_create_info{};
20170 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20171 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20172
20173 VkCommandPool command_pool;
20174 VkCommandPoolCreateInfo pool_create_info{};
20175 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20176 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20177 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20178 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20179
20180 VkCommandBuffer command_buffer;
20181 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20182 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20183 command_buffer_allocate_info.commandPool = command_pool;
20184 command_buffer_allocate_info.commandBufferCount = 1;
20185 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20186 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20187
20188 VkQueue queue = VK_NULL_HANDLE;
20189 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20190
20191 {
20192 VkCommandBufferBeginInfo begin_info{};
20193 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20194 vkBeginCommandBuffer(command_buffer, &begin_info);
20195
20196 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 -070020197 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020198 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
20199 vkEndCommandBuffer(command_buffer);
20200 }
20201 {
20202 VkSubmitInfo submit_info{};
20203 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20204 submit_info.commandBufferCount = 1;
20205 submit_info.pCommandBuffers = &command_buffer;
20206 submit_info.signalSemaphoreCount = 0;
20207 submit_info.pSignalSemaphores = nullptr;
20208 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20209 }
20210 { vkSetEvent(m_device->device(), event); }
20211
20212 vkQueueWaitIdle(queue);
20213
20214 vkDestroyEvent(m_device->device(), event, nullptr);
20215 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20216 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20217
20218 m_errorMonitor->VerifyNotFound();
20219}
20220// This is a positive test. No errors should be generated.
20221TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
20222 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
20223
20224 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020225 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020226
20227 m_errorMonitor->ExpectSuccess();
20228
20229 VkQueryPool query_pool;
20230 VkQueryPoolCreateInfo query_pool_create_info{};
20231 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20232 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20233 query_pool_create_info.queryCount = 1;
20234 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20235
20236 VkCommandPool command_pool;
20237 VkCommandPoolCreateInfo pool_create_info{};
20238 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20239 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20240 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20241 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20242
20243 VkCommandBuffer command_buffer;
20244 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20245 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20246 command_buffer_allocate_info.commandPool = command_pool;
20247 command_buffer_allocate_info.commandBufferCount = 1;
20248 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20249 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20250
20251 VkCommandBuffer secondary_command_buffer;
20252 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20253 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20254
20255 VkQueue queue = VK_NULL_HANDLE;
20256 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20257
20258 uint32_t qfi = 0;
20259 VkBufferCreateInfo buff_create_info = {};
20260 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20261 buff_create_info.size = 1024;
20262 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20263 buff_create_info.queueFamilyIndexCount = 1;
20264 buff_create_info.pQueueFamilyIndices = &qfi;
20265
20266 VkResult err;
20267 VkBuffer buffer;
20268 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20269 ASSERT_VK_SUCCESS(err);
20270 VkMemoryAllocateInfo mem_alloc = {};
20271 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20272 mem_alloc.pNext = NULL;
20273 mem_alloc.allocationSize = 1024;
20274 mem_alloc.memoryTypeIndex = 0;
20275
20276 VkMemoryRequirements memReqs;
20277 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20278 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20279 if (!pass) {
20280 vkDestroyBuffer(m_device->device(), buffer, NULL);
20281 return;
20282 }
20283
20284 VkDeviceMemory mem;
20285 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20286 ASSERT_VK_SUCCESS(err);
20287 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20288 ASSERT_VK_SUCCESS(err);
20289
20290 VkCommandBufferInheritanceInfo hinfo = {};
20291 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20292 hinfo.renderPass = VK_NULL_HANDLE;
20293 hinfo.subpass = 0;
20294 hinfo.framebuffer = VK_NULL_HANDLE;
20295 hinfo.occlusionQueryEnable = VK_FALSE;
20296 hinfo.queryFlags = 0;
20297 hinfo.pipelineStatistics = 0;
20298
20299 {
20300 VkCommandBufferBeginInfo begin_info{};
20301 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20302 begin_info.pInheritanceInfo = &hinfo;
20303 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20304
20305 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20306 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20307
20308 vkEndCommandBuffer(secondary_command_buffer);
20309
20310 begin_info.pInheritanceInfo = nullptr;
20311 vkBeginCommandBuffer(command_buffer, &begin_info);
20312
20313 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20314 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20315
20316 vkEndCommandBuffer(command_buffer);
20317 }
20318 {
20319 VkSubmitInfo submit_info{};
20320 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20321 submit_info.commandBufferCount = 1;
20322 submit_info.pCommandBuffers = &command_buffer;
20323 submit_info.signalSemaphoreCount = 0;
20324 submit_info.pSignalSemaphores = nullptr;
20325 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20326 }
20327
20328 vkQueueWaitIdle(queue);
20329
20330 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20331 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20332 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20333 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20334 vkDestroyBuffer(m_device->device(), buffer, NULL);
20335 vkFreeMemory(m_device->device(), mem, NULL);
20336
20337 m_errorMonitor->VerifyNotFound();
20338}
20339
20340// This is a positive test. No errors should be generated.
20341TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20342 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20343
20344 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020345 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020346
20347 m_errorMonitor->ExpectSuccess();
20348
20349 VkQueryPool query_pool;
20350 VkQueryPoolCreateInfo query_pool_create_info{};
20351 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20352 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20353 query_pool_create_info.queryCount = 1;
20354 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20355
20356 VkCommandPool command_pool;
20357 VkCommandPoolCreateInfo pool_create_info{};
20358 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20359 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20360 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20361 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20362
20363 VkCommandBuffer command_buffer[2];
20364 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20365 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20366 command_buffer_allocate_info.commandPool = command_pool;
20367 command_buffer_allocate_info.commandBufferCount = 2;
20368 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20369 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20370
20371 VkQueue queue = VK_NULL_HANDLE;
20372 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20373
20374 uint32_t qfi = 0;
20375 VkBufferCreateInfo buff_create_info = {};
20376 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20377 buff_create_info.size = 1024;
20378 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20379 buff_create_info.queueFamilyIndexCount = 1;
20380 buff_create_info.pQueueFamilyIndices = &qfi;
20381
20382 VkResult err;
20383 VkBuffer buffer;
20384 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20385 ASSERT_VK_SUCCESS(err);
20386 VkMemoryAllocateInfo mem_alloc = {};
20387 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20388 mem_alloc.pNext = NULL;
20389 mem_alloc.allocationSize = 1024;
20390 mem_alloc.memoryTypeIndex = 0;
20391
20392 VkMemoryRequirements memReqs;
20393 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20394 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20395 if (!pass) {
20396 vkDestroyBuffer(m_device->device(), buffer, NULL);
20397 return;
20398 }
20399
20400 VkDeviceMemory mem;
20401 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20402 ASSERT_VK_SUCCESS(err);
20403 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20404 ASSERT_VK_SUCCESS(err);
20405
20406 {
20407 VkCommandBufferBeginInfo begin_info{};
20408 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20409 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20410
20411 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20412 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20413
20414 vkEndCommandBuffer(command_buffer[0]);
20415
20416 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20417
20418 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20419
20420 vkEndCommandBuffer(command_buffer[1]);
20421 }
20422 {
20423 VkSubmitInfo submit_info{};
20424 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20425 submit_info.commandBufferCount = 2;
20426 submit_info.pCommandBuffers = command_buffer;
20427 submit_info.signalSemaphoreCount = 0;
20428 submit_info.pSignalSemaphores = nullptr;
20429 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20430 }
20431
20432 vkQueueWaitIdle(queue);
20433
20434 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20435 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20436 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20437 vkDestroyBuffer(m_device->device(), buffer, NULL);
20438 vkFreeMemory(m_device->device(), mem, NULL);
20439
20440 m_errorMonitor->VerifyNotFound();
20441}
20442
Tony Barbourc46924f2016-11-04 11:49:52 -060020443TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020444 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20445
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020446 ASSERT_NO_FATAL_FAILURE(InitState());
20447 VkEvent event;
20448 VkEventCreateInfo event_create_info{};
20449 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20450 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20451
20452 VkCommandPool command_pool;
20453 VkCommandPoolCreateInfo pool_create_info{};
20454 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20455 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20456 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20457 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20458
20459 VkCommandBuffer command_buffer;
20460 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20461 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20462 command_buffer_allocate_info.commandPool = command_pool;
20463 command_buffer_allocate_info.commandBufferCount = 1;
20464 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20465 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20466
20467 VkQueue queue = VK_NULL_HANDLE;
20468 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20469
20470 {
20471 VkCommandBufferBeginInfo begin_info{};
20472 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20473 vkBeginCommandBuffer(command_buffer, &begin_info);
20474
20475 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020476 vkEndCommandBuffer(command_buffer);
20477 }
20478 {
20479 VkSubmitInfo submit_info{};
20480 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20481 submit_info.commandBufferCount = 1;
20482 submit_info.pCommandBuffers = &command_buffer;
20483 submit_info.signalSemaphoreCount = 0;
20484 submit_info.pSignalSemaphores = nullptr;
20485 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20486 }
20487 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20489 "that is already in use by a "
20490 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020491 vkSetEvent(m_device->device(), event);
20492 m_errorMonitor->VerifyFound();
20493 }
20494
20495 vkQueueWaitIdle(queue);
20496
20497 vkDestroyEvent(m_device->device(), event, nullptr);
20498 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20499 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20500}
20501
20502// This is a positive test. No errors should be generated.
20503TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020504 TEST_DESCRIPTION(
20505 "Two command buffers with two separate fences are each "
20506 "run through a Submit & WaitForFences cycle 3 times. This "
20507 "previously revealed a bug so running this positive test "
20508 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020509 m_errorMonitor->ExpectSuccess();
20510
20511 ASSERT_NO_FATAL_FAILURE(InitState());
20512 VkQueue queue = VK_NULL_HANDLE;
20513 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20514
20515 static const uint32_t NUM_OBJECTS = 2;
20516 static const uint32_t NUM_FRAMES = 3;
20517 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20518 VkFence fences[NUM_OBJECTS] = {};
20519
20520 VkCommandPool cmd_pool;
20521 VkCommandPoolCreateInfo cmd_pool_ci = {};
20522 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20523 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20524 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20525 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20526 ASSERT_VK_SUCCESS(err);
20527
20528 VkCommandBufferAllocateInfo cmd_buf_info = {};
20529 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20530 cmd_buf_info.commandPool = cmd_pool;
20531 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20532 cmd_buf_info.commandBufferCount = 1;
20533
20534 VkFenceCreateInfo fence_ci = {};
20535 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20536 fence_ci.pNext = nullptr;
20537 fence_ci.flags = 0;
20538
20539 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20540 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20541 ASSERT_VK_SUCCESS(err);
20542 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20543 ASSERT_VK_SUCCESS(err);
20544 }
20545
20546 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20547 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20548 // Create empty cmd buffer
20549 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20550 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20551
20552 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20553 ASSERT_VK_SUCCESS(err);
20554 err = vkEndCommandBuffer(cmd_buffers[obj]);
20555 ASSERT_VK_SUCCESS(err);
20556
20557 VkSubmitInfo submit_info = {};
20558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20559 submit_info.commandBufferCount = 1;
20560 submit_info.pCommandBuffers = &cmd_buffers[obj];
20561 // Submit cmd buffer and wait for fence
20562 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20563 ASSERT_VK_SUCCESS(err);
20564 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20565 ASSERT_VK_SUCCESS(err);
20566 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20567 ASSERT_VK_SUCCESS(err);
20568 }
20569 }
20570 m_errorMonitor->VerifyNotFound();
20571 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20572 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20573 vkDestroyFence(m_device->device(), fences[i], nullptr);
20574 }
20575}
20576// This is a positive test. No errors should be generated.
20577TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020578 TEST_DESCRIPTION(
20579 "Two command buffers, each in a separate QueueSubmit call "
20580 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020581
20582 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020583 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020584
20585 m_errorMonitor->ExpectSuccess();
20586
20587 VkSemaphore semaphore;
20588 VkSemaphoreCreateInfo semaphore_create_info{};
20589 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20590 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20591
20592 VkCommandPool command_pool;
20593 VkCommandPoolCreateInfo pool_create_info{};
20594 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20595 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20596 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20597 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20598
20599 VkCommandBuffer command_buffer[2];
20600 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20601 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20602 command_buffer_allocate_info.commandPool = command_pool;
20603 command_buffer_allocate_info.commandBufferCount = 2;
20604 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20605 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20606
20607 VkQueue queue = VK_NULL_HANDLE;
20608 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20609
20610 {
20611 VkCommandBufferBeginInfo begin_info{};
20612 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20613 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20614
20615 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 -070020616 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020617
20618 VkViewport viewport{};
20619 viewport.maxDepth = 1.0f;
20620 viewport.minDepth = 0.0f;
20621 viewport.width = 512;
20622 viewport.height = 512;
20623 viewport.x = 0;
20624 viewport.y = 0;
20625 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20626 vkEndCommandBuffer(command_buffer[0]);
20627 }
20628 {
20629 VkCommandBufferBeginInfo begin_info{};
20630 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20631 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20632
20633 VkViewport viewport{};
20634 viewport.maxDepth = 1.0f;
20635 viewport.minDepth = 0.0f;
20636 viewport.width = 512;
20637 viewport.height = 512;
20638 viewport.x = 0;
20639 viewport.y = 0;
20640 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20641 vkEndCommandBuffer(command_buffer[1]);
20642 }
20643 {
20644 VkSubmitInfo submit_info{};
20645 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20646 submit_info.commandBufferCount = 1;
20647 submit_info.pCommandBuffers = &command_buffer[0];
20648 submit_info.signalSemaphoreCount = 1;
20649 submit_info.pSignalSemaphores = &semaphore;
20650 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20651 }
20652 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020653 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020654 VkSubmitInfo submit_info{};
20655 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20656 submit_info.commandBufferCount = 1;
20657 submit_info.pCommandBuffers = &command_buffer[1];
20658 submit_info.waitSemaphoreCount = 1;
20659 submit_info.pWaitSemaphores = &semaphore;
20660 submit_info.pWaitDstStageMask = flags;
20661 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20662 }
20663
20664 vkQueueWaitIdle(m_device->m_queue);
20665
20666 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20667 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20668 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20669
20670 m_errorMonitor->VerifyNotFound();
20671}
20672
20673// This is a positive test. No errors should be generated.
20674TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020675 TEST_DESCRIPTION(
20676 "Two command buffers, each in a separate QueueSubmit call "
20677 "submitted on separate queues, the second having a fence"
20678 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020679
20680 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020681 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020682
20683 m_errorMonitor->ExpectSuccess();
20684
20685 VkFence fence;
20686 VkFenceCreateInfo fence_create_info{};
20687 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20688 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20689
20690 VkSemaphore semaphore;
20691 VkSemaphoreCreateInfo semaphore_create_info{};
20692 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20693 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20694
20695 VkCommandPool command_pool;
20696 VkCommandPoolCreateInfo pool_create_info{};
20697 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20698 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20699 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20700 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20701
20702 VkCommandBuffer command_buffer[2];
20703 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20704 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20705 command_buffer_allocate_info.commandPool = command_pool;
20706 command_buffer_allocate_info.commandBufferCount = 2;
20707 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20708 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20709
20710 VkQueue queue = VK_NULL_HANDLE;
20711 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20712
20713 {
20714 VkCommandBufferBeginInfo begin_info{};
20715 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20716 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20717
20718 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 -070020719 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020720
20721 VkViewport viewport{};
20722 viewport.maxDepth = 1.0f;
20723 viewport.minDepth = 0.0f;
20724 viewport.width = 512;
20725 viewport.height = 512;
20726 viewport.x = 0;
20727 viewport.y = 0;
20728 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20729 vkEndCommandBuffer(command_buffer[0]);
20730 }
20731 {
20732 VkCommandBufferBeginInfo begin_info{};
20733 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20734 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20735
20736 VkViewport viewport{};
20737 viewport.maxDepth = 1.0f;
20738 viewport.minDepth = 0.0f;
20739 viewport.width = 512;
20740 viewport.height = 512;
20741 viewport.x = 0;
20742 viewport.y = 0;
20743 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20744 vkEndCommandBuffer(command_buffer[1]);
20745 }
20746 {
20747 VkSubmitInfo submit_info{};
20748 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20749 submit_info.commandBufferCount = 1;
20750 submit_info.pCommandBuffers = &command_buffer[0];
20751 submit_info.signalSemaphoreCount = 1;
20752 submit_info.pSignalSemaphores = &semaphore;
20753 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20754 }
20755 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020756 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020757 VkSubmitInfo submit_info{};
20758 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20759 submit_info.commandBufferCount = 1;
20760 submit_info.pCommandBuffers = &command_buffer[1];
20761 submit_info.waitSemaphoreCount = 1;
20762 submit_info.pWaitSemaphores = &semaphore;
20763 submit_info.pWaitDstStageMask = flags;
20764 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20765 }
20766
20767 vkQueueWaitIdle(m_device->m_queue);
20768
20769 vkDestroyFence(m_device->device(), fence, nullptr);
20770 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20771 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20772 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20773
20774 m_errorMonitor->VerifyNotFound();
20775}
20776
20777// This is a positive test. No errors should be generated.
20778TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020779 TEST_DESCRIPTION(
20780 "Two command buffers, each in a separate QueueSubmit call "
20781 "submitted on separate queues, the second having a fence"
20782 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020783
20784 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020785 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020786
20787 m_errorMonitor->ExpectSuccess();
20788
20789 VkFence fence;
20790 VkFenceCreateInfo fence_create_info{};
20791 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20792 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20793
20794 VkSemaphore semaphore;
20795 VkSemaphoreCreateInfo semaphore_create_info{};
20796 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20797 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20798
20799 VkCommandPool command_pool;
20800 VkCommandPoolCreateInfo pool_create_info{};
20801 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20802 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20803 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20804 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20805
20806 VkCommandBuffer command_buffer[2];
20807 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20808 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20809 command_buffer_allocate_info.commandPool = command_pool;
20810 command_buffer_allocate_info.commandBufferCount = 2;
20811 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20812 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20813
20814 VkQueue queue = VK_NULL_HANDLE;
20815 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20816
20817 {
20818 VkCommandBufferBeginInfo begin_info{};
20819 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20820 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20821
20822 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 -070020823 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020824
20825 VkViewport viewport{};
20826 viewport.maxDepth = 1.0f;
20827 viewport.minDepth = 0.0f;
20828 viewport.width = 512;
20829 viewport.height = 512;
20830 viewport.x = 0;
20831 viewport.y = 0;
20832 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20833 vkEndCommandBuffer(command_buffer[0]);
20834 }
20835 {
20836 VkCommandBufferBeginInfo begin_info{};
20837 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20838 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20839
20840 VkViewport viewport{};
20841 viewport.maxDepth = 1.0f;
20842 viewport.minDepth = 0.0f;
20843 viewport.width = 512;
20844 viewport.height = 512;
20845 viewport.x = 0;
20846 viewport.y = 0;
20847 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20848 vkEndCommandBuffer(command_buffer[1]);
20849 }
20850 {
20851 VkSubmitInfo submit_info{};
20852 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20853 submit_info.commandBufferCount = 1;
20854 submit_info.pCommandBuffers = &command_buffer[0];
20855 submit_info.signalSemaphoreCount = 1;
20856 submit_info.pSignalSemaphores = &semaphore;
20857 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20858 }
20859 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020860 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020861 VkSubmitInfo submit_info{};
20862 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20863 submit_info.commandBufferCount = 1;
20864 submit_info.pCommandBuffers = &command_buffer[1];
20865 submit_info.waitSemaphoreCount = 1;
20866 submit_info.pWaitSemaphores = &semaphore;
20867 submit_info.pWaitDstStageMask = flags;
20868 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20869 }
20870
20871 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20872 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20873
20874 vkDestroyFence(m_device->device(), fence, nullptr);
20875 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20876 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20877 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20878
20879 m_errorMonitor->VerifyNotFound();
20880}
20881
20882TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020883 ASSERT_NO_FATAL_FAILURE(InitState());
20884 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020885 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020886 return;
20887 }
20888
20889 VkResult err;
20890
20891 m_errorMonitor->ExpectSuccess();
20892
20893 VkQueue q0 = m_device->m_queue;
20894 VkQueue q1 = nullptr;
20895 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20896 ASSERT_NE(q1, nullptr);
20897
20898 // An (empty) command buffer. We must have work in the first submission --
20899 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020900 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020901 VkCommandPool pool;
20902 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20903 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020904 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20905 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020906 VkCommandBuffer cb;
20907 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20908 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020909 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020910 err = vkBeginCommandBuffer(cb, &cbbi);
20911 ASSERT_VK_SUCCESS(err);
20912 err = vkEndCommandBuffer(cb);
20913 ASSERT_VK_SUCCESS(err);
20914
20915 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020916 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020917 VkSemaphore s;
20918 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20919 ASSERT_VK_SUCCESS(err);
20920
20921 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020922 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020923
20924 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20925 ASSERT_VK_SUCCESS(err);
20926
20927 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020928 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020929 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020930
20931 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20932 ASSERT_VK_SUCCESS(err);
20933
20934 // Wait for q0 idle
20935 err = vkQueueWaitIdle(q0);
20936 ASSERT_VK_SUCCESS(err);
20937
20938 // Command buffer should have been completed (it was on q0); reset the pool.
20939 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20940
20941 m_errorMonitor->VerifyNotFound();
20942
20943 // Force device completely idle and clean up resources
20944 vkDeviceWaitIdle(m_device->device());
20945 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20946 vkDestroySemaphore(m_device->device(), s, nullptr);
20947}
20948
20949// This is a positive test. No errors should be generated.
20950TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020951 TEST_DESCRIPTION(
20952 "Two command buffers, each in a separate QueueSubmit call "
20953 "submitted on separate queues, the second having a fence, "
20954 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020955
20956 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020957 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020958
20959 m_errorMonitor->ExpectSuccess();
20960
20961 ASSERT_NO_FATAL_FAILURE(InitState());
20962 VkFence fence;
20963 VkFenceCreateInfo fence_create_info{};
20964 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20965 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20966
20967 VkSemaphore semaphore;
20968 VkSemaphoreCreateInfo semaphore_create_info{};
20969 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20970 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20971
20972 VkCommandPool command_pool;
20973 VkCommandPoolCreateInfo pool_create_info{};
20974 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20975 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20976 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20977 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20978
20979 VkCommandBuffer command_buffer[2];
20980 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20981 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20982 command_buffer_allocate_info.commandPool = command_pool;
20983 command_buffer_allocate_info.commandBufferCount = 2;
20984 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20985 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20986
20987 VkQueue queue = VK_NULL_HANDLE;
20988 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20989
20990 {
20991 VkCommandBufferBeginInfo begin_info{};
20992 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20993 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20994
20995 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 -070020996 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020997
20998 VkViewport viewport{};
20999 viewport.maxDepth = 1.0f;
21000 viewport.minDepth = 0.0f;
21001 viewport.width = 512;
21002 viewport.height = 512;
21003 viewport.x = 0;
21004 viewport.y = 0;
21005 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21006 vkEndCommandBuffer(command_buffer[0]);
21007 }
21008 {
21009 VkCommandBufferBeginInfo begin_info{};
21010 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21011 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21012
21013 VkViewport viewport{};
21014 viewport.maxDepth = 1.0f;
21015 viewport.minDepth = 0.0f;
21016 viewport.width = 512;
21017 viewport.height = 512;
21018 viewport.x = 0;
21019 viewport.y = 0;
21020 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21021 vkEndCommandBuffer(command_buffer[1]);
21022 }
21023 {
21024 VkSubmitInfo submit_info{};
21025 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21026 submit_info.commandBufferCount = 1;
21027 submit_info.pCommandBuffers = &command_buffer[0];
21028 submit_info.signalSemaphoreCount = 1;
21029 submit_info.pSignalSemaphores = &semaphore;
21030 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21031 }
21032 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021033 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021034 VkSubmitInfo submit_info{};
21035 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21036 submit_info.commandBufferCount = 1;
21037 submit_info.pCommandBuffers = &command_buffer[1];
21038 submit_info.waitSemaphoreCount = 1;
21039 submit_info.pWaitSemaphores = &semaphore;
21040 submit_info.pWaitDstStageMask = flags;
21041 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21042 }
21043
21044 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21045
21046 vkDestroyFence(m_device->device(), fence, nullptr);
21047 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21048 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21049 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21050
21051 m_errorMonitor->VerifyNotFound();
21052}
21053
21054// This is a positive test. No errors should be generated.
21055TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021056 TEST_DESCRIPTION(
21057 "Two command buffers, each in a separate QueueSubmit call "
21058 "on the same queue, sharing a signal/wait semaphore, the "
21059 "second having a fence, "
21060 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021061
21062 m_errorMonitor->ExpectSuccess();
21063
21064 ASSERT_NO_FATAL_FAILURE(InitState());
21065 VkFence fence;
21066 VkFenceCreateInfo fence_create_info{};
21067 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21068 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21069
21070 VkSemaphore semaphore;
21071 VkSemaphoreCreateInfo semaphore_create_info{};
21072 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21073 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21074
21075 VkCommandPool command_pool;
21076 VkCommandPoolCreateInfo pool_create_info{};
21077 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21078 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21079 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21080 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21081
21082 VkCommandBuffer command_buffer[2];
21083 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21084 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21085 command_buffer_allocate_info.commandPool = command_pool;
21086 command_buffer_allocate_info.commandBufferCount = 2;
21087 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21088 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21089
21090 {
21091 VkCommandBufferBeginInfo begin_info{};
21092 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21093 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21094
21095 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 -070021096 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021097
21098 VkViewport viewport{};
21099 viewport.maxDepth = 1.0f;
21100 viewport.minDepth = 0.0f;
21101 viewport.width = 512;
21102 viewport.height = 512;
21103 viewport.x = 0;
21104 viewport.y = 0;
21105 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21106 vkEndCommandBuffer(command_buffer[0]);
21107 }
21108 {
21109 VkCommandBufferBeginInfo begin_info{};
21110 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21111 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21112
21113 VkViewport viewport{};
21114 viewport.maxDepth = 1.0f;
21115 viewport.minDepth = 0.0f;
21116 viewport.width = 512;
21117 viewport.height = 512;
21118 viewport.x = 0;
21119 viewport.y = 0;
21120 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21121 vkEndCommandBuffer(command_buffer[1]);
21122 }
21123 {
21124 VkSubmitInfo submit_info{};
21125 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21126 submit_info.commandBufferCount = 1;
21127 submit_info.pCommandBuffers = &command_buffer[0];
21128 submit_info.signalSemaphoreCount = 1;
21129 submit_info.pSignalSemaphores = &semaphore;
21130 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21131 }
21132 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021133 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021134 VkSubmitInfo submit_info{};
21135 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21136 submit_info.commandBufferCount = 1;
21137 submit_info.pCommandBuffers = &command_buffer[1];
21138 submit_info.waitSemaphoreCount = 1;
21139 submit_info.pWaitSemaphores = &semaphore;
21140 submit_info.pWaitDstStageMask = flags;
21141 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21142 }
21143
21144 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21145
21146 vkDestroyFence(m_device->device(), fence, nullptr);
21147 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21148 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21149 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21150
21151 m_errorMonitor->VerifyNotFound();
21152}
21153
21154// This is a positive test. No errors should be generated.
21155TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021156 TEST_DESCRIPTION(
21157 "Two command buffers, each in a separate QueueSubmit call "
21158 "on the same queue, no fences, followed by a third QueueSubmit with NO "
21159 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021160
21161 m_errorMonitor->ExpectSuccess();
21162
21163 ASSERT_NO_FATAL_FAILURE(InitState());
21164 VkFence fence;
21165 VkFenceCreateInfo fence_create_info{};
21166 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21167 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21168
21169 VkCommandPool command_pool;
21170 VkCommandPoolCreateInfo pool_create_info{};
21171 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21172 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21173 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21174 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21175
21176 VkCommandBuffer command_buffer[2];
21177 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21178 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21179 command_buffer_allocate_info.commandPool = command_pool;
21180 command_buffer_allocate_info.commandBufferCount = 2;
21181 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21182 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21183
21184 {
21185 VkCommandBufferBeginInfo begin_info{};
21186 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21187 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21188
21189 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 -070021190 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021191
21192 VkViewport viewport{};
21193 viewport.maxDepth = 1.0f;
21194 viewport.minDepth = 0.0f;
21195 viewport.width = 512;
21196 viewport.height = 512;
21197 viewport.x = 0;
21198 viewport.y = 0;
21199 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21200 vkEndCommandBuffer(command_buffer[0]);
21201 }
21202 {
21203 VkCommandBufferBeginInfo begin_info{};
21204 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21205 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21206
21207 VkViewport viewport{};
21208 viewport.maxDepth = 1.0f;
21209 viewport.minDepth = 0.0f;
21210 viewport.width = 512;
21211 viewport.height = 512;
21212 viewport.x = 0;
21213 viewport.y = 0;
21214 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21215 vkEndCommandBuffer(command_buffer[1]);
21216 }
21217 {
21218 VkSubmitInfo submit_info{};
21219 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21220 submit_info.commandBufferCount = 1;
21221 submit_info.pCommandBuffers = &command_buffer[0];
21222 submit_info.signalSemaphoreCount = 0;
21223 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21224 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21225 }
21226 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021227 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021228 VkSubmitInfo submit_info{};
21229 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21230 submit_info.commandBufferCount = 1;
21231 submit_info.pCommandBuffers = &command_buffer[1];
21232 submit_info.waitSemaphoreCount = 0;
21233 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21234 submit_info.pWaitDstStageMask = flags;
21235 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21236 }
21237
21238 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
21239
21240 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21241 ASSERT_VK_SUCCESS(err);
21242
21243 vkDestroyFence(m_device->device(), fence, nullptr);
21244 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21245 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21246
21247 m_errorMonitor->VerifyNotFound();
21248}
21249
21250// This is a positive test. No errors should be generated.
21251TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021252 TEST_DESCRIPTION(
21253 "Two command buffers, each in a separate QueueSubmit call "
21254 "on the same queue, the second having a fence, followed "
21255 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021256
21257 m_errorMonitor->ExpectSuccess();
21258
21259 ASSERT_NO_FATAL_FAILURE(InitState());
21260 VkFence fence;
21261 VkFenceCreateInfo fence_create_info{};
21262 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21263 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21264
21265 VkCommandPool command_pool;
21266 VkCommandPoolCreateInfo pool_create_info{};
21267 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21268 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21269 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21270 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21271
21272 VkCommandBuffer command_buffer[2];
21273 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21274 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21275 command_buffer_allocate_info.commandPool = command_pool;
21276 command_buffer_allocate_info.commandBufferCount = 2;
21277 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21278 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21279
21280 {
21281 VkCommandBufferBeginInfo begin_info{};
21282 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21283 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21284
21285 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 -070021286 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021287
21288 VkViewport viewport{};
21289 viewport.maxDepth = 1.0f;
21290 viewport.minDepth = 0.0f;
21291 viewport.width = 512;
21292 viewport.height = 512;
21293 viewport.x = 0;
21294 viewport.y = 0;
21295 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21296 vkEndCommandBuffer(command_buffer[0]);
21297 }
21298 {
21299 VkCommandBufferBeginInfo begin_info{};
21300 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21301 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21302
21303 VkViewport viewport{};
21304 viewport.maxDepth = 1.0f;
21305 viewport.minDepth = 0.0f;
21306 viewport.width = 512;
21307 viewport.height = 512;
21308 viewport.x = 0;
21309 viewport.y = 0;
21310 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21311 vkEndCommandBuffer(command_buffer[1]);
21312 }
21313 {
21314 VkSubmitInfo submit_info{};
21315 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21316 submit_info.commandBufferCount = 1;
21317 submit_info.pCommandBuffers = &command_buffer[0];
21318 submit_info.signalSemaphoreCount = 0;
21319 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21320 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21321 }
21322 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021323 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021324 VkSubmitInfo submit_info{};
21325 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21326 submit_info.commandBufferCount = 1;
21327 submit_info.pCommandBuffers = &command_buffer[1];
21328 submit_info.waitSemaphoreCount = 0;
21329 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21330 submit_info.pWaitDstStageMask = flags;
21331 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21332 }
21333
21334 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21335
21336 vkDestroyFence(m_device->device(), fence, nullptr);
21337 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21338 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21339
21340 m_errorMonitor->VerifyNotFound();
21341}
21342
21343// This is a positive test. No errors should be generated.
21344TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021345 TEST_DESCRIPTION(
21346 "Two command buffers each in a separate SubmitInfo sent in a single "
21347 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021348 ASSERT_NO_FATAL_FAILURE(InitState());
21349
21350 m_errorMonitor->ExpectSuccess();
21351
21352 VkFence fence;
21353 VkFenceCreateInfo fence_create_info{};
21354 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21355 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21356
21357 VkSemaphore semaphore;
21358 VkSemaphoreCreateInfo semaphore_create_info{};
21359 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21360 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21361
21362 VkCommandPool command_pool;
21363 VkCommandPoolCreateInfo pool_create_info{};
21364 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21365 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21366 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21367 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21368
21369 VkCommandBuffer command_buffer[2];
21370 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21371 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21372 command_buffer_allocate_info.commandPool = command_pool;
21373 command_buffer_allocate_info.commandBufferCount = 2;
21374 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21375 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21376
21377 {
21378 VkCommandBufferBeginInfo begin_info{};
21379 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21380 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21381
21382 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 -070021383 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021384
21385 VkViewport viewport{};
21386 viewport.maxDepth = 1.0f;
21387 viewport.minDepth = 0.0f;
21388 viewport.width = 512;
21389 viewport.height = 512;
21390 viewport.x = 0;
21391 viewport.y = 0;
21392 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21393 vkEndCommandBuffer(command_buffer[0]);
21394 }
21395 {
21396 VkCommandBufferBeginInfo begin_info{};
21397 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21398 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21399
21400 VkViewport viewport{};
21401 viewport.maxDepth = 1.0f;
21402 viewport.minDepth = 0.0f;
21403 viewport.width = 512;
21404 viewport.height = 512;
21405 viewport.x = 0;
21406 viewport.y = 0;
21407 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21408 vkEndCommandBuffer(command_buffer[1]);
21409 }
21410 {
21411 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021412 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021413
21414 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21415 submit_info[0].pNext = NULL;
21416 submit_info[0].commandBufferCount = 1;
21417 submit_info[0].pCommandBuffers = &command_buffer[0];
21418 submit_info[0].signalSemaphoreCount = 1;
21419 submit_info[0].pSignalSemaphores = &semaphore;
21420 submit_info[0].waitSemaphoreCount = 0;
21421 submit_info[0].pWaitSemaphores = NULL;
21422 submit_info[0].pWaitDstStageMask = 0;
21423
21424 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21425 submit_info[1].pNext = NULL;
21426 submit_info[1].commandBufferCount = 1;
21427 submit_info[1].pCommandBuffers = &command_buffer[1];
21428 submit_info[1].waitSemaphoreCount = 1;
21429 submit_info[1].pWaitSemaphores = &semaphore;
21430 submit_info[1].pWaitDstStageMask = flags;
21431 submit_info[1].signalSemaphoreCount = 0;
21432 submit_info[1].pSignalSemaphores = NULL;
21433 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21434 }
21435
21436 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21437
21438 vkDestroyFence(m_device->device(), fence, nullptr);
21439 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21440 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21441 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21442
21443 m_errorMonitor->VerifyNotFound();
21444}
21445
21446TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21447 m_errorMonitor->ExpectSuccess();
21448
21449 ASSERT_NO_FATAL_FAILURE(InitState());
21450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21451
Tony Barbour552f6c02016-12-21 14:34:07 -070021452 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021453
21454 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21455 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21456 m_errorMonitor->VerifyNotFound();
21457 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21458 m_errorMonitor->VerifyNotFound();
21459 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21460 m_errorMonitor->VerifyNotFound();
21461
21462 m_commandBuffer->EndCommandBuffer();
21463 m_errorMonitor->VerifyNotFound();
21464}
21465
21466TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021467 TEST_DESCRIPTION(
21468 "Positive test where we create a renderpass with an "
21469 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21470 "has a valid layout, and a second subpass then uses a "
21471 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021472 m_errorMonitor->ExpectSuccess();
21473 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070021474 auto depth_format = find_depth_stencil_format(m_device);
21475 if (!depth_format) {
21476 printf(" No Depth + Stencil format found. Skipped.\n");
21477 return;
21478 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021479
21480 VkAttachmentReference attach[2] = {};
21481 attach[0].attachment = 0;
21482 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21483 attach[1].attachment = 0;
21484 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21485 VkSubpassDescription subpasses[2] = {};
21486 // First subpass clears DS attach on load
21487 subpasses[0].pDepthStencilAttachment = &attach[0];
21488 // 2nd subpass reads in DS as input attachment
21489 subpasses[1].inputAttachmentCount = 1;
21490 subpasses[1].pInputAttachments = &attach[1];
21491 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070021492 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021493 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21494 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21495 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21496 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21497 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21498 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21499 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21500 VkRenderPassCreateInfo rpci = {};
21501 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21502 rpci.attachmentCount = 1;
21503 rpci.pAttachments = &attach_desc;
21504 rpci.subpassCount = 2;
21505 rpci.pSubpasses = subpasses;
21506
21507 // Now create RenderPass and verify no errors
21508 VkRenderPass rp;
21509 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21510 m_errorMonitor->VerifyNotFound();
21511
21512 vkDestroyRenderPass(m_device->device(), rp, NULL);
21513}
21514
Tobin Ehlis01103de2017-02-16 13:22:47 -070021515TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21516 TEST_DESCRIPTION(
21517 "Create a render pass with depth-stencil attachment where layout transition "
21518 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21519 "transition has correctly occurred at queue submit time with no validation errors.");
21520
Tony Barbourf887b162017-03-09 10:06:46 -070021521 ASSERT_NO_FATAL_FAILURE(InitState());
21522 auto depth_format = find_depth_stencil_format(m_device);
21523 if (!depth_format) {
21524 printf(" No Depth + Stencil format found. Skipped.\n");
21525 return;
21526 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070021527 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070021528 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021529 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21530 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070021531 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070021532 return;
21533 }
21534
21535 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070021536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21537
21538 // A renderpass with one depth/stencil attachment.
21539 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070021540 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021541 VK_SAMPLE_COUNT_1_BIT,
21542 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21543 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21544 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21545 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21546 VK_IMAGE_LAYOUT_UNDEFINED,
21547 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21548
21549 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21550
21551 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21552
21553 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21554
21555 VkRenderPass rp;
21556 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21557 ASSERT_VK_SUCCESS(err);
21558 // A compatible ds image.
21559 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070021560 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 -070021561 ASSERT_TRUE(image.initialized());
21562
21563 VkImageViewCreateInfo ivci = {
21564 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21565 nullptr,
21566 0,
21567 image.handle(),
21568 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070021569 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021570 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21571 VK_COMPONENT_SWIZZLE_IDENTITY},
21572 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21573 };
21574 VkImageView view;
21575 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21576 ASSERT_VK_SUCCESS(err);
21577
21578 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21579 VkFramebuffer fb;
21580 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21581 ASSERT_VK_SUCCESS(err);
21582
21583 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21584 m_commandBuffer->BeginCommandBuffer();
21585 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21586 vkCmdEndRenderPass(m_commandBuffer->handle());
21587 m_commandBuffer->EndCommandBuffer();
21588 QueueCommandBuffer(false);
21589 m_errorMonitor->VerifyNotFound();
21590
21591 // Cleanup
21592 vkDestroyImageView(m_device->device(), view, NULL);
21593 vkDestroyRenderPass(m_device->device(), rp, NULL);
21594 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21595}
21596
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021597TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021598 TEST_DESCRIPTION(
21599 "Test that pipeline validation accepts matrices passed "
21600 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021601 m_errorMonitor->ExpectSuccess();
21602
21603 ASSERT_NO_FATAL_FAILURE(InitState());
21604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21605
21606 VkVertexInputBindingDescription input_binding;
21607 memset(&input_binding, 0, sizeof(input_binding));
21608
21609 VkVertexInputAttributeDescription input_attribs[2];
21610 memset(input_attribs, 0, sizeof(input_attribs));
21611
21612 for (int i = 0; i < 2; i++) {
21613 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21614 input_attribs[i].location = i;
21615 }
21616
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021617 char const *vsSource =
21618 "#version 450\n"
21619 "\n"
21620 "layout(location=0) in mat2x4 x;\n"
21621 "out gl_PerVertex {\n"
21622 " vec4 gl_Position;\n"
21623 "};\n"
21624 "void main(){\n"
21625 " gl_Position = x[0] + x[1];\n"
21626 "}\n";
21627 char const *fsSource =
21628 "#version 450\n"
21629 "\n"
21630 "layout(location=0) out vec4 color;\n"
21631 "void main(){\n"
21632 " color = vec4(1);\n"
21633 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021634
21635 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21636 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21637
21638 VkPipelineObj pipe(m_device);
21639 pipe.AddColorAttachment();
21640 pipe.AddShader(&vs);
21641 pipe.AddShader(&fs);
21642
21643 pipe.AddVertexInputBindings(&input_binding, 1);
21644 pipe.AddVertexInputAttribs(input_attribs, 2);
21645
21646 VkDescriptorSetObj descriptorSet(m_device);
21647 descriptorSet.AppendDummy();
21648 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21649
21650 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21651
21652 /* expect success */
21653 m_errorMonitor->VerifyNotFound();
21654}
21655
21656TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21657 m_errorMonitor->ExpectSuccess();
21658
21659 ASSERT_NO_FATAL_FAILURE(InitState());
21660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21661
21662 VkVertexInputBindingDescription input_binding;
21663 memset(&input_binding, 0, sizeof(input_binding));
21664
21665 VkVertexInputAttributeDescription input_attribs[2];
21666 memset(input_attribs, 0, sizeof(input_attribs));
21667
21668 for (int i = 0; i < 2; i++) {
21669 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21670 input_attribs[i].location = i;
21671 }
21672
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021673 char const *vsSource =
21674 "#version 450\n"
21675 "\n"
21676 "layout(location=0) in vec4 x[2];\n"
21677 "out gl_PerVertex {\n"
21678 " vec4 gl_Position;\n"
21679 "};\n"
21680 "void main(){\n"
21681 " gl_Position = x[0] + x[1];\n"
21682 "}\n";
21683 char const *fsSource =
21684 "#version 450\n"
21685 "\n"
21686 "layout(location=0) out vec4 color;\n"
21687 "void main(){\n"
21688 " color = vec4(1);\n"
21689 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021690
21691 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21692 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21693
21694 VkPipelineObj pipe(m_device);
21695 pipe.AddColorAttachment();
21696 pipe.AddShader(&vs);
21697 pipe.AddShader(&fs);
21698
21699 pipe.AddVertexInputBindings(&input_binding, 1);
21700 pipe.AddVertexInputAttribs(input_attribs, 2);
21701
21702 VkDescriptorSetObj descriptorSet(m_device);
21703 descriptorSet.AppendDummy();
21704 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21705
21706 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21707
21708 m_errorMonitor->VerifyNotFound();
21709}
21710
21711TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021712 TEST_DESCRIPTION(
21713 "Test that pipeline validation accepts consuming a vertex attribute "
21714 "through multiple vertex shader inputs, each consuming a different "
21715 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021716 m_errorMonitor->ExpectSuccess();
21717
21718 ASSERT_NO_FATAL_FAILURE(InitState());
21719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21720
21721 VkVertexInputBindingDescription input_binding;
21722 memset(&input_binding, 0, sizeof(input_binding));
21723
21724 VkVertexInputAttributeDescription input_attribs[3];
21725 memset(input_attribs, 0, sizeof(input_attribs));
21726
21727 for (int i = 0; i < 3; i++) {
21728 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21729 input_attribs[i].location = i;
21730 }
21731
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021732 char const *vsSource =
21733 "#version 450\n"
21734 "\n"
21735 "layout(location=0) in vec4 x;\n"
21736 "layout(location=1) in vec3 y1;\n"
21737 "layout(location=1, component=3) in float y2;\n"
21738 "layout(location=2) in vec4 z;\n"
21739 "out gl_PerVertex {\n"
21740 " vec4 gl_Position;\n"
21741 "};\n"
21742 "void main(){\n"
21743 " gl_Position = x + vec4(y1, y2) + z;\n"
21744 "}\n";
21745 char const *fsSource =
21746 "#version 450\n"
21747 "\n"
21748 "layout(location=0) out vec4 color;\n"
21749 "void main(){\n"
21750 " color = vec4(1);\n"
21751 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021752
21753 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21754 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21755
21756 VkPipelineObj pipe(m_device);
21757 pipe.AddColorAttachment();
21758 pipe.AddShader(&vs);
21759 pipe.AddShader(&fs);
21760
21761 pipe.AddVertexInputBindings(&input_binding, 1);
21762 pipe.AddVertexInputAttribs(input_attribs, 3);
21763
21764 VkDescriptorSetObj descriptorSet(m_device);
21765 descriptorSet.AppendDummy();
21766 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21767
21768 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21769
21770 m_errorMonitor->VerifyNotFound();
21771}
21772
21773TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21774 m_errorMonitor->ExpectSuccess();
21775
21776 ASSERT_NO_FATAL_FAILURE(InitState());
21777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21778
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021779 char const *vsSource =
21780 "#version 450\n"
21781 "out gl_PerVertex {\n"
21782 " vec4 gl_Position;\n"
21783 "};\n"
21784 "void main(){\n"
21785 " gl_Position = vec4(0);\n"
21786 "}\n";
21787 char const *fsSource =
21788 "#version 450\n"
21789 "\n"
21790 "layout(location=0) out vec4 color;\n"
21791 "void main(){\n"
21792 " color = vec4(1);\n"
21793 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021794
21795 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21796 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21797
21798 VkPipelineObj pipe(m_device);
21799 pipe.AddColorAttachment();
21800 pipe.AddShader(&vs);
21801 pipe.AddShader(&fs);
21802
21803 VkDescriptorSetObj descriptorSet(m_device);
21804 descriptorSet.AppendDummy();
21805 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21806
21807 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21808
21809 m_errorMonitor->VerifyNotFound();
21810}
21811
21812TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021813 TEST_DESCRIPTION(
21814 "Test that pipeline validation accepts the relaxed type matching rules "
21815 "set out in 14.1.3: fundamental type must match, and producer side must "
21816 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021817 m_errorMonitor->ExpectSuccess();
21818
21819 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21820
21821 ASSERT_NO_FATAL_FAILURE(InitState());
21822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21823
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021824 char const *vsSource =
21825 "#version 450\n"
21826 "out gl_PerVertex {\n"
21827 " vec4 gl_Position;\n"
21828 "};\n"
21829 "layout(location=0) out vec3 x;\n"
21830 "layout(location=1) out ivec3 y;\n"
21831 "layout(location=2) out vec3 z;\n"
21832 "void main(){\n"
21833 " gl_Position = vec4(0);\n"
21834 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21835 "}\n";
21836 char const *fsSource =
21837 "#version 450\n"
21838 "\n"
21839 "layout(location=0) out vec4 color;\n"
21840 "layout(location=0) in float x;\n"
21841 "layout(location=1) flat in int y;\n"
21842 "layout(location=2) in vec2 z;\n"
21843 "void main(){\n"
21844 " color = vec4(1 + x + y + z.x);\n"
21845 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021846
21847 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21848 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21849
21850 VkPipelineObj pipe(m_device);
21851 pipe.AddColorAttachment();
21852 pipe.AddShader(&vs);
21853 pipe.AddShader(&fs);
21854
21855 VkDescriptorSetObj descriptorSet(m_device);
21856 descriptorSet.AppendDummy();
21857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21858
21859 VkResult err = VK_SUCCESS;
21860 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21861 ASSERT_VK_SUCCESS(err);
21862
21863 m_errorMonitor->VerifyNotFound();
21864}
21865
21866TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021867 TEST_DESCRIPTION(
21868 "Test that pipeline validation accepts per-vertex variables "
21869 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021870 m_errorMonitor->ExpectSuccess();
21871
21872 ASSERT_NO_FATAL_FAILURE(InitState());
21873 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21874
21875 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021876 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021877 return;
21878 }
21879
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021880 char const *vsSource =
21881 "#version 450\n"
21882 "void main(){}\n";
21883 char const *tcsSource =
21884 "#version 450\n"
21885 "layout(location=0) out int x[];\n"
21886 "layout(vertices=3) out;\n"
21887 "void main(){\n"
21888 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21889 " gl_TessLevelInner[0] = 1;\n"
21890 " x[gl_InvocationID] = gl_InvocationID;\n"
21891 "}\n";
21892 char const *tesSource =
21893 "#version 450\n"
21894 "layout(triangles, equal_spacing, cw) in;\n"
21895 "layout(location=0) in int x[];\n"
21896 "out gl_PerVertex { vec4 gl_Position; };\n"
21897 "void main(){\n"
21898 " gl_Position.xyz = gl_TessCoord;\n"
21899 " gl_Position.w = x[0] + x[1] + x[2];\n"
21900 "}\n";
21901 char const *fsSource =
21902 "#version 450\n"
21903 "layout(location=0) out vec4 color;\n"
21904 "void main(){\n"
21905 " color = vec4(1);\n"
21906 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021907
21908 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21909 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21910 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21911 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21912
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021913 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21914 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021915
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021916 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021917
21918 VkPipelineObj pipe(m_device);
21919 pipe.SetInputAssembly(&iasci);
21920 pipe.SetTessellation(&tsci);
21921 pipe.AddColorAttachment();
21922 pipe.AddShader(&vs);
21923 pipe.AddShader(&tcs);
21924 pipe.AddShader(&tes);
21925 pipe.AddShader(&fs);
21926
21927 VkDescriptorSetObj descriptorSet(m_device);
21928 descriptorSet.AppendDummy();
21929 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21930
21931 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21932
21933 m_errorMonitor->VerifyNotFound();
21934}
21935
21936TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021937 TEST_DESCRIPTION(
21938 "Test that pipeline validation accepts a user-defined "
21939 "interface block passed into the geometry shader. This "
21940 "is interesting because the 'extra' array level is not "
21941 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021942 m_errorMonitor->ExpectSuccess();
21943
21944 ASSERT_NO_FATAL_FAILURE(InitState());
21945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21946
21947 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021948 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021949 return;
21950 }
21951
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021952 char const *vsSource =
21953 "#version 450\n"
21954 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21955 "void main(){\n"
21956 " vs_out.x = vec4(1);\n"
21957 "}\n";
21958 char const *gsSource =
21959 "#version 450\n"
21960 "layout(triangles) in;\n"
21961 "layout(triangle_strip, max_vertices=3) out;\n"
21962 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21963 "out gl_PerVertex { vec4 gl_Position; };\n"
21964 "void main() {\n"
21965 " gl_Position = gs_in[0].x;\n"
21966 " EmitVertex();\n"
21967 "}\n";
21968 char const *fsSource =
21969 "#version 450\n"
21970 "layout(location=0) out vec4 color;\n"
21971 "void main(){\n"
21972 " color = vec4(1);\n"
21973 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021974
21975 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21976 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21977 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21978
21979 VkPipelineObj pipe(m_device);
21980 pipe.AddColorAttachment();
21981 pipe.AddShader(&vs);
21982 pipe.AddShader(&gs);
21983 pipe.AddShader(&fs);
21984
21985 VkDescriptorSetObj descriptorSet(m_device);
21986 descriptorSet.AppendDummy();
21987 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21988
21989 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21990
21991 m_errorMonitor->VerifyNotFound();
21992}
21993
21994TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021995 TEST_DESCRIPTION(
21996 "Test that pipeline validation accepts basic use of 64bit vertex "
21997 "attributes. This is interesting because they consume multiple "
21998 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021999 m_errorMonitor->ExpectSuccess();
22000
22001 ASSERT_NO_FATAL_FAILURE(InitState());
22002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22003
22004 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022005 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022006 return;
22007 }
22008
22009 VkVertexInputBindingDescription input_bindings[1];
22010 memset(input_bindings, 0, sizeof(input_bindings));
22011
22012 VkVertexInputAttributeDescription input_attribs[4];
22013 memset(input_attribs, 0, sizeof(input_attribs));
22014 input_attribs[0].location = 0;
22015 input_attribs[0].offset = 0;
22016 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22017 input_attribs[1].location = 2;
22018 input_attribs[1].offset = 32;
22019 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22020 input_attribs[2].location = 4;
22021 input_attribs[2].offset = 64;
22022 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22023 input_attribs[3].location = 6;
22024 input_attribs[3].offset = 96;
22025 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22026
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022027 char const *vsSource =
22028 "#version 450\n"
22029 "\n"
22030 "layout(location=0) in dmat4 x;\n"
22031 "out gl_PerVertex {\n"
22032 " vec4 gl_Position;\n"
22033 "};\n"
22034 "void main(){\n"
22035 " gl_Position = vec4(x[0][0]);\n"
22036 "}\n";
22037 char const *fsSource =
22038 "#version 450\n"
22039 "\n"
22040 "layout(location=0) out vec4 color;\n"
22041 "void main(){\n"
22042 " color = vec4(1);\n"
22043 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022044
22045 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22046 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22047
22048 VkPipelineObj pipe(m_device);
22049 pipe.AddColorAttachment();
22050 pipe.AddShader(&vs);
22051 pipe.AddShader(&fs);
22052
22053 pipe.AddVertexInputBindings(input_bindings, 1);
22054 pipe.AddVertexInputAttribs(input_attribs, 4);
22055
22056 VkDescriptorSetObj descriptorSet(m_device);
22057 descriptorSet.AppendDummy();
22058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22059
22060 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22061
22062 m_errorMonitor->VerifyNotFound();
22063}
22064
22065TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
22066 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
22067 m_errorMonitor->ExpectSuccess();
22068
22069 ASSERT_NO_FATAL_FAILURE(InitState());
22070
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022071 char const *vsSource =
22072 "#version 450\n"
22073 "\n"
22074 "out gl_PerVertex {\n"
22075 " vec4 gl_Position;\n"
22076 "};\n"
22077 "void main(){\n"
22078 " gl_Position = vec4(1);\n"
22079 "}\n";
22080 char const *fsSource =
22081 "#version 450\n"
22082 "\n"
22083 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
22084 "layout(location=0) out vec4 color;\n"
22085 "void main() {\n"
22086 " color = subpassLoad(x);\n"
22087 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022088
22089 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22090 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22091
22092 VkPipelineObj pipe(m_device);
22093 pipe.AddShader(&vs);
22094 pipe.AddShader(&fs);
22095 pipe.AddColorAttachment();
22096 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22097
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022098 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
22099 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022100 VkDescriptorSetLayout dsl;
22101 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22102 ASSERT_VK_SUCCESS(err);
22103
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022104 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022105 VkPipelineLayout pl;
22106 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22107 ASSERT_VK_SUCCESS(err);
22108
22109 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022110 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22111 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22112 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
22113 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22114 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 -060022115 };
22116 VkAttachmentReference color = {
22117 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22118 };
22119 VkAttachmentReference input = {
22120 1, VK_IMAGE_LAYOUT_GENERAL,
22121 };
22122
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022123 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022124
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022125 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022126 VkRenderPass rp;
22127 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22128 ASSERT_VK_SUCCESS(err);
22129
22130 // should be OK. would go wrong here if it's going to...
22131 pipe.CreateVKPipeline(pl, rp);
22132
22133 m_errorMonitor->VerifyNotFound();
22134
22135 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22136 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22137 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22138}
22139
22140TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022141 TEST_DESCRIPTION(
22142 "Test that pipeline validation accepts a compute pipeline which declares a "
22143 "descriptor-backed resource which is not provided, but the shader does not "
22144 "statically use it. This is interesting because it requires compute pipelines "
22145 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022146 m_errorMonitor->ExpectSuccess();
22147
22148 ASSERT_NO_FATAL_FAILURE(InitState());
22149
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022150 char const *csSource =
22151 "#version 450\n"
22152 "\n"
22153 "layout(local_size_x=1) in;\n"
22154 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
22155 "void main(){\n"
22156 " // x is not used.\n"
22157 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022158
22159 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22160
22161 VkDescriptorSetObj descriptorSet(m_device);
22162 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22163
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022164 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22165 nullptr,
22166 0,
22167 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22168 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22169 descriptorSet.GetPipelineLayout(),
22170 VK_NULL_HANDLE,
22171 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022172
22173 VkPipeline pipe;
22174 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22175
22176 m_errorMonitor->VerifyNotFound();
22177
22178 if (err == VK_SUCCESS) {
22179 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22180 }
22181}
22182
22183TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022184 TEST_DESCRIPTION(
22185 "Test that pipeline validation accepts a shader consuming only the "
22186 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022187 m_errorMonitor->ExpectSuccess();
22188
22189 ASSERT_NO_FATAL_FAILURE(InitState());
22190
22191 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022192 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22193 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22194 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022195 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022196 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022197 VkDescriptorSetLayout dsl;
22198 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22199 ASSERT_VK_SUCCESS(err);
22200
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022201 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022202 VkPipelineLayout pl;
22203 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22204 ASSERT_VK_SUCCESS(err);
22205
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022206 char const *csSource =
22207 "#version 450\n"
22208 "\n"
22209 "layout(local_size_x=1) in;\n"
22210 "layout(set=0, binding=0) uniform sampler s;\n"
22211 "layout(set=0, binding=1) uniform texture2D t;\n"
22212 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22213 "void main() {\n"
22214 " x = texture(sampler2D(t, s), vec2(0));\n"
22215 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022216 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22217
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022218 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22219 nullptr,
22220 0,
22221 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22222 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22223 pl,
22224 VK_NULL_HANDLE,
22225 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022226
22227 VkPipeline pipe;
22228 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22229
22230 m_errorMonitor->VerifyNotFound();
22231
22232 if (err == VK_SUCCESS) {
22233 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22234 }
22235
22236 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22237 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22238}
22239
22240TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022241 TEST_DESCRIPTION(
22242 "Test that pipeline validation accepts a shader consuming only the "
22243 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022244 m_errorMonitor->ExpectSuccess();
22245
22246 ASSERT_NO_FATAL_FAILURE(InitState());
22247
22248 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022249 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22250 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22251 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022252 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022253 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022254 VkDescriptorSetLayout dsl;
22255 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22256 ASSERT_VK_SUCCESS(err);
22257
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022258 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022259 VkPipelineLayout pl;
22260 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22261 ASSERT_VK_SUCCESS(err);
22262
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022263 char const *csSource =
22264 "#version 450\n"
22265 "\n"
22266 "layout(local_size_x=1) in;\n"
22267 "layout(set=0, binding=0) uniform texture2D t;\n"
22268 "layout(set=0, binding=1) uniform sampler s;\n"
22269 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22270 "void main() {\n"
22271 " x = texture(sampler2D(t, s), vec2(0));\n"
22272 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022273 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22274
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022275 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22276 nullptr,
22277 0,
22278 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22279 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22280 pl,
22281 VK_NULL_HANDLE,
22282 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022283
22284 VkPipeline pipe;
22285 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22286
22287 m_errorMonitor->VerifyNotFound();
22288
22289 if (err == VK_SUCCESS) {
22290 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22291 }
22292
22293 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22294 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22295}
22296
22297TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022298 TEST_DESCRIPTION(
22299 "Test that pipeline validation accepts a shader consuming "
22300 "both the sampler and the image of a combined image+sampler "
22301 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022302 m_errorMonitor->ExpectSuccess();
22303
22304 ASSERT_NO_FATAL_FAILURE(InitState());
22305
22306 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022307 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22308 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022309 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022310 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022311 VkDescriptorSetLayout dsl;
22312 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22313 ASSERT_VK_SUCCESS(err);
22314
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022315 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022316 VkPipelineLayout pl;
22317 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22318 ASSERT_VK_SUCCESS(err);
22319
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022320 char const *csSource =
22321 "#version 450\n"
22322 "\n"
22323 "layout(local_size_x=1) in;\n"
22324 "layout(set=0, binding=0) uniform texture2D t;\n"
22325 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22326 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22327 "void main() {\n"
22328 " x = texture(sampler2D(t, s), vec2(0));\n"
22329 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022330 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22331
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022332 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22333 nullptr,
22334 0,
22335 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22336 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22337 pl,
22338 VK_NULL_HANDLE,
22339 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022340
22341 VkPipeline pipe;
22342 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22343
22344 m_errorMonitor->VerifyNotFound();
22345
22346 if (err == VK_SUCCESS) {
22347 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22348 }
22349
22350 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22351 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22352}
22353
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060022354// This test class enables the Maintenance1 extension for related validation tests
22355TEST_F(VkMaintenance1LayerTest, Maintenance1Tests) {
22356 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
22357
22358 // Ensure that extension is available and enabled.
22359 uint32_t extension_count = 0;
22360 bool supports_maintenance1_extension = false;
22361 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22362 ASSERT_VK_SUCCESS(err);
22363 if (extension_count > 0) {
22364 std::vector<VkExtensionProperties> available_extensions(extension_count);
22365
22366 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22367 ASSERT_VK_SUCCESS(err);
22368 for (const auto &extension_props : available_extensions) {
22369 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
22370 supports_maintenance1_extension = true;
22371 }
22372 }
22373 }
22374
22375 // Proceed if extension is supported by hardware
22376 if (!supports_maintenance1_extension) {
22377 printf(" Maintenance1 Extension not supported, skipping tests\n");
22378 return;
22379 }
22380 ASSERT_NO_FATAL_FAILURE(InitState());
22381
22382 m_errorMonitor->ExpectSuccess();
22383
22384 VkCommandBuffer cmd_buf;
22385 VkCommandBufferAllocateInfo alloc_info;
22386 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22387 alloc_info.pNext = NULL;
22388 alloc_info.commandBufferCount = 1;
22389 alloc_info.commandPool = m_commandPool;
22390 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22391 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
22392
22393 VkCommandBufferBeginInfo cb_binfo;
22394 cb_binfo.pNext = NULL;
22395 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22396 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
22397 cb_binfo.flags = 0;
22398 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
22399 // Set Negative height, should give error if Maintenance 1 is not enabled
22400 VkViewport viewport = {0, 0, 16, -16, 0, 1};
22401 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
22402 vkEndCommandBuffer(cmd_buf);
22403
22404 m_errorMonitor->VerifyNotFound();
22405}
22406
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022407TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22408 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22409
22410 ASSERT_NO_FATAL_FAILURE(InitState());
22411
22412 // Positive test to check parameter_validation and unique_objects support
22413 // for NV_dedicated_allocation
22414 uint32_t extension_count = 0;
22415 bool supports_nv_dedicated_allocation = false;
22416 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22417 ASSERT_VK_SUCCESS(err);
22418
22419 if (extension_count > 0) {
22420 std::vector<VkExtensionProperties> available_extensions(extension_count);
22421
22422 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22423 ASSERT_VK_SUCCESS(err);
22424
22425 for (const auto &extension_props : available_extensions) {
22426 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22427 supports_nv_dedicated_allocation = true;
22428 }
22429 }
22430 }
22431
22432 if (supports_nv_dedicated_allocation) {
22433 m_errorMonitor->ExpectSuccess();
22434
22435 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22436 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22437 dedicated_buffer_create_info.pNext = nullptr;
22438 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22439
22440 uint32_t queue_family_index = 0;
22441 VkBufferCreateInfo buffer_create_info = {};
22442 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22443 buffer_create_info.pNext = &dedicated_buffer_create_info;
22444 buffer_create_info.size = 1024;
22445 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22446 buffer_create_info.queueFamilyIndexCount = 1;
22447 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22448
22449 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022450 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022451 ASSERT_VK_SUCCESS(err);
22452
22453 VkMemoryRequirements memory_reqs;
22454 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22455
22456 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22457 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22458 dedicated_memory_info.pNext = nullptr;
22459 dedicated_memory_info.buffer = buffer;
22460 dedicated_memory_info.image = VK_NULL_HANDLE;
22461
22462 VkMemoryAllocateInfo memory_info = {};
22463 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22464 memory_info.pNext = &dedicated_memory_info;
22465 memory_info.allocationSize = memory_reqs.size;
22466
22467 bool pass;
22468 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22469 ASSERT_TRUE(pass);
22470
22471 VkDeviceMemory buffer_memory;
22472 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22473 ASSERT_VK_SUCCESS(err);
22474
22475 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22476 ASSERT_VK_SUCCESS(err);
22477
22478 vkDestroyBuffer(m_device->device(), buffer, NULL);
22479 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22480
22481 m_errorMonitor->VerifyNotFound();
22482 }
22483}
22484
22485TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22486 VkResult err;
22487
22488 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22489
22490 ASSERT_NO_FATAL_FAILURE(InitState());
22491 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22492
22493 std::vector<const char *> device_extension_names;
22494 auto features = m_device->phy().features();
22495 // Artificially disable support for non-solid fill modes
22496 features.fillModeNonSolid = false;
22497 // The sacrificial device object
22498 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22499
22500 VkRenderpassObj render_pass(&test_device);
22501
22502 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22503 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22504 pipeline_layout_ci.setLayoutCount = 0;
22505 pipeline_layout_ci.pSetLayouts = NULL;
22506
22507 VkPipelineLayout pipeline_layout;
22508 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22509 ASSERT_VK_SUCCESS(err);
22510
22511 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22512 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22513 rs_ci.pNext = nullptr;
22514 rs_ci.lineWidth = 1.0f;
22515 rs_ci.rasterizerDiscardEnable = true;
22516
22517 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22518 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22519
22520 // Set polygonMode=FILL. No error is expected
22521 m_errorMonitor->ExpectSuccess();
22522 {
22523 VkPipelineObj pipe(&test_device);
22524 pipe.AddShader(&vs);
22525 pipe.AddShader(&fs);
22526 pipe.AddColorAttachment();
22527 // Set polygonMode to a good value
22528 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22529 pipe.SetRasterization(&rs_ci);
22530 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22531 }
22532 m_errorMonitor->VerifyNotFound();
22533
22534 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22535}
22536
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022537#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022538TEST_F(VkPositiveLayerTest, LongFenceChain)
22539{
22540 m_errorMonitor->ExpectSuccess();
22541
22542 ASSERT_NO_FATAL_FAILURE(InitState());
22543 VkResult err;
22544
22545 std::vector<VkFence> fences;
22546
22547 const int chainLength = 32768;
22548
22549 for (int i = 0; i < chainLength; i++) {
22550 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22551 VkFence fence;
22552 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22553 ASSERT_VK_SUCCESS(err);
22554
22555 fences.push_back(fence);
22556
22557 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22558 0, nullptr, 0, nullptr };
22559 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22560 ASSERT_VK_SUCCESS(err);
22561
22562 }
22563
22564 // BOOM, stack overflow.
22565 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22566
22567 for (auto fence : fences)
22568 vkDestroyFence(m_device->device(), fence, nullptr);
22569
22570 m_errorMonitor->VerifyNotFound();
22571}
22572#endif
22573
Cody Northrop1242dfd2016-07-13 17:24:59 -060022574#if defined(ANDROID) && defined(VALIDATION_APK)
22575static bool initialized = false;
22576static bool active = false;
22577
22578// Convert Intents to argv
22579// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022580std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022581 std::vector<std::string> args;
22582 JavaVM &vm = *app.activity->vm;
22583 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022584 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022585
22586 JNIEnv &env = *p_env;
22587 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022588 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022589 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022590 jmethodID get_string_extra_method =
22591 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022592 jvalue get_string_extra_args;
22593 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022594 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022595
22596 std::string args_str;
22597 if (extra_str) {
22598 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22599 args_str = extra_utf;
22600 env.ReleaseStringUTFChars(extra_str, extra_utf);
22601 env.DeleteLocalRef(extra_str);
22602 }
22603
22604 env.DeleteLocalRef(get_string_extra_args.l);
22605 env.DeleteLocalRef(intent);
22606 vm.DetachCurrentThread();
22607
22608 // split args_str
22609 std::stringstream ss(args_str);
22610 std::string arg;
22611 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022612 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022613 }
22614
22615 return args;
22616}
22617
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022618static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022619
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022620static void processCommand(struct android_app *app, int32_t cmd) {
22621 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022622 case APP_CMD_INIT_WINDOW: {
22623 if (app->window) {
22624 initialized = true;
22625 }
22626 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022627 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022628 case APP_CMD_GAINED_FOCUS: {
22629 active = true;
22630 break;
22631 }
22632 case APP_CMD_LOST_FOCUS: {
22633 active = false;
22634 break;
22635 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022636 }
22637}
22638
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022639void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022640 app_dummy();
22641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022642 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022643
22644 int vulkanSupport = InitVulkan();
22645 if (vulkanSupport == 0) {
22646 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22647 return;
22648 }
22649
22650 app->onAppCmd = processCommand;
22651 app->onInputEvent = processInput;
22652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022653 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022654 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022655 struct android_poll_source *source;
22656 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022657 if (source) {
22658 source->process(app, source);
22659 }
22660
22661 if (app->destroyRequested != 0) {
22662 VkTestFramework::Finish();
22663 return;
22664 }
22665 }
22666
22667 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022668 // Use the following key to send arguments to gtest, i.e.
22669 // --es args "--gtest_filter=-VkLayerTest.foo"
22670 const char key[] = "args";
22671 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022673 std::string filter = "";
22674 if (args.size() > 0) {
22675 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22676 filter += args[0];
22677 } else {
22678 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22679 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022681 int argc = 2;
22682 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22683 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022684
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022685 // Route output to files until we can override the gtest output
22686 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22687 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022688
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022689 ::testing::InitGoogleTest(&argc, argv);
22690 VkTestFramework::InitArgs(&argc, argv);
22691 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022693 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022694
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022695 if (result != 0) {
22696 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22697 } else {
22698 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22699 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022700
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022701 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022703 fclose(stdout);
22704 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022706 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022707 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022708 }
22709 }
22710}
22711#endif
22712
Tony Barbour300a6082015-04-07 13:44:53 -060022713int main(int argc, char **argv) {
22714 int result;
22715
Cody Northrop8e54a402016-03-08 22:25:52 -070022716#ifdef ANDROID
22717 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022718 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022719#endif
22720
Tony Barbour300a6082015-04-07 13:44:53 -060022721 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022722 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022723
22724 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22725
22726 result = RUN_ALL_TESTS();
22727
Tony Barbour6918cd52015-04-09 12:58:51 -060022728 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022729 return result;
22730}