blob: 0840cd202dde9c75c9d09ae233614d87fd6e4dc3 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060038#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060039#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070040
41#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060042#include <limits.h>
43#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
49//--------------------------------------------------------------------------------------
50// Mesh and VertexFormat Data
51//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070052struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070053 float posX, posY, posZ, posW; // Position data
54 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055};
56
Karl Schultz6addd812016-02-02 17:17:23 -070057#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058
59typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070060 BsoFailNone = 0x00000000,
61 BsoFailLineWidth = 0x00000001,
62 BsoFailDepthBias = 0x00000002,
63 BsoFailViewport = 0x00000004,
64 BsoFailScissor = 0x00000008,
65 BsoFailBlend = 0x00000010,
66 BsoFailDepthBounds = 0x00000020,
67 BsoFailStencilReadMask = 0x00000040,
68 BsoFailStencilWriteMask = 0x00000080,
69 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060070 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060071 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072} BsoFailSelect;
73
74struct vktriangle_vs_uniform {
75 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070076 float mvp[4][4];
77 float position[3][4];
78 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050079};
80
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081static const char bindStateVertShaderText[] =
82 "#version 450\n"
83 "vec2 vertices[3];\n"
84 "out gl_PerVertex {\n"
85 " vec4 gl_Position;\n"
86 "};\n"
87 "void main() {\n"
88 " vertices[0] = vec2(-1.0, -1.0);\n"
89 " vertices[1] = vec2( 1.0, -1.0);\n"
90 " vertices[2] = vec2( 0.0, 1.0);\n"
91 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
92 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static const char bindStateFragShaderText[] =
95 "#version 450\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
103 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
104 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600106// ErrorMonitor Usage:
107//
Dave Houltonfbf52152017-01-06 12:55:29 -0700108// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600109// encountered log messages, or a validation error enum identifying
110// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
111// will match all log messages. logMsg will return true for skipCall
112// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call VerifyFound to determine if all desired failure messages
115// were encountered. Call VerifyNotFound to determine if any unexpected
116// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700119 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700120 test_platform_thread_create_mutex(&mutex_);
121 test_platform_thread_lock_mutex(&mutex_);
122 Reset();
123 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600124 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600125
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600127
Dave Houltonfbf52152017-01-06 12:55:29 -0700128 // Set monitor to pristine state
129 void Reset() {
130 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
131 bailout_ = NULL;
132 message_found_ = VK_FALSE;
133 failure_message_strings_.clear();
134 desired_message_strings_.clear();
135 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700136 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700137 other_messages_.clear();
138 message_outstanding_count_ = 0;
139 }
140
141 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700142 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700143 test_platform_thread_lock_mutex(&mutex_);
144 desired_message_strings_.insert(msgString);
145 message_flags_ |= msgFlags;
146 message_outstanding_count_++;
147 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700150 // ErrorMonitor will look for an error message containing the specified string(s)
151 template <typename Iter>
152 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
153 for (; iter != end; ++iter) {
154 SetDesiredFailureMsg(msgFlags, *iter);
155 }
156 }
157
Dave Houltonfbf52152017-01-06 12:55:29 -0700158 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700159 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700160 test_platform_thread_lock_mutex(&mutex_);
161 desired_message_ids_.insert(msg_id);
162 message_flags_ |= msgFlags;
163 message_outstanding_count_++;
164 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600165 }
166
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700167 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
168 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
169 // function and its definition.
170 void SetUnexpectedError(const char *const msg) {
171 test_platform_thread_lock_mutex(&mutex_);
172
173 ignore_message_strings_.emplace_back(msg);
174
175 test_platform_thread_unlock_mutex(&mutex_);
176 }
177
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700178 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600179 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 test_platform_thread_lock_mutex(&mutex_);
181 if (bailout_ != NULL) {
182 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600183 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700187 if (!IgnoreMessage(errorString)) {
188 for (auto desired_msg : desired_message_strings_) {
189 if (desired_msg.length() == 0) {
190 // An empty desired_msg string "" indicates a positive test - not expecting an error.
191 // Return true to avoid calling layers/driver with this error.
192 // And don't erase the "" string, so it remains if another error is found.
193 result = VK_TRUE;
194 found_expected = true;
195 message_found_ = VK_TRUE;
196 failure_message_strings_.insert(errorString);
197 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600198 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700199 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700200 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700202 result = VK_TRUE;
203 // We only want one match for each expected error so remove from set here
204 // Since we're about the break the loop it's ok to remove from set we're iterating over
205 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 }
208 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700209 for (auto desired_id : desired_message_ids_) {
210 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
211 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
212 // Return true to avoid calling layers/driver with this error.
213 result = VK_TRUE;
214 } else if (desired_id == message_code) {
215 // Double-check that the string matches the error enum
216 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
217 found_expected = true;
218 message_outstanding_count_--;
219 result = VK_TRUE;
220 message_found_ = VK_TRUE;
221 desired_message_ids_.erase(desired_id);
222 break;
223 } else {
224 // Treat this message as a regular unexpected error, but print a warning jic
225 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
226 errorString.c_str(), desired_id, validation_error_map[desired_id]);
227 }
228 }
229 }
230
231 if (!found_expected) {
232 printf("Unexpected: %s\n", msgString);
233 other_messages_.push_back(errorString);
234 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600235 }
236
Dave Houltonfbf52152017-01-06 12:55:29 -0700237 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600238 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700241 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600242
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700243 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700245 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600246
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700247 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700248
249 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600250
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700251 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600252 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600253 if (otherMsgs.size()) {
254 cout << "Other error messages logged for this test were:" << endl;
255 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
256 cout << " " << *iter << endl;
257 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600258 }
259 }
260
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600263 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700264 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600265 // Match ANY message matching specified type
266 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 }
269
270 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700275 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700278 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600279 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700281 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
283
284 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600285 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700286 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200287 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700289 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600290 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200291 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600358
359 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600360 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600361 std::vector<const char *> instance_extension_names;
362 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600363
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700364 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600365 /*
366 * Since CreateDbgMsgCallback is an instance level extension call
367 * any extension / layer that utilizes that feature also needs
368 * to be enabled at create instance time.
369 */
Karl Schultz6addd812016-02-02 17:17:23 -0700370 // Use Threading layer first to protect others from
371 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700372 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600373 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800374 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700375 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600376 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700377 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600378
Ian Elliott2c1daf52016-05-12 09:41:46 -0600379 if (m_enableWSI) {
380 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
381 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
382#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
383#if defined(VK_USE_PLATFORM_ANDROID_KHR)
384 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700385#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600386#if defined(VK_USE_PLATFORM_MIR_KHR)
387 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700388#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600389#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
390 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700391#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600392#if defined(VK_USE_PLATFORM_WIN32_KHR)
393 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700394#endif // VK_USE_PLATFORM_WIN32_KHR
395#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600396#if defined(VK_USE_PLATFORM_XCB_KHR)
397 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
398#elif defined(VK_USE_PLATFORM_XLIB_KHR)
399 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700400#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600401 }
402
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600404 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800405 this->app_info.pApplicationName = "layer_tests";
406 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600407 this->app_info.pEngineName = "unittest";
408 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600409 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600410
Tony Barbour15524c32015-04-29 17:34:29 -0600411 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600412 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600413 }
414
415 virtual void TearDown() {
416 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600417 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600418 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600419 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600420
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600421 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600422};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600424void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 // Create identity matrix
426 int i;
427 struct vktriangle_vs_uniform data;
428
429 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700430 glm::mat4 View = glm::mat4(1.0f);
431 glm::mat4 Model = glm::mat4(1.0f);
432 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435
436 memcpy(&data.mvp, &MVP[0][0], matrixSize);
437
Karl Schultz6addd812016-02-02 17:17:23 -0700438 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600439 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500440 };
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 data.position[i][0] = tri_data[i].posX;
444 data.position[i][1] = tri_data[i].posY;
445 data.position[i][2] = tri_data[i].posZ;
446 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700447 data.color[i][0] = tri_data[i].r;
448 data.color[i][1] = tri_data[i].g;
449 data.color[i][2] = tri_data[i].b;
450 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451 }
452
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 ASSERT_NO_FATAL_FAILURE(InitViewport());
454
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200455 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
456 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Karl Schultz6addd812016-02-02 17:17:23 -0700458 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460
461 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800462 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500463 pipelineobj.AddShader(&vs);
464 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600465 if (failMask & BsoFailLineWidth) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
470 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600471 }
472 if (failMask & BsoFailDepthBias) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600475 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600476 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600477 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600479 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700480 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700481 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600482 if (failMask & BsoFailViewport) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
484 }
485 if (failMask & BsoFailScissor) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
487 }
488 if (failMask & BsoFailBlend) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600490 VkPipelineColorBlendAttachmentState att_state = {};
491 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
492 att_state.blendEnable = VK_TRUE;
493 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 }
495 if (failMask & BsoFailDepthBounds) {
496 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
497 }
498 if (failMask & BsoFailStencilReadMask) {
499 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
500 }
501 if (failMask & BsoFailStencilWriteMask) {
502 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
503 }
504 if (failMask & BsoFailStencilReference) {
505 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
508 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600509 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510
511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700512 m_commandBuffer->BeginCommandBuffer();
513 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
Tony Barbourfe3351b2015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
517 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600518 if (failMask & BsoFailIndexBuffer) {
519 // Use DrawIndexed w/o an index buffer bound
520 DrawIndexed(3, 1, 0, 0, 0);
521 } else {
522 Draw(3, 1, 0, 0);
523 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500524
Mark Muellerd4914412016-06-13 17:52:06 -0600525 if (failMask & BsoFailCmdClearAttachments) {
526 VkClearAttachment color_attachment = {};
527 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700528 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600529 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
530
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600531 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600532 }
533
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700535 m_commandBuffer->EndRenderPass();
536 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600537 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538}
539
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600540void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
541 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600543 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600545 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 }
547
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800548 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700549 // Make sure depthWriteEnable is set so that Depth fail test will work
550 // correctly
551 // Make sure stencilTestEnable is set so that Stencil fail test will work
552 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600553 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800554 stencil.failOp = VK_STENCIL_OP_KEEP;
555 stencil.passOp = VK_STENCIL_OP_KEEP;
556 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
557 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600558
559 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
560 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600561 ds_ci.pNext = NULL;
562 ds_ci.depthTestEnable = VK_FALSE;
563 ds_ci.depthWriteEnable = VK_TRUE;
564 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
565 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600566 if (failMask & BsoFailDepthBounds) {
567 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600568 ds_ci.maxDepthBounds = 0.0f;
569 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600571 ds_ci.stencilTestEnable = VK_TRUE;
572 ds_ci.front = stencil;
573 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600574
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600575 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600576 pipelineobj.SetViewport(m_viewports);
577 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800578 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600579 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800581 commandBuffer->BindPipeline(pipelineobj);
582 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500583}
584
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600585class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700586 public:
587 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600588};
589
Ian Elliott2c1daf52016-05-12 09:41:46 -0600590class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700591 public:
592 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600594};
595
Mark Muellerdfe37552016-07-07 14:47:42 -0600596class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700597 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 enum eTestEnFlags {
599 eDoubleDelete,
600 eInvalidDeviceOffset,
601 eInvalidMemoryOffset,
602 eBindNullBuffer,
603 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600604 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600605 };
606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600608
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600609 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
610 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600611 return true;
612 }
613 VkDeviceSize offset_limit = 0;
614 if (eInvalidMemoryOffset == aTestFlag) {
615 VkBuffer vulkanBuffer;
616 VkBufferCreateInfo buffer_create_info = {};
617 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
618 buffer_create_info.size = 32;
619 buffer_create_info.usage = aBufferUsage;
620
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600622 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
626 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
628 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600633 }
634 if (eOffsetAlignment < offset_limit) {
635 return true;
636 }
637 return false;
638 }
639
640 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
642 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 if (eBindNullBuffer == aTestFlag) {
644 VulkanMemory = 0;
645 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
646 } else {
647 VkBufferCreateInfo buffer_create_info = {};
648 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
649 buffer_create_info.size = 32;
650 buffer_create_info.usage = aBufferUsage;
651
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600653
654 CreateCurrent = true;
655
656 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658
659 VkMemoryAllocateInfo memory_allocate_info = {};
660 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
661 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
663 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 if (!pass) {
665 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
666 return;
667 }
668
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600669 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600670 AllocateCurrent = true;
671 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
673 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 BoundCurrent = true;
675
676 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
677 }
678 }
679
680 ~VkBufferTest() {
681 if (CreateCurrent) {
682 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
683 }
684 if (AllocateCurrent) {
685 if (InvalidDeleteEn) {
686 union {
687 VkDeviceMemory device_memory;
688 unsigned long long index_access;
689 } bad_index;
690
691 bad_index.device_memory = VulkanMemory;
692 bad_index.index_access++;
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 }
696 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
697 }
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
704 void TestDoubleDestroy() {
705 // Destroy the buffer but leave the flag set, which will cause
706 // the buffer to be destroyed again in the destructor.
707 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
708 }
709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700710 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600711 bool AllocateCurrent;
712 bool BoundCurrent;
713 bool CreateCurrent;
714 bool InvalidDeleteEn;
715
716 VkBuffer VulkanBuffer;
717 VkDevice VulkanDevice;
718 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719};
720
721class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700722 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700725 : BoundCurrent(false),
726 AttributeCount(aAttributeCount),
727 BindingCount(aBindingCount),
728 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600729 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600730 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
731 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
735 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600736
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
738 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
739 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
740 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
741 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600742
743 unsigned i = 0;
744 do {
745 VertexInputAttributeDescription[i].binding = BindId;
746 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
748 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600749 i++;
750 } while (AttributeCount < i);
751
752 i = 0;
753 do {
754 VertexInputBindingDescription[i].binding = BindId;
755 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600756 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600757 i++;
758 } while (BindingCount < i);
759 }
760
761 ~VkVerticesObj() {
762 if (VertexInputAttributeDescription) {
763 delete[] VertexInputAttributeDescription;
764 }
765 if (VertexInputBindingDescription) {
766 delete[] VertexInputBindingDescription;
767 }
768 }
769
770 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
772 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 return true;
774 }
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600777 VkDeviceSize *offsetList;
778 unsigned offsetCount;
779
780 if (aOffsetCount) {
781 offsetList = aOffsetList;
782 offsetCount = aOffsetCount;
783 } else {
784 offsetList = new VkDeviceSize[1]();
785 offsetCount = 1;
786 }
787
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600788 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600789 BoundCurrent = true;
790
791 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600793 }
794 }
795
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700796 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 static uint32_t BindIdGenerator;
798
799 bool BoundCurrent;
800 unsigned AttributeCount;
801 unsigned BindingCount;
802 uint32_t BindId;
803
804 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
805 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
806 VkVertexInputBindingDescription *VertexInputBindingDescription;
807 VkConstantBufferObj VulkanMemoryBuffer;
808};
809
810uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500811// ********************************************************************************************************************
812// ********************************************************************************************************************
813// ********************************************************************************************************************
814// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700816 TEST_DESCRIPTION(
817 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
818 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600823 // Specify NULL for a pointer to a handle
824 // Expected to trigger an error with
825 // parameter_validation::validate_required_pointer
826 vkGetPhysicalDeviceFeatures(gpu(), NULL);
827 m_errorMonitor->VerifyFound();
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
830 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for pointer to array count
832 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600833 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify 0 for a required array count
838 // Expected to trigger an error with parameter_validation::validate_array
839 VkViewport view_port = {};
840 m_commandBuffer->SetViewport(0, 0, &view_port);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 // Specify NULL for a required array
845 // Expected to trigger an error with parameter_validation::validate_array
846 m_commandBuffer->SetViewport(0, 1, NULL);
847 m_errorMonitor->VerifyFound();
848
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600850 // Specify VK_NULL_HANDLE for a required handle
851 // Expected to trigger an error with
852 // parameter_validation::validate_required_handle
853 vkUnmapMemory(device(), VK_NULL_HANDLE);
854 m_errorMonitor->VerifyFound();
855
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
857 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 // Specify VK_NULL_HANDLE for a required handle array entry
859 // Expected to trigger an error with
860 // parameter_validation::validate_required_handle_array
861 VkFence fence = VK_NULL_HANDLE;
862 vkResetFences(device(), 1, &fence);
863 m_errorMonitor->VerifyFound();
864
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600866 // Specify NULL for a required struct pointer
867 // Expected to trigger an error with
868 // parameter_validation::validate_struct_type
869 VkDeviceMemory memory = VK_NULL_HANDLE;
870 vkAllocateMemory(device(), NULL, NULL, &memory);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify 0 for a required VkFlags parameter
875 // Expected to trigger an error with parameter_validation::validate_flags
876 m_commandBuffer->SetStencilReference(0, 0);
877 m_errorMonitor->VerifyFound();
878
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600880 // Specify 0 for a required VkFlags array entry
881 // Expected to trigger an error with
882 // parameter_validation::validate_flags_array
883 VkSemaphore semaphore = VK_NULL_HANDLE;
884 VkPipelineStageFlags stageFlags = 0;
885 VkSubmitInfo submitInfo = {};
886 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
887 submitInfo.waitSemaphoreCount = 1;
888 submitInfo.pWaitSemaphores = &semaphore;
889 submitInfo.pWaitDstStageMask = &stageFlags;
890 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
891 m_errorMonitor->VerifyFound();
892}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600893
Dustin Gravesfce74c02016-05-10 11:42:58 -0600894TEST_F(VkLayerTest, ReservedParameter) {
895 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
896
897 ASSERT_NO_FATAL_FAILURE(InitState());
898
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600900 // Specify 0 for a reserved VkFlags parameter
901 // Expected to trigger an error with
902 // parameter_validation::validate_reserved_flags
903 VkEvent event_handle = VK_NULL_HANDLE;
904 VkEventCreateInfo event_info = {};
905 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
906 event_info.flags = 1;
907 vkCreateEvent(device(), &event_info, NULL, &event_handle);
908 m_errorMonitor->VerifyFound();
909}
910
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600911TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700912 TEST_DESCRIPTION(
913 "Specify an invalid VkStructureType for a Vulkan "
914 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915
916 ASSERT_NO_FATAL_FAILURE(InitState());
917
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 // Zero struct memory, effectively setting sType to
920 // VK_STRUCTURE_TYPE_APPLICATION_INFO
921 // Expected to trigger an error with
922 // parameter_validation::validate_struct_type
923 VkMemoryAllocateInfo alloc_info = {};
924 VkDeviceMemory memory = VK_NULL_HANDLE;
925 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
926 m_errorMonitor->VerifyFound();
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type_array
933 VkSubmitInfo submit_info = {};
934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
935 m_errorMonitor->VerifyFound();
936}
937
938TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600945 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600946 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600947 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600948 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600949 // Zero-initialization will provide the correct sType
950 VkApplicationInfo app_info = {};
951 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
952 event_alloc_info.pNext = &app_info;
953 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
954 m_errorMonitor->VerifyFound();
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
957 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600958 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
959 // a function that has allowed pNext structure types and specify
960 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600961 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600962 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600963 VkMemoryAllocateInfo memory_alloc_info = {};
964 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
965 memory_alloc_info.pNext = &app_info;
966 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600967 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
976 "does not fall within the begin..end "
977 "range of the core VkFormat "
978 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkFormat value
980 // Expected to trigger an error with
981 // parameter_validation::validate_ranged_enum
982 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600983 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600984 m_errorMonitor->VerifyFound();
985
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600987 // Specify an invalid VkFlags bitmask value
988 // Expected to trigger an error with parameter_validation::validate_flags
989 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600990 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
991 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600992 m_errorMonitor->VerifyFound();
993
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600995 // Specify an invalid VkFlags array entry
996 // Expected to trigger an error with
997 // parameter_validation::validate_flags_array
998 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600999 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001000 VkSubmitInfo submit_info = {};
1001 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1002 submit_info.waitSemaphoreCount = 1;
1003 submit_info.pWaitSemaphores = &semaphore;
1004 submit_info.pWaitDstStageMask = &stage_flags;
1005 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1006 m_errorMonitor->VerifyFound();
1007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001009 // Specify an invalid VkBool32 value
1010 // Expected to trigger a warning with
1011 // parameter_validation::validate_bool32
1012 VkSampler sampler = VK_NULL_HANDLE;
1013 VkSamplerCreateInfo sampler_info = {};
1014 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1015 sampler_info.pNext = NULL;
1016 sampler_info.magFilter = VK_FILTER_NEAREST;
1017 sampler_info.minFilter = VK_FILTER_NEAREST;
1018 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1019 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.mipLodBias = 1.0;
1023 sampler_info.maxAnisotropy = 1;
1024 sampler_info.compareEnable = VK_FALSE;
1025 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1026 sampler_info.minLod = 1.0;
1027 sampler_info.maxLod = 1.0;
1028 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1029 sampler_info.unnormalizedCoordinates = VK_FALSE;
1030 // Not VK_TRUE or VK_FALSE
1031 sampler_info.anisotropyEnable = 3;
1032 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1033 m_errorMonitor->VerifyFound();
1034}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035
1036TEST_F(VkLayerTest, FailedReturnValue) {
1037 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 // Find an unsupported image format
1042 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1044 VkFormat format = static_cast<VkFormat>(f);
1045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 unsupported = format;
1048 break;
1049 }
1050 }
1051
1052 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1054 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001055 // Specify an unsupported VkFormat value to generate a
1056 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1057 // Expected to trigger a warning from
1058 // parameter_validation::validate_result
1059 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1061 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1063 m_errorMonitor->VerifyFound();
1064 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001065}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066
1067TEST_F(VkLayerTest, UpdateBufferAlignment) {
1068 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
Tony Barbour552f6c02016-12-21 14:34:07 -07001077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1081 m_errorMonitor->VerifyFound();
1082
1083 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 // Introduce failure by using dataSize that is < 0
1089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is > 65536
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1098 m_errorMonitor->VerifyFound();
1099
Tony Barbour552f6c02016-12-21 14:34:07 -07001100 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101}
1102
1103TEST_F(VkLayerTest, FillBufferAlignment) {
1104 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1105
1106 ASSERT_NO_FATAL_FAILURE(InitState());
1107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
Tony Barbour552f6c02016-12-21 14:34:07 -07001112 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001113
1114 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1117 m_errorMonitor->VerifyFound();
1118
1119 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1122 m_errorMonitor->VerifyFound();
1123
1124 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
Tony Barbour552f6c02016-12-21 14:34:07 -07001129 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130}
Dustin Graves40f35822016-06-23 11:12:53 -06001131
Cortd889ff92016-07-27 09:51:27 -07001132TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1133 VkResult err;
1134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001135 TEST_DESCRIPTION(
1136 "Attempt to use a non-solid polygon fill mode in a "
1137 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001138
1139 ASSERT_NO_FATAL_FAILURE(InitState());
1140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1141
1142 std::vector<const char *> device_extension_names;
1143 auto features = m_device->phy().features();
1144 // Artificially disable support for non-solid fill modes
1145 features.fillModeNonSolid = false;
1146 // The sacrificial device object
1147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1148
1149 VkRenderpassObj render_pass(&test_device);
1150
1151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1153 pipeline_layout_ci.setLayoutCount = 0;
1154 pipeline_layout_ci.pSetLayouts = NULL;
1155
1156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001158 ASSERT_VK_SUCCESS(err);
1159
1160 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1161 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1162 rs_ci.pNext = nullptr;
1163 rs_ci.lineWidth = 1.0f;
1164 rs_ci.rasterizerDiscardEnable = true;
1165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1167 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001168
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001169 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1171 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001172 {
1173 VkPipelineObj pipe(&test_device);
1174 pipe.AddShader(&vs);
1175 pipe.AddShader(&fs);
1176 pipe.AddColorAttachment();
1177 // Introduce failure by setting unsupported polygon mode
1178 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1179 pipe.SetRasterization(&rs_ci);
1180 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1181 }
1182 m_errorMonitor->VerifyFound();
1183
1184 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1186 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001187 {
1188 VkPipelineObj pipe(&test_device);
1189 pipe.AddShader(&vs);
1190 pipe.AddShader(&fs);
1191 pipe.AddColorAttachment();
1192 // Introduce failure by setting unsupported polygon mode
1193 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1194 pipe.SetRasterization(&rs_ci);
1195 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1196 }
1197 m_errorMonitor->VerifyFound();
1198
Cortd889ff92016-07-27 09:51:27 -07001199 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1200}
1201
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001202#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001203TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001204{
1205 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206 VkFenceCreateInfo fenceInfo = {};
1207 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1208 fenceInfo.pNext = NULL;
1209 fenceInfo.flags = 0;
1210
Mike Weiblencce7ec72016-10-17 19:33:05 -06001211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001212
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001213 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001214
1215 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1216 vk_testing::Buffer buffer;
1217 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001244 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245}
1246
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001247TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001248{
1249 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001250 VkFenceCreateInfo fenceInfo = {};
1251 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1252 fenceInfo.pNext = NULL;
1253 fenceInfo.flags = 0;
1254
Mike Weiblencce7ec72016-10-17 19:33:05 -06001255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001256
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257 ASSERT_NO_FATAL_FAILURE(InitState());
1258 ASSERT_NO_FATAL_FAILURE(InitViewport());
1259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1260
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001263 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001264
1265 testFence.init(*m_device, fenceInfo);
1266
1267 // Bypass framework since it does the waits automatically
1268 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001269 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001270 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1271 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001272 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001273 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001274 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001275 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001277 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001278 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001279
1280 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001281 ASSERT_VK_SUCCESS( err );
1282
Jon Ashburnf19916e2016-01-11 13:12:43 -07001283 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 VkCommandBufferBeginInfo info = {};
1285 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1286 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001287 info.renderPass = VK_NULL_HANDLE;
1288 info.subpass = 0;
1289 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001290 info.occlusionQueryEnable = VK_FALSE;
1291 info.queryFlags = 0;
1292 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001293
1294 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001295 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001297 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001299#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001300
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001301TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1302 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1303
1304 ASSERT_NO_FATAL_FAILURE(InitState());
1305
1306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1307 VkBuffer buffer;
1308 VkBufferCreateInfo buf_info = {};
1309 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1310 buf_info.pNext = NULL;
1311 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1312 buf_info.size = 2048;
1313 buf_info.queueFamilyIndexCount = 0;
1314 buf_info.pQueueFamilyIndices = NULL;
1315 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1316 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1317 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1318 m_errorMonitor->VerifyFound();
1319
1320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1321 VkImage image;
1322 VkImageCreateInfo image_create_info = {};
1323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1324 image_create_info.pNext = NULL;
1325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1326 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1327 image_create_info.extent.width = 512;
1328 image_create_info.extent.height = 64;
1329 image_create_info.extent.depth = 1;
1330 image_create_info.mipLevels = 1;
1331 image_create_info.arrayLayers = 1;
1332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1334 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1336 image_create_info.queueFamilyIndexCount = 0;
1337 image_create_info.pQueueFamilyIndices = NULL;
1338 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1339 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1340 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1341 m_errorMonitor->VerifyFound();
1342}
1343
Dave Houlton829c0d82017-01-24 15:09:17 -07001344TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1345 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1346
1347 // Determine which device feature are available
1348 VkPhysicalDeviceFeatures available_features;
1349 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1350
1351 // Mask out device features we don't want
1352 VkPhysicalDeviceFeatures desired_features = available_features;
1353 desired_features.sparseResidencyImage2D = VK_FALSE;
1354 desired_features.sparseResidencyImage3D = VK_FALSE;
1355 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1356
1357 VkImage image = VK_NULL_HANDLE;
1358 VkResult result = VK_RESULT_MAX_ENUM;
1359 VkImageCreateInfo image_create_info = {};
1360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1361 image_create_info.pNext = NULL;
1362 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1363 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1364 image_create_info.extent.width = 512;
1365 image_create_info.extent.height = 1;
1366 image_create_info.extent.depth = 1;
1367 image_create_info.mipLevels = 1;
1368 image_create_info.arrayLayers = 1;
1369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1370 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1373 image_create_info.queueFamilyIndexCount = 0;
1374 image_create_info.pQueueFamilyIndices = NULL;
1375 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1376 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1377
1378 // 1D image w/ sparse residency is an error
1379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1380 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1381 m_errorMonitor->VerifyFound();
1382 if (VK_SUCCESS == result) {
1383 vkDestroyImage(m_device->device(), image, NULL);
1384 image = VK_NULL_HANDLE;
1385 }
1386
1387 // 2D image w/ sparse residency when feature isn't available
1388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1389 image_create_info.extent.height = 64;
1390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1391 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1392 m_errorMonitor->VerifyFound();
1393 if (VK_SUCCESS == result) {
1394 vkDestroyImage(m_device->device(), image, NULL);
1395 image = VK_NULL_HANDLE;
1396 }
1397
1398 // 3D image w/ sparse residency when feature isn't available
1399 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1400 image_create_info.extent.depth = 8;
1401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1402 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1403 m_errorMonitor->VerifyFound();
1404 if (VK_SUCCESS == result) {
1405 vkDestroyImage(m_device->device(), image, NULL);
1406 image = VK_NULL_HANDLE;
1407 }
1408}
1409
1410TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1411 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1412
1413 // Determine which device feature are available
1414 VkPhysicalDeviceFeatures available_features;
1415 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1416
1417 // These tests all require that the device support sparse residency for 2D images
1418 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1419 return;
1420 }
1421
1422 // Mask out device features we don't want
1423 VkPhysicalDeviceFeatures desired_features = available_features;
1424 desired_features.sparseResidency2Samples = VK_FALSE;
1425 desired_features.sparseResidency4Samples = VK_FALSE;
1426 desired_features.sparseResidency8Samples = VK_FALSE;
1427 desired_features.sparseResidency16Samples = VK_FALSE;
1428 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1429
1430 VkImage image = VK_NULL_HANDLE;
1431 VkResult result = VK_RESULT_MAX_ENUM;
1432 VkImageCreateInfo image_create_info = {};
1433 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1434 image_create_info.pNext = NULL;
1435 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1436 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1437 image_create_info.extent.width = 64;
1438 image_create_info.extent.height = 64;
1439 image_create_info.extent.depth = 1;
1440 image_create_info.mipLevels = 1;
1441 image_create_info.arrayLayers = 1;
1442 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1443 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1446 image_create_info.queueFamilyIndexCount = 0;
1447 image_create_info.pQueueFamilyIndices = NULL;
1448 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1449 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1450
1451 // 2D image w/ sparse residency and linear tiling is an error
1452 m_errorMonitor->SetDesiredFailureMsg(
1453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1455 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1456 m_errorMonitor->VerifyFound();
1457 if (VK_SUCCESS == result) {
1458 vkDestroyImage(m_device->device(), image, NULL);
1459 image = VK_NULL_HANDLE;
1460 }
1461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1462
1463 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1464 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1466 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1467 m_errorMonitor->VerifyFound();
1468 if (VK_SUCCESS == result) {
1469 vkDestroyImage(m_device->device(), image, NULL);
1470 image = VK_NULL_HANDLE;
1471 }
1472
1473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1475 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1476 m_errorMonitor->VerifyFound();
1477 if (VK_SUCCESS == result) {
1478 vkDestroyImage(m_device->device(), image, NULL);
1479 image = VK_NULL_HANDLE;
1480 }
1481
1482 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1484 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1485 m_errorMonitor->VerifyFound();
1486 if (VK_SUCCESS == result) {
1487 vkDestroyImage(m_device->device(), image, NULL);
1488 image = VK_NULL_HANDLE;
1489 }
1490
1491 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499}
1500
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001502 TEST_DESCRIPTION(
1503 "Create a buffer and image, allocate memory, and bind the "
1504 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001505 VkResult err;
1506 bool pass;
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508
Tobin Ehlis077ded32016-05-12 17:39:13 -06001509 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001510 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001511 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 VkDeviceMemory mem; // buffer will be bound first
1513 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001514 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001515 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001516
1517 VkBufferCreateInfo buf_info = {};
1518 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1519 buf_info.pNext = NULL;
1520 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1521 buf_info.size = 256;
1522 buf_info.queueFamilyIndexCount = 0;
1523 buf_info.pQueueFamilyIndices = NULL;
1524 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1525 buf_info.flags = 0;
1526 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1527 ASSERT_VK_SUCCESS(err);
1528
Tobin Ehlis077ded32016-05-12 17:39:13 -06001529 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001530
1531 VkImageCreateInfo image_create_info = {};
1532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1533 image_create_info.pNext = NULL;
1534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1535 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1536 image_create_info.extent.width = 64;
1537 image_create_info.extent.height = 64;
1538 image_create_info.extent.depth = 1;
1539 image_create_info.mipLevels = 1;
1540 image_create_info.arrayLayers = 1;
1541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001542 // Image tiling must be optimal to trigger error when aliasing linear buffer
1543 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001544 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1545 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1546 image_create_info.queueFamilyIndexCount = 0;
1547 image_create_info.pQueueFamilyIndices = NULL;
1548 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1549 image_create_info.flags = 0;
1550
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001553 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1554 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1557
1558 VkMemoryAllocateInfo alloc_info = {};
1559 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1560 alloc_info.pNext = NULL;
1561 alloc_info.memoryTypeIndex = 0;
1562 // Ensure memory is big enough for both bindings
1563 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001564 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1565 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001569 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570 return;
1571 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001572 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1573 ASSERT_VK_SUCCESS(err);
1574 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1575 ASSERT_VK_SUCCESS(err);
1576
Rene Lindsayd14f5572016-12-16 14:57:18 -07001577 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1578
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001580 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001581 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1582 m_errorMonitor->VerifyFound();
1583
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001584 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001585 // aliasing buffer2
1586 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1587 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001588 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001590 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001593 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 m_errorMonitor->VerifyFound();
1596
1597 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001598 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001599 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 vkFreeMemory(m_device->device(), mem, NULL);
1602 vkFreeMemory(m_device->device(), mem_img, NULL);
1603}
1604
Tobin Ehlis35372522016-05-12 08:32:31 -06001605TEST_F(VkLayerTest, InvalidMemoryMapping) {
1606 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1607 VkResult err;
1608 bool pass;
1609 ASSERT_NO_FATAL_FAILURE(InitState());
1610
1611 VkBuffer buffer;
1612 VkDeviceMemory mem;
1613 VkMemoryRequirements mem_reqs;
1614
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001615 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1616
Tobin Ehlis35372522016-05-12 08:32:31 -06001617 VkBufferCreateInfo buf_info = {};
1618 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1619 buf_info.pNext = NULL;
1620 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1621 buf_info.size = 256;
1622 buf_info.queueFamilyIndexCount = 0;
1623 buf_info.pQueueFamilyIndices = NULL;
1624 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1625 buf_info.flags = 0;
1626 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1627 ASSERT_VK_SUCCESS(err);
1628
1629 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1630 VkMemoryAllocateInfo alloc_info = {};
1631 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1632 alloc_info.pNext = NULL;
1633 alloc_info.memoryTypeIndex = 0;
1634
1635 // Ensure memory is big enough for both bindings
1636 static const VkDeviceSize allocation_size = 0x10000;
1637 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001639 if (!pass) {
1640 vkDestroyBuffer(m_device->device(), buffer, NULL);
1641 return;
1642 }
1643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1644 ASSERT_VK_SUCCESS(err);
1645
1646 uint8_t *pData;
1647 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1650 m_errorMonitor->VerifyFound();
1651 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001652 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001653 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1655 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1656 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001657 m_errorMonitor->VerifyFound();
1658
1659 // Unmap the memory to avoid re-map error
1660 vkUnmapMemory(m_device->device(), mem);
1661 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1663 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1664 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 m_errorMonitor->VerifyFound();
1666 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1668 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001669 m_errorMonitor->VerifyFound();
1670 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001672 vkUnmapMemory(m_device->device(), mem);
1673 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001674
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001676 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001677 ASSERT_VK_SUCCESS(err);
1678 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001679 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001681 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001683 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1684 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001685
Tobin Ehlis35372522016-05-12 08:32:31 -06001686 // Now flush range that oversteps mapped range
1687 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001688 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001689 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001690 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
1695
1696 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001701 mmr.size = VK_WHOLE_SIZE;
1702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001706#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001707 // Some platforms have an atomsize of 1 which makes the test meaningless
1708 if (atom_size > 3) {
1709 // Now with an offset NOT a multiple of the device limit
1710 vkUnmapMemory(m_device->device(), mem);
1711 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1712 ASSERT_VK_SUCCESS(err);
1713 mmr.offset = 3; // Not a multiple of atom_size
1714 mmr.size = VK_WHOLE_SIZE;
1715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1716 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1717 m_errorMonitor->VerifyFound();
1718
1719 // Now with a size NOT a multiple of the device limit
1720 vkUnmapMemory(m_device->device(), mem);
1721 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1722 ASSERT_VK_SUCCESS(err);
1723 mmr.offset = atom_size;
1724 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001729#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1731 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001732 if (!pass) {
1733 vkFreeMemory(m_device->device(), mem, NULL);
1734 vkDestroyBuffer(m_device->device(), buffer, NULL);
1735 return;
1736 }
1737 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1738 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1739
1740 vkDestroyBuffer(m_device->device(), buffer, NULL);
1741 vkFreeMemory(m_device->device(), mem, NULL);
1742}
1743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001745TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1746 VkResult err;
1747 bool pass;
1748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1750 // following declaration (which is temporarily being moved below):
1751 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001753 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001754 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001756 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001758
1759 ASSERT_NO_FATAL_FAILURE(InitState());
1760
Ian Elliott3f06ce52016-04-29 14:46:21 -06001761#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1762#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1763 // Use the functions from the VK_KHR_android_surface extension without
1764 // enabling that extension:
1765
1766 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001767 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1769 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001770 pass = (err != VK_SUCCESS);
1771 ASSERT_TRUE(pass);
1772 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001773#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001774
Ian Elliott3f06ce52016-04-29 14:46:21 -06001775#if defined(VK_USE_PLATFORM_MIR_KHR)
1776 // Use the functions from the VK_KHR_mir_surface extension without enabling
1777 // that extension:
1778
1779 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001780 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001782 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1783 pass = (err != VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785 m_errorMonitor->VerifyFound();
1786
1787 // Tell whether an mir_connection supports presentation:
1788 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1790 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001791 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001792#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001793
Ian Elliott3f06ce52016-04-29 14:46:21 -06001794#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1795 // Use the functions from the VK_KHR_wayland_surface extension without
1796 // enabling that extension:
1797
1798 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001799 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1801 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001802 pass = (err != VK_SUCCESS);
1803 ASSERT_TRUE(pass);
1804 m_errorMonitor->VerifyFound();
1805
1806 // Tell whether an wayland_display supports presentation:
1807 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1809 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001810 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001811#endif // VK_USE_PLATFORM_WAYLAND_KHR
1812#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001813
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001815 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1816 // TO NON-LINUX PLATFORMS:
1817 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001818 // Use the functions from the VK_KHR_win32_surface extension without
1819 // enabling that extension:
1820
1821 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001822 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1824 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001825 pass = (err != VK_SUCCESS);
1826 ASSERT_TRUE(pass);
1827 m_errorMonitor->VerifyFound();
1828
1829 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001831 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001832 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001833// Set this (for now, until all platforms are supported and tested):
1834#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001835#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001836#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001837 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1838 // TO NON-LINUX PLATFORMS:
1839 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001840#endif
1841#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001842 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1843 // that extension:
1844
1845 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001846 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001848 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1849 pass = (err != VK_SUCCESS);
1850 ASSERT_TRUE(pass);
1851 m_errorMonitor->VerifyFound();
1852
1853 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001854 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001855 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1857 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001859// Set this (for now, until all platforms are supported and tested):
1860#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001861#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001862
Ian Elliott12630812016-04-29 14:35:43 -06001863#if defined(VK_USE_PLATFORM_XLIB_KHR)
1864 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1865 // that extension:
1866
1867 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001868 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001870 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1871 pass = (err != VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873 m_errorMonitor->VerifyFound();
1874
1875 // Tell whether an Xlib VisualID supports presentation:
1876 Display *dpy = NULL;
1877 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001879 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1880 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001881// Set this (for now, until all platforms are supported and tested):
1882#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001883#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001885// Use the functions from the VK_KHR_surface extension without enabling
1886// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001887
Ian Elliott489eec02016-05-05 14:12:44 -06001888#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001889 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001891 vkDestroySurfaceKHR(instance(), surface, NULL);
1892 m_errorMonitor->VerifyFound();
1893
1894 // Check if surface supports presentation:
1895 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001897 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
1901
1902 // Check surface capabilities:
1903 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1905 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 pass = (err != VK_SUCCESS);
1907 ASSERT_TRUE(pass);
1908 m_errorMonitor->VerifyFound();
1909
1910 // Check surface formats:
1911 uint32_t format_count = 0;
1912 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1914 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001915 pass = (err != VK_SUCCESS);
1916 ASSERT_TRUE(pass);
1917 m_errorMonitor->VerifyFound();
1918
1919 // Check surface present modes:
1920 uint32_t present_mode_count = 0;
1921 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1923 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001927#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001928
Ian Elliott1c32c772016-04-28 14:47:13 -06001929 // Use the functions from the VK_KHR_swapchain extension without enabling
1930 // that extension:
1931
1932 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1935 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001937 pass = (err != VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1943 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 pass = (err != VK_SUCCESS);
1945 ASSERT_TRUE(pass);
1946 m_errorMonitor->VerifyFound();
1947
Chris Forbeseb7d5502016-09-13 18:19:21 +12001948 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1949 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1950 VkFence fence;
1951 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1952
Ian Elliott1c32c772016-04-28 14:47:13 -06001953 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001955 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001956 pass = (err != VK_SUCCESS);
1957 ASSERT_TRUE(pass);
1958 m_errorMonitor->VerifyFound();
1959
Chris Forbeseb7d5502016-09-13 18:19:21 +12001960 vkDestroyFence(m_device->device(), fence, nullptr);
1961
Ian Elliott1c32c772016-04-28 14:47:13 -06001962 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001963 //
1964 // NOTE: Currently can't test this because a real swapchain is needed (as
1965 // opposed to the fake one we created) in order for the layer to lookup the
1966 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001967
1968 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001970 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1971 m_errorMonitor->VerifyFound();
1972}
Chris Forbes09368e42016-10-13 11:59:22 +13001973#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001974
Karl Schultz6addd812016-02-02 17:17:23 -07001975TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1976 VkResult err;
1977 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1980 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001981
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001982 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001983
1984 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001985 VkImage image;
1986 VkDeviceMemory mem;
1987 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Karl Schultz6addd812016-02-02 17:17:23 -07001989 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1990 const int32_t tex_width = 32;
1991 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992
Tony Barboureb254902015-07-15 12:50:33 -06001993 VkImageCreateInfo image_create_info = {};
1994 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001995 image_create_info.pNext = NULL;
1996 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1997 image_create_info.format = tex_format;
1998 image_create_info.extent.width = tex_width;
1999 image_create_info.extent.height = tex_height;
2000 image_create_info.extent.depth = 1;
2001 image_create_info.mipLevels = 1;
2002 image_create_info.arrayLayers = 1;
2003 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2004 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2005 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2006 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002007 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002008
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002009 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002010 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002011 mem_alloc.pNext = NULL;
2012 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002013
Chia-I Wuf7458c52015-10-26 21:10:41 +08002014 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002015 ASSERT_VK_SUCCESS(err);
2016
Karl Schultz6addd812016-02-02 17:17:23 -07002017 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002018
Mark Lobodzinski23065352015-05-29 09:32:35 -05002019 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002021 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002022 if (!pass) { // If we can't find any unmappable memory this test doesn't
2023 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002025 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002026 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002027
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002029 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
2032 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002033 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002034 ASSERT_VK_SUCCESS(err);
2035
2036 // Map memory as if to initialize the image
2037 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002040 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002041
Chia-I Wuf7458c52015-10-26 21:10:41 +08002042 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002043 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044}
2045
Karl Schultz6addd812016-02-02 17:17:23 -07002046TEST_F(VkLayerTest, RebindMemory) {
2047 VkResult err;
2048 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002051
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002053
2054 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002055 VkImage image;
2056 VkDeviceMemory mem1;
2057 VkDeviceMemory mem2;
2058 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Karl Schultz6addd812016-02-02 17:17:23 -07002060 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2061 const int32_t tex_width = 32;
2062 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
Tony Barboureb254902015-07-15 12:50:33 -06002064 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002065 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2066 image_create_info.pNext = NULL;
2067 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2068 image_create_info.format = tex_format;
2069 image_create_info.extent.width = tex_width;
2070 image_create_info.extent.height = tex_height;
2071 image_create_info.extent.depth = 1;
2072 image_create_info.mipLevels = 1;
2073 image_create_info.arrayLayers = 1;
2074 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2075 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2076 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2077 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002079 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002080 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2081 mem_alloc.pNext = NULL;
2082 mem_alloc.allocationSize = 0;
2083 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002084
Karl Schultz6addd812016-02-02 17:17:23 -07002085 // Introduce failure, do NOT set memProps to
2086 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002087 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002088 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002089 ASSERT_VK_SUCCESS(err);
2090
Karl Schultz6addd812016-02-02 17:17:23 -07002091 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
2093 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002095 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002096
2097 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002098 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002100 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101 ASSERT_VK_SUCCESS(err);
2102
2103 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002104 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002105 ASSERT_VK_SUCCESS(err);
2106
Karl Schultz6addd812016-02-02 17:17:23 -07002107 // Introduce validation failure, try to bind a different memory object to
2108 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002109 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002110
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002111 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002112
Chia-I Wuf7458c52015-10-26 21:10:41 +08002113 vkDestroyImage(m_device->device(), image, NULL);
2114 vkFreeMemory(m_device->device(), mem1, NULL);
2115 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002117
Karl Schultz6addd812016-02-02 17:17:23 -07002118TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002119 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002120
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2122 "submitted in SIGNALED state. Fences "
2123 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002124
2125 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002126 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2127 fenceInfo.pNext = NULL;
2128 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002129
Tony Barbour300a6082015-04-07 13:44:53 -06002130 ASSERT_NO_FATAL_FAILURE(InitState());
2131 ASSERT_NO_FATAL_FAILURE(InitViewport());
2132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2133
Tony Barbour552f6c02016-12-21 14:34:07 -07002134 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002136 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002137
2138 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002139
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002140 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002141 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2142 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002143 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002144 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002145 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002146 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002148 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002149 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002150
2151 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002152 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002153
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002154 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002155}
Chris Forbes4e44c912016-06-16 10:20:00 +12002156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002158 TEST_DESCRIPTION(
2159 "Specify wrong usage for image then create conflicting view of image "
2160 "Initialize buffer with wrong usage then perform copy expecting errors "
2161 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002163
2164 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002165
2166 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2167
Tony Barbourf92621a2016-05-02 14:28:12 -06002168 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002169 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002170 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002171 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002172
Tony Barbourf92621a2016-05-02 14:28:12 -06002173 VkImageView dsv;
2174 VkImageViewCreateInfo dsvci = {};
2175 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2176 dsvci.image = image.handle();
2177 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002178 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002179 dsvci.subresourceRange.layerCount = 1;
2180 dsvci.subresourceRange.baseMipLevel = 0;
2181 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002182 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002183
Tony Barbourf92621a2016-05-02 14:28:12 -06002184 // Create a view with depth / stencil aspect for image with different usage
2185 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002187 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002188
2189 // Initialize buffer with TRANSFER_DST usage
2190 vk_testing::Buffer buffer;
2191 VkMemoryPropertyFlags reqs = 0;
2192 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2193 VkBufferImageCopy region = {};
2194 region.bufferRowLength = 128;
2195 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002196 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002197 region.imageSubresource.layerCount = 1;
2198 region.imageExtent.height = 16;
2199 region.imageExtent.width = 16;
2200 region.imageExtent.depth = 1;
2201
Mark Lobodzinski80871462017-02-16 10:37:27 -07002202 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002203 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002204
Chris Forbesda581202016-10-06 18:25:26 +13002205 // two separate errors from this call:
2206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2210 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002212}
Tony Barbour75d79f02016-08-30 09:39:07 -06002213
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002214TEST_F(VkLayerTest, LeakAnObject) {
2215 VkResult err;
2216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218
2219 // Note that we have to create a new device since destroying the
2220 // framework's device causes Teardown() to fail and just calling Teardown
2221 // will destroy the errorMonitor.
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002224
2225 ASSERT_NO_FATAL_FAILURE(InitState());
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228 std::vector<VkDeviceQueueCreateInfo> queue_info;
2229 queue_info.reserve(queue_props.size());
2230 std::vector<std::vector<float>> queue_priorities;
2231 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2232 VkDeviceQueueCreateInfo qi = {};
2233 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2234 qi.pNext = NULL;
2235 qi.queueFamilyIndex = i;
2236 qi.queueCount = queue_props[i].queueCount;
2237 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2238 qi.pQueuePriorities = queue_priorities[i].data();
2239 queue_info.push_back(qi);
2240 }
2241
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002243
2244 // The sacrificial device object
2245 VkDevice testDevice;
2246 VkDeviceCreateInfo device_create_info = {};
2247 auto features = m_device->phy().features();
2248 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2249 device_create_info.pNext = NULL;
2250 device_create_info.queueCreateInfoCount = queue_info.size();
2251 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002252 device_create_info.enabledLayerCount = 0;
2253 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254 device_create_info.pEnabledFeatures = &features;
2255 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2256 ASSERT_VK_SUCCESS(err);
2257
2258 VkFence fence;
2259 VkFenceCreateInfo fence_create_info = {};
2260 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2261 fence_create_info.pNext = NULL;
2262 fence_create_info.flags = 0;
2263 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2264 ASSERT_VK_SUCCESS(err);
2265
2266 // Induce failure by not calling vkDestroyFence
2267 vkDestroyDevice(testDevice, NULL);
2268 m_errorMonitor->VerifyFound();
2269}
2270
2271TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002272 TEST_DESCRIPTION(
2273 "Allocate command buffers from one command pool and "
2274 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002277
Cody Northropc31a84f2016-08-22 10:41:47 -06002278 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279 VkCommandPool command_pool_one;
2280 VkCommandPool command_pool_two;
2281
2282 VkCommandPoolCreateInfo pool_create_info{};
2283 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2284 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2285 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002289 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002290
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002291 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002295 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002299 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300
2301 m_errorMonitor->VerifyFound();
2302
2303 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2304 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2305}
2306
2307TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2308 VkResult err;
2309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002310 TEST_DESCRIPTION(
2311 "Allocate descriptor sets from one DS pool and "
2312 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002315
2316 ASSERT_NO_FATAL_FAILURE(InitState());
2317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2318
2319 VkDescriptorPoolSize ds_type_count = {};
2320 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2321 ds_type_count.descriptorCount = 1;
2322
2323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2325 ds_pool_ci.pNext = NULL;
2326 ds_pool_ci.flags = 0;
2327 ds_pool_ci.maxSets = 1;
2328 ds_pool_ci.poolSizeCount = 1;
2329 ds_pool_ci.pPoolSizes = &ds_type_count;
2330
2331 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333 ASSERT_VK_SUCCESS(err);
2334
2335 // Create a second descriptor pool
2336 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002337 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002338 ASSERT_VK_SUCCESS(err);
2339
2340 VkDescriptorSetLayoutBinding dsl_binding = {};
2341 dsl_binding.binding = 0;
2342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2343 dsl_binding.descriptorCount = 1;
2344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2345 dsl_binding.pImmutableSamplers = NULL;
2346
2347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2349 ds_layout_ci.pNext = NULL;
2350 ds_layout_ci.bindingCount = 1;
2351 ds_layout_ci.pBindings = &dsl_binding;
2352
2353 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002355 ASSERT_VK_SUCCESS(err);
2356
2357 VkDescriptorSet descriptorSet;
2358 VkDescriptorSetAllocateInfo alloc_info = {};
2359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2360 alloc_info.descriptorSetCount = 1;
2361 alloc_info.descriptorPool = ds_pool_one;
2362 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002364 ASSERT_VK_SUCCESS(err);
2365
2366 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2371 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2372 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2373}
2374
2375TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002379
2380 ASSERT_NO_FATAL_FAILURE(InitState());
2381
2382 // Pass bogus handle into GetImageMemoryRequirements
2383 VkMemoryRequirements mem_reqs;
2384 uint64_t fakeImageHandle = 0xCADECADE;
2385 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2386
2387 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2388
2389 m_errorMonitor->VerifyFound();
2390}
2391
Mike Schuchardt17838902017-02-21 09:48:06 -07002392TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2393 TEST_DESCRIPTION(
2394 "Try to destroy a render pass object using a device other than the one it was created on. "
2395 "This should generate a distinct error from the invalid handle error.");
2396 // Create first device and renderpass
2397 ASSERT_NO_FATAL_FAILURE(InitState());
2398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2399
2400 // Create second device
2401 float priorities[] = {1.0f};
2402 VkDeviceQueueCreateInfo queue_info{};
2403 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2404 queue_info.pNext = NULL;
2405 queue_info.flags = 0;
2406 queue_info.queueFamilyIndex = 0;
2407 queue_info.queueCount = 1;
2408 queue_info.pQueuePriorities = &priorities[0];
2409
2410 VkDeviceCreateInfo device_create_info = {};
2411 auto features = m_device->phy().features();
2412 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2413 device_create_info.pNext = NULL;
2414 device_create_info.queueCreateInfoCount = 1;
2415 device_create_info.pQueueCreateInfos = &queue_info;
2416 device_create_info.enabledLayerCount = 0;
2417 device_create_info.ppEnabledLayerNames = NULL;
2418 device_create_info.pEnabledFeatures = &features;
2419
2420 VkDevice second_device;
2421 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2422
2423 // Try to destroy the renderpass from the first device using the second device
2424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2425 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2426 m_errorMonitor->VerifyFound();
2427
2428 vkDestroyDevice(second_device, NULL);
2429}
2430
Karl Schultz6addd812016-02-02 17:17:23 -07002431TEST_F(VkLayerTest, PipelineNotBound) {
2432 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002434 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002435
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002437
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002438 ASSERT_NO_FATAL_FAILURE(InitState());
2439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002440
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002441 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002442 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2443 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002444
2445 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002446 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2447 ds_pool_ci.pNext = NULL;
2448 ds_pool_ci.maxSets = 1;
2449 ds_pool_ci.poolSizeCount = 1;
2450 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002451
2452 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002453 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454 ASSERT_VK_SUCCESS(err);
2455
2456 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002457 dsl_binding.binding = 0;
2458 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2459 dsl_binding.descriptorCount = 1;
2460 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2461 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002462
2463 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002464 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2465 ds_layout_ci.pNext = NULL;
2466 ds_layout_ci.bindingCount = 1;
2467 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468
2469 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002471 ASSERT_VK_SUCCESS(err);
2472
2473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002474 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002476 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002477 alloc_info.descriptorPool = ds_pool;
2478 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002480 ASSERT_VK_SUCCESS(err);
2481
2482 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002483 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2484 pipeline_layout_ci.pNext = NULL;
2485 pipeline_layout_ci.setLayoutCount = 1;
2486 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002487
2488 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002490 ASSERT_VK_SUCCESS(err);
2491
Mark Youngad779052016-01-06 14:26:04 -07002492 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002493
Tony Barbour552f6c02016-12-21 14:34:07 -07002494 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002496
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002497 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002498
Chia-I Wuf7458c52015-10-26 21:10:41 +08002499 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002502}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002503
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002504TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2505 VkResult err;
2506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002507 TEST_DESCRIPTION(
2508 "Test validation check for an invalid memory type index "
2509 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002510
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002511 ASSERT_NO_FATAL_FAILURE(InitState());
2512
2513 // Create an image, allocate memory, set a bad typeIndex and then try to
2514 // bind it
2515 VkImage image;
2516 VkDeviceMemory mem;
2517 VkMemoryRequirements mem_reqs;
2518 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2519 const int32_t tex_width = 32;
2520 const int32_t tex_height = 32;
2521
2522 VkImageCreateInfo image_create_info = {};
2523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2524 image_create_info.pNext = NULL;
2525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2526 image_create_info.format = tex_format;
2527 image_create_info.extent.width = tex_width;
2528 image_create_info.extent.height = tex_height;
2529 image_create_info.extent.depth = 1;
2530 image_create_info.mipLevels = 1;
2531 image_create_info.arrayLayers = 1;
2532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2533 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2535 image_create_info.flags = 0;
2536
2537 VkMemoryAllocateInfo mem_alloc = {};
2538 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2539 mem_alloc.pNext = NULL;
2540 mem_alloc.allocationSize = 0;
2541 mem_alloc.memoryTypeIndex = 0;
2542
2543 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2544 ASSERT_VK_SUCCESS(err);
2545
2546 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2547 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002548
2549 // Introduce Failure, select invalid TypeIndex
2550 VkPhysicalDeviceMemoryProperties memory_info;
2551
2552 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2553 unsigned int i;
2554 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2555 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2556 mem_alloc.memoryTypeIndex = i;
2557 break;
2558 }
2559 }
2560 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002561 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562 vkDestroyImage(m_device->device(), image, NULL);
2563 return;
2564 }
2565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002567
2568 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2569 ASSERT_VK_SUCCESS(err);
2570
2571 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2572 (void)err;
2573
2574 m_errorMonitor->VerifyFound();
2575
2576 vkDestroyImage(m_device->device(), image, NULL);
2577 vkFreeMemory(m_device->device(), mem, NULL);
2578}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002579
Karl Schultz6addd812016-02-02 17:17:23 -07002580TEST_F(VkLayerTest, BindInvalidMemory) {
2581 VkResult err;
2582 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002583
2584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002585
Cortf801b982017-01-17 18:10:21 -08002586 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002587 const int32_t tex_width = 256;
2588 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
2590 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002591 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2592 image_create_info.pNext = NULL;
2593 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2594 image_create_info.format = tex_format;
2595 image_create_info.extent.width = tex_width;
2596 image_create_info.extent.height = tex_height;
2597 image_create_info.extent.depth = 1;
2598 image_create_info.mipLevels = 1;
2599 image_create_info.arrayLayers = 1;
2600 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002601 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002602 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2603 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002604
Cortf801b982017-01-17 18:10:21 -08002605 VkBufferCreateInfo buffer_create_info = {};
2606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2607 buffer_create_info.pNext = NULL;
2608 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002609 buffer_create_info.size = 4 * 1024 * 1024;
2610 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002611 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002612
Cortf801b982017-01-17 18:10:21 -08002613 // Create an image/buffer, allocate memory, free it, and then try to bind it
2614 {
2615 VkImage image = VK_NULL_HANDLE;
2616 VkBuffer buffer = VK_NULL_HANDLE;
2617 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2618 ASSERT_VK_SUCCESS(err);
2619 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2620 ASSERT_VK_SUCCESS(err);
2621 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2622 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2623 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002624
Cortf801b982017-01-17 18:10:21 -08002625 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2626 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2627 image_mem_alloc.allocationSize = image_mem_reqs.size;
2628 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2629 ASSERT_TRUE(pass);
2630 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2631 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2632 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2633 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002634
Cortf801b982017-01-17 18:10:21 -08002635 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2636 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2637 ASSERT_VK_SUCCESS(err);
2638 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2639 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002640
Cortf801b982017-01-17 18:10:21 -08002641 vkFreeMemory(device(), image_mem, NULL);
2642 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002643
Cortf801b982017-01-17 18:10:21 -08002644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2645 err = vkBindImageMemory(device(), image, image_mem, 0);
2646 (void)err; // This may very well return an error.
2647 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2650 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2651 (void)err; // This may very well return an error.
2652 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002653
Cortf801b982017-01-17 18:10:21 -08002654 vkDestroyImage(m_device->device(), image, NULL);
2655 vkDestroyBuffer(m_device->device(), buffer, NULL);
2656 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002657
2658 // Try to bind memory to an object that already has a memory binding
2659 {
2660 VkImage image = VK_NULL_HANDLE;
2661 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2662 ASSERT_VK_SUCCESS(err);
2663 VkBuffer buffer = VK_NULL_HANDLE;
2664 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2665 ASSERT_VK_SUCCESS(err);
2666 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2667 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2668 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2669 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2670 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2671 image_alloc_info.allocationSize = image_mem_reqs.size;
2672 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2673 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2674 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2675 ASSERT_TRUE(pass);
2676 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2677 ASSERT_TRUE(pass);
2678 VkDeviceMemory image_mem, buffer_mem;
2679 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2680 ASSERT_VK_SUCCESS(err);
2681 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2682 ASSERT_VK_SUCCESS(err);
2683
2684 err = vkBindImageMemory(device(), image, image_mem, 0);
2685 ASSERT_VK_SUCCESS(err);
2686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2687 err = vkBindImageMemory(device(), image, image_mem, 0);
2688 (void)err; // This may very well return an error.
2689 m_errorMonitor->VerifyFound();
2690
2691 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2692 ASSERT_VK_SUCCESS(err);
2693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2694 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2695 (void)err; // This may very well return an error.
2696 m_errorMonitor->VerifyFound();
2697
2698 vkFreeMemory(device(), image_mem, NULL);
2699 vkFreeMemory(device(), buffer_mem, NULL);
2700 vkDestroyImage(device(), image, NULL);
2701 vkDestroyBuffer(device(), buffer, NULL);
2702 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002703
Cort Strattonde748202017-02-17 12:50:01 -08002704 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002705 {
2706 VkImage image = VK_NULL_HANDLE;
2707 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2708 ASSERT_VK_SUCCESS(err);
2709 VkBuffer buffer = VK_NULL_HANDLE;
2710 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2711 ASSERT_VK_SUCCESS(err);
2712 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2713 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2714 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2715 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2716 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002717 // Leave some extra space for alignment wiggle room
2718 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002719 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002720 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002721 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2722 ASSERT_TRUE(pass);
2723 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2724 ASSERT_TRUE(pass);
2725 VkDeviceMemory image_mem, buffer_mem;
2726 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2727 ASSERT_VK_SUCCESS(err);
2728 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2729 ASSERT_VK_SUCCESS(err);
2730
Cort Strattonde748202017-02-17 12:50:01 -08002731 // Test unaligned memory offset
2732 {
2733 if (image_mem_reqs.alignment > 1) {
2734 VkDeviceSize image_offset = 1;
2735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2736 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2737 (void)err; // This may very well return an error.
2738 m_errorMonitor->VerifyFound();
2739 }
Cort6c7dff72017-01-27 18:34:50 -08002740
Cort Strattonde748202017-02-17 12:50:01 -08002741 if (buffer_mem_reqs.alignment > 1) {
2742 VkDeviceSize buffer_offset = 1;
2743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2744 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2745 (void)err; // This may very well return an error.
2746 m_errorMonitor->VerifyFound();
2747 }
2748 }
2749
2750 // Test memory offsets outside the memory allocation
2751 {
2752 VkDeviceSize image_offset =
2753 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2755 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2756 (void)err; // This may very well return an error.
2757 m_errorMonitor->VerifyFound();
2758
2759 VkDeviceSize buffer_offset =
2760 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2762 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2763 (void)err; // This may very well return an error.
2764 m_errorMonitor->VerifyFound();
2765 }
2766
2767 // Test memory offsets within the memory allocation, but which leave too little memory for
2768 // the resource.
2769 {
2770 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2771 if (image_offset > 0) {
2772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2773 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2774 (void)err; // This may very well return an error.
2775 m_errorMonitor->VerifyFound();
2776 }
2777
2778 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2779 if (buffer_offset > 0) {
2780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2781 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2782 (void)err; // This may very well return an error.
2783 m_errorMonitor->VerifyFound();
2784 }
2785 }
Cort6c7dff72017-01-27 18:34:50 -08002786
2787 vkFreeMemory(device(), image_mem, NULL);
2788 vkFreeMemory(device(), buffer_mem, NULL);
2789 vkDestroyImage(device(), image, NULL);
2790 vkDestroyBuffer(device(), buffer, NULL);
2791 }
2792
Cort Stratton4c38bb52017-01-28 13:33:10 -08002793 // Try to bind memory to an object with an invalid memory type
2794 {
2795 VkImage image = VK_NULL_HANDLE;
2796 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2797 ASSERT_VK_SUCCESS(err);
2798 VkBuffer buffer = VK_NULL_HANDLE;
2799 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2800 ASSERT_VK_SUCCESS(err);
2801 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2802 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2803 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2804 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2805 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2806 image_alloc_info.allocationSize = image_mem_reqs.size;
2807 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2808 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002809 // Create a mask of available memory types *not* supported by these resources,
2810 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002811 VkPhysicalDeviceMemoryProperties memory_properties = {};
2812 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002813 VkDeviceMemory image_mem, buffer_mem;
2814
Cort Stratton4c38bb52017-01-28 13:33:10 -08002815 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002816 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002817 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2818 ASSERT_TRUE(pass);
2819 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2820 ASSERT_VK_SUCCESS(err);
2821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2822 err = vkBindImageMemory(device(), image, image_mem, 0);
2823 (void)err; // This may very well return an error.
2824 m_errorMonitor->VerifyFound();
2825 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002826 }
2827
Cort Stratton4c38bb52017-01-28 13:33:10 -08002828 uint32_t buffer_unsupported_mem_type_bits =
2829 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002830 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002831 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2832 ASSERT_TRUE(pass);
2833 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2834 ASSERT_VK_SUCCESS(err);
2835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2836 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2837 (void)err; // This may very well return an error.
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002840 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002841
Cort Stratton4c38bb52017-01-28 13:33:10 -08002842 vkDestroyImage(device(), image, NULL);
2843 vkDestroyBuffer(device(), buffer, NULL);
2844 }
2845
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002846 // Try to bind memory to an image created with sparse memory flags
2847 {
2848 VkImageCreateInfo sparse_image_create_info = image_create_info;
2849 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2850 VkImageFormatProperties image_format_properties = {};
2851 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2852 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2853 sparse_image_create_info.usage, sparse_image_create_info.flags,
2854 &image_format_properties);
2855 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2856 // most likely means sparse formats aren't supported here; skip this test.
2857 } else {
2858 ASSERT_VK_SUCCESS(err);
2859 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002860 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002861 return;
2862 } else {
2863 VkImage sparse_image = VK_NULL_HANDLE;
2864 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2865 ASSERT_VK_SUCCESS(err);
2866 VkMemoryRequirements sparse_mem_reqs = {};
2867 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2868 if (sparse_mem_reqs.memoryTypeBits != 0) {
2869 VkMemoryAllocateInfo sparse_mem_alloc = {};
2870 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2871 sparse_mem_alloc.pNext = NULL;
2872 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2873 sparse_mem_alloc.memoryTypeIndex = 0;
2874 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2875 ASSERT_TRUE(pass);
2876 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2877 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2878 ASSERT_VK_SUCCESS(err);
2879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2880 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2881 // This may very well return an error.
2882 (void)err;
2883 m_errorMonitor->VerifyFound();
2884 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2885 }
2886 vkDestroyImage(m_device->device(), sparse_image, NULL);
2887 }
2888 }
2889 }
2890
2891 // Try to bind memory to a buffer created with sparse memory flags
2892 {
2893 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2894 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2895 if (!m_device->phy().features().sparseResidencyBuffer) {
2896 // most likely means sparse formats aren't supported here; skip this test.
2897 } else {
2898 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2899 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2900 ASSERT_VK_SUCCESS(err);
2901 VkMemoryRequirements sparse_mem_reqs = {};
2902 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2903 if (sparse_mem_reqs.memoryTypeBits != 0) {
2904 VkMemoryAllocateInfo sparse_mem_alloc = {};
2905 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2906 sparse_mem_alloc.pNext = NULL;
2907 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2908 sparse_mem_alloc.memoryTypeIndex = 0;
2909 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2910 ASSERT_TRUE(pass);
2911 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2912 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2913 ASSERT_VK_SUCCESS(err);
2914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2915 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2916 // This may very well return an error.
2917 (void)err;
2918 m_errorMonitor->VerifyFound();
2919 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2920 }
2921 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2922 }
2923 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002924}
2925
Karl Schultz6addd812016-02-02 17:17:23 -07002926TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2927 VkResult err;
2928 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002929
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002931
Tobin Ehlisec598302015-09-15 15:02:17 -06002932 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002933
Karl Schultz6addd812016-02-02 17:17:23 -07002934 // Create an image object, allocate memory, destroy the object and then try
2935 // to bind it
2936 VkImage image;
2937 VkDeviceMemory mem;
2938 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002939
Karl Schultz6addd812016-02-02 17:17:23 -07002940 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2941 const int32_t tex_width = 32;
2942 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002943
2944 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002945 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2946 image_create_info.pNext = NULL;
2947 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2948 image_create_info.format = tex_format;
2949 image_create_info.extent.width = tex_width;
2950 image_create_info.extent.height = tex_height;
2951 image_create_info.extent.depth = 1;
2952 image_create_info.mipLevels = 1;
2953 image_create_info.arrayLayers = 1;
2954 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2955 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2956 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2957 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002958
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002959 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002960 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2961 mem_alloc.pNext = NULL;
2962 mem_alloc.allocationSize = 0;
2963 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002964
Chia-I Wuf7458c52015-10-26 21:10:41 +08002965 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002966 ASSERT_VK_SUCCESS(err);
2967
Karl Schultz6addd812016-02-02 17:17:23 -07002968 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002969
2970 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002971 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002972 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002973
2974 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002975 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002976 ASSERT_VK_SUCCESS(err);
2977
2978 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002979 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002980 ASSERT_VK_SUCCESS(err);
2981
2982 // Now Try to bind memory to this destroyed object
2983 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2984 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002985 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002987 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002988
Chia-I Wuf7458c52015-10-26 21:10:41 +08002989 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002990}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002991
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002992TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2993 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2994
2995 ASSERT_NO_FATAL_FAILURE(InitState());
2996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2997
2998 VkVertexInputBindingDescription input_binding;
2999 memset(&input_binding, 0, sizeof(input_binding));
3000
3001 VkVertexInputAttributeDescription input_attribs;
3002 memset(&input_attribs, 0, sizeof(input_attribs));
3003
3004 // Pick a really bad format for this purpose and make sure it should fail
3005 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3006 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3007 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003008 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003009 return;
3010 }
3011
3012 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003013 char const *vsSource =
3014 "#version 450\n"
3015 "\n"
3016 "out gl_PerVertex {\n"
3017 " vec4 gl_Position;\n"
3018 "};\n"
3019 "void main(){\n"
3020 " gl_Position = vec4(1);\n"
3021 "}\n";
3022 char const *fsSource =
3023 "#version 450\n"
3024 "\n"
3025 "layout(location=0) out vec4 color;\n"
3026 "void main(){\n"
3027 " color = vec4(1);\n"
3028 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003029
3030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3031 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3032 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3033
3034 VkPipelineObj pipe(m_device);
3035 pipe.AddColorAttachment();
3036 pipe.AddShader(&vs);
3037 pipe.AddShader(&fs);
3038
3039 pipe.AddVertexInputBindings(&input_binding, 1);
3040 pipe.AddVertexInputAttribs(&input_attribs, 1);
3041
3042 VkDescriptorSetObj descriptorSet(m_device);
3043 descriptorSet.AppendDummy();
3044 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3045
3046 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3047
3048 m_errorMonitor->VerifyFound();
3049}
3050
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003051TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003052 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3053 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003054
3055 VkMemoryPropertyFlags reqs = 0;
3056 VkImageCreateInfo image_create_info = {};
3057 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3058 image_create_info.pNext = NULL;
3059 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3060 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3061 image_create_info.extent.width = 256;
3062 image_create_info.extent.height = 256;
3063 image_create_info.extent.depth = 1;
3064 image_create_info.mipLevels = 1;
3065 image_create_info.arrayLayers = 1;
3066 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3067 image_create_info.flags = 0;
3068
3069 VkImageBlit blit_region = {};
3070 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3071 blit_region.srcSubresource.baseArrayLayer = 0;
3072 blit_region.srcSubresource.layerCount = 1;
3073 blit_region.srcSubresource.mipLevel = 0;
3074 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3075 blit_region.dstSubresource.baseArrayLayer = 0;
3076 blit_region.dstSubresource.layerCount = 1;
3077 blit_region.dstSubresource.mipLevel = 0;
3078
3079 // Create two images, the source with sampleCount = 2, and attempt to blit
3080 // between them
3081 {
3082 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003083 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003084 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003085 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003086 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003087 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003088 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003089 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003090 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003091 m_errorMonitor->SetDesiredFailureMsg(
3092 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3093 "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 -06003094 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3095 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003096 m_errorMonitor->VerifyFound();
3097 m_commandBuffer->EndCommandBuffer();
3098 }
3099
3100 // Create two images, the dest with sampleCount = 4, and attempt to blit
3101 // between them
3102 {
3103 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003104 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003105 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003107 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003109 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003111 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003112 m_errorMonitor->SetDesiredFailureMsg(
3113 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3114 "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 -06003115 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3116 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003117 m_errorMonitor->VerifyFound();
3118 m_commandBuffer->EndCommandBuffer();
3119 }
3120
3121 VkBufferImageCopy copy_region = {};
3122 copy_region.bufferRowLength = 128;
3123 copy_region.bufferImageHeight = 128;
3124 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3125 copy_region.imageSubresource.layerCount = 1;
3126 copy_region.imageExtent.height = 64;
3127 copy_region.imageExtent.width = 64;
3128 copy_region.imageExtent.depth = 1;
3129
3130 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3131 // buffer to image
3132 {
3133 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003134 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3135 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003136 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003137 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003138 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003139 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003140 m_errorMonitor->SetDesiredFailureMsg(
3141 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3142 "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 -06003143 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3144 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003145 m_errorMonitor->VerifyFound();
3146 m_commandBuffer->EndCommandBuffer();
3147 }
3148
3149 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3150 // image to buffer
3151 {
3152 vk_testing::Buffer dst_buffer;
3153 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3154 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003155 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003156 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003157 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003158 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003159 m_errorMonitor->SetDesiredFailureMsg(
3160 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3161 "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 -06003162 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003163 dst_buffer.handle(), 1, &copy_region);
3164 m_errorMonitor->VerifyFound();
3165 m_commandBuffer->EndCommandBuffer();
3166 }
3167}
3168
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003169TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003170 ASSERT_NO_FATAL_FAILURE(InitState());
3171
3172 VkImageObj src_image(m_device);
3173 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3174 VkImageObj dst_image(m_device);
3175 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3176 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003177 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 -06003178
3179 VkImageBlit blitRegion = {};
3180 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3181 blitRegion.srcSubresource.baseArrayLayer = 0;
3182 blitRegion.srcSubresource.layerCount = 1;
3183 blitRegion.srcSubresource.mipLevel = 0;
3184 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3185 blitRegion.dstSubresource.baseArrayLayer = 0;
3186 blitRegion.dstSubresource.layerCount = 1;
3187 blitRegion.dstSubresource.mipLevel = 0;
3188
Dave Houlton34df4cb2016-12-01 16:43:06 -07003189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3190
3191 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3192 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003193
3194 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003195 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003196 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3197 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003198
3199 m_errorMonitor->VerifyFound();
3200
Dave Houlton34df4cb2016-12-01 16:43:06 -07003201 // Test should generate 2 VU failures
3202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003204
3205 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003206 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3207 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003208
Dave Houlton34df4cb2016-12-01 16:43:06 -07003209 // TODO: Note that this only verifies that at least one of the VU enums was found
3210 // 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 -06003211 m_errorMonitor->VerifyFound();
3212
Tony Barbour552f6c02016-12-21 14:34:07 -07003213 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003214}
3215
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003216TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3217 VkResult err;
3218 bool pass;
3219
3220 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3221 ASSERT_NO_FATAL_FAILURE(InitState());
3222
3223 // If w/d/h granularity is 1, test is not meaningful
3224 // TODO: When virtual device limits are available, create a set of limits for this test that
3225 // will always have a granularity of > 1 for w, h, and d
3226 auto index = m_device->graphics_queue_node_index_;
3227 auto queue_family_properties = m_device->phy().queue_properties();
3228
3229 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3230 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3231 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3232 return;
3233 }
3234
3235 // Create two images of different types and try to copy between them
3236 VkImage srcImage;
3237 VkImage dstImage;
3238 VkDeviceMemory srcMem;
3239 VkDeviceMemory destMem;
3240 VkMemoryRequirements memReqs;
3241
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003242 VkImageCreateInfo image_create_info = {};
3243 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3244 image_create_info.pNext = NULL;
3245 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3246 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3247 image_create_info.extent.width = 32;
3248 image_create_info.extent.height = 32;
3249 image_create_info.extent.depth = 1;
3250 image_create_info.mipLevels = 1;
3251 image_create_info.arrayLayers = 4;
3252 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3253 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3254 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3255 image_create_info.flags = 0;
3256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003258 ASSERT_VK_SUCCESS(err);
3259
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003260 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003261 ASSERT_VK_SUCCESS(err);
3262
3263 // Allocate memory
3264 VkMemoryAllocateInfo memAlloc = {};
3265 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3266 memAlloc.pNext = NULL;
3267 memAlloc.allocationSize = 0;
3268 memAlloc.memoryTypeIndex = 0;
3269
3270 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3271 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003272 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003273 ASSERT_TRUE(pass);
3274 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3275 ASSERT_VK_SUCCESS(err);
3276
3277 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3278 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003280 ASSERT_VK_SUCCESS(err);
3281 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3282 ASSERT_VK_SUCCESS(err);
3283
3284 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3285 ASSERT_VK_SUCCESS(err);
3286 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3287 ASSERT_VK_SUCCESS(err);
3288
Tony Barbour552f6c02016-12-21 14:34:07 -07003289 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003290 VkImageCopy copyRegion;
3291 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3292 copyRegion.srcSubresource.mipLevel = 0;
3293 copyRegion.srcSubresource.baseArrayLayer = 0;
3294 copyRegion.srcSubresource.layerCount = 1;
3295 copyRegion.srcOffset.x = 0;
3296 copyRegion.srcOffset.y = 0;
3297 copyRegion.srcOffset.z = 0;
3298 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3299 copyRegion.dstSubresource.mipLevel = 0;
3300 copyRegion.dstSubresource.baseArrayLayer = 0;
3301 copyRegion.dstSubresource.layerCount = 1;
3302 copyRegion.dstOffset.x = 0;
3303 copyRegion.dstOffset.y = 0;
3304 copyRegion.dstOffset.z = 0;
3305 copyRegion.extent.width = 1;
3306 copyRegion.extent.height = 1;
3307 copyRegion.extent.depth = 1;
3308
3309 // Introduce failure by setting srcOffset to a bad granularity value
3310 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3312 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003313 m_errorMonitor->VerifyFound();
3314
3315 // Introduce failure by setting extent to a bad granularity value
3316 copyRegion.srcOffset.y = 0;
3317 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3319 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003320 m_errorMonitor->VerifyFound();
3321
3322 // Now do some buffer/image copies
3323 vk_testing::Buffer buffer;
3324 VkMemoryPropertyFlags reqs = 0;
3325 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3326 VkBufferImageCopy region = {};
3327 region.bufferOffset = 0;
3328 region.bufferRowLength = 3;
3329 region.bufferImageHeight = 128;
3330 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3331 region.imageSubresource.layerCount = 1;
3332 region.imageExtent.height = 16;
3333 region.imageExtent.width = 16;
3334 region.imageExtent.depth = 1;
3335 region.imageOffset.x = 0;
3336 region.imageOffset.y = 0;
3337 region.imageOffset.z = 0;
3338
3339 // Introduce failure by setting bufferRowLength to a bad granularity value
3340 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3342 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3343 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003344 m_errorMonitor->VerifyFound();
3345 region.bufferRowLength = 128;
3346
3347 // Introduce failure by setting bufferOffset to a bad granularity value
3348 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3350 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3351 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003352 m_errorMonitor->VerifyFound();
3353 region.bufferOffset = 0;
3354
3355 // Introduce failure by setting bufferImageHeight to a bad granularity value
3356 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3358 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3359 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003360 m_errorMonitor->VerifyFound();
3361 region.bufferImageHeight = 128;
3362
3363 // Introduce failure by setting imageExtent to a bad granularity value
3364 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3366 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3367 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003368 m_errorMonitor->VerifyFound();
3369 region.imageExtent.width = 16;
3370
3371 // Introduce failure by setting imageOffset to a bad granularity value
3372 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3374 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3375 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003376 m_errorMonitor->VerifyFound();
3377
Tony Barbour552f6c02016-12-21 14:34:07 -07003378 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003379
3380 vkDestroyImage(m_device->device(), srcImage, NULL);
3381 vkDestroyImage(m_device->device(), dstImage, NULL);
3382 vkFreeMemory(m_device->device(), srcMem, NULL);
3383 vkFreeMemory(m_device->device(), destMem, NULL);
3384}
3385
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003386TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003387 TEST_DESCRIPTION(
3388 "Submit command buffer created using one queue family and "
3389 "attempt to submit them on a queue created in a different "
3390 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003391
Cody Northropc31a84f2016-08-22 10:41:47 -06003392 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003393
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003394 // This test is meaningless unless we have multiple queue families
3395 auto queue_family_properties = m_device->phy().queue_properties();
3396 if (queue_family_properties.size() < 2) {
3397 return;
3398 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003400 // Get safe index of another queue family
3401 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3402 ASSERT_NO_FATAL_FAILURE(InitState());
3403 // Create a second queue using a different queue family
3404 VkQueue other_queue;
3405 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3406
3407 // Record an empty cmd buffer
3408 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3409 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3410 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3411 vkEndCommandBuffer(m_commandBuffer->handle());
3412
3413 // And submit on the wrong queue
3414 VkSubmitInfo submit_info = {};
3415 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3416 submit_info.commandBufferCount = 1;
3417 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003418 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003419
3420 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003421}
3422
Chris Forbes4c24a922016-11-16 08:59:10 +13003423TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3424 ASSERT_NO_FATAL_FAILURE(InitState());
3425
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003426 // There are no attachments, but refer to attachment 0.
3427 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003428 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003429 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003430 };
3431
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003432 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003433 VkRenderPass rp;
3434
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003435 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003437 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3438 m_errorMonitor->VerifyFound();
3439}
3440
Chris Forbesa58c4522016-09-28 15:19:39 +13003441TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3442 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3443 ASSERT_NO_FATAL_FAILURE(InitState());
3444
3445 // A renderpass with two subpasses, both writing the same attachment.
3446 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003447 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3448 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3449 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003450 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003451 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003452 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003453 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3454 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003455 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003456 VkSubpassDependency dep = {0,
3457 1,
3458 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3459 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3460 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3461 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3462 VK_DEPENDENCY_BY_REGION_BIT};
3463 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003464 VkRenderPass rp;
3465 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3466 ASSERT_VK_SUCCESS(err);
3467
3468 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003469 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 +13003470 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3471
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003472 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003473 VkFramebuffer fb;
3474 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3475 ASSERT_VK_SUCCESS(err);
3476
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003477 char const *vsSource =
3478 "#version 450\n"
3479 "void main() { gl_Position = vec4(1); }\n";
3480 char const *fsSource =
3481 "#version 450\n"
3482 "layout(location=0) out vec4 color;\n"
3483 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003484
3485 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3486 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3487 VkPipelineObj pipe(m_device);
3488 pipe.AddColorAttachment();
3489 pipe.AddShader(&vs);
3490 pipe.AddShader(&fs);
3491 VkViewport view_port = {};
3492 m_viewports.push_back(view_port);
3493 pipe.SetViewport(m_viewports);
3494 VkRect2D rect = {};
3495 m_scissors.push_back(rect);
3496 pipe.SetScissor(m_scissors);
3497
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003498 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003499 VkPipelineLayout pl;
3500 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3501 ASSERT_VK_SUCCESS(err);
3502 pipe.CreateVKPipeline(pl, rp);
3503
Tony Barbour552f6c02016-12-21 14:34:07 -07003504 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003505
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003506 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3507 nullptr,
3508 rp,
3509 fb,
3510 {{
3511 0, 0,
3512 },
3513 {32, 32}},
3514 0,
3515 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003516
3517 // subtest 1: bind in the wrong subpass
3518 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3519 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003520 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 +13003521 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3522 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3523 m_errorMonitor->VerifyFound();
3524
3525 vkCmdEndRenderPass(m_commandBuffer->handle());
3526
3527 // subtest 2: bind in correct subpass, then transition to next subpass
3528 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3529 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3530 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003531 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 +13003532 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3533 m_errorMonitor->VerifyFound();
3534
3535 vkCmdEndRenderPass(m_commandBuffer->handle());
3536
Tony Barbour552f6c02016-12-21 14:34:07 -07003537 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003538
3539 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3540 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3541 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3542}
3543
Tony Barbour4e919972016-08-09 13:27:40 -06003544TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003545 TEST_DESCRIPTION(
3546 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3547 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003548 ASSERT_NO_FATAL_FAILURE(InitState());
3549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3550
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3552 "Cannot execute a render pass with renderArea "
3553 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003554
3555 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3556 m_renderPassBeginInfo.renderArea.extent.width = 257;
3557 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003558 m_commandBuffer->BeginCommandBuffer();
3559 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003560 m_errorMonitor->VerifyFound();
3561}
3562
3563TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003564 TEST_DESCRIPTION(
3565 "Generate INDEPENDENT_BLEND by disabling independent "
3566 "blend and then specifying different blend states for two "
3567 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003568 VkPhysicalDeviceFeatures features = {};
3569 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003570 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003571
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3573 "Invalid Pipeline CreateInfo: If independent blend feature not "
3574 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003575
Cody Northropc31a84f2016-08-22 10:41:47 -06003576 VkDescriptorSetObj descriptorSet(m_device);
3577 descriptorSet.AppendDummy();
3578 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003579
Cody Northropc31a84f2016-08-22 10:41:47 -06003580 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003581 // Create a renderPass with two color attachments
3582 VkAttachmentReference attachments[2] = {};
3583 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3584 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3585
3586 VkSubpassDescription subpass = {};
3587 subpass.pColorAttachments = attachments;
3588 subpass.colorAttachmentCount = 2;
3589
3590 VkRenderPassCreateInfo rpci = {};
3591 rpci.subpassCount = 1;
3592 rpci.pSubpasses = &subpass;
3593 rpci.attachmentCount = 1;
3594
3595 VkAttachmentDescription attach_desc = {};
3596 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3597 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3598 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3599 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3600
3601 rpci.pAttachments = &attach_desc;
3602 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3603
3604 VkRenderPass renderpass;
3605 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003606 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003607 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003608
Cody Northropc31a84f2016-08-22 10:41:47 -06003609 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3610 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3611 att_state1.blendEnable = VK_TRUE;
3612 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3613 att_state2.blendEnable = VK_FALSE;
3614 pipeline.AddColorAttachment(0, &att_state1);
3615 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003616 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003617 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003618 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003619}
3620
Mike Weiblen40b160e2017-02-06 19:21:52 -07003621// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3622TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3623 TEST_DESCRIPTION(
3624 "Create a graphics pipeline that is incompatible with the requirements "
3625 "of its contained Renderpass/subpasses.");
3626 ASSERT_NO_FATAL_FAILURE(InitState());
3627
3628 VkDescriptorSetObj ds_obj(m_device);
3629 ds_obj.AppendDummy();
3630 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3631
3632 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3633
3634 VkPipelineColorBlendAttachmentState att_state1 = {};
3635 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3636 att_state1.blendEnable = VK_TRUE;
3637
3638 VkRenderpassObj rp_obj(m_device);
3639
3640 {
3641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3642 VkPipelineObj pipeline(m_device);
3643 pipeline.AddShader(&vs_obj);
3644 pipeline.AddColorAttachment(0, &att_state1);
3645
3646 VkGraphicsPipelineCreateInfo info = {};
3647 pipeline.InitGraphicsPipelineCreateInfo(&info);
3648 info.pColorBlendState = nullptr;
3649
3650 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3651 m_errorMonitor->VerifyFound();
3652 }
3653}
3654
Chris Forbes26ec2122016-11-29 08:58:33 +13003655#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003656TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3657 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3658 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003659 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003660
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3662 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003663
3664 // Create a renderPass with a single color attachment
3665 VkAttachmentReference attach = {};
3666 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3667 VkSubpassDescription subpass = {};
3668 VkRenderPassCreateInfo rpci = {};
3669 rpci.subpassCount = 1;
3670 rpci.pSubpasses = &subpass;
3671 rpci.attachmentCount = 1;
3672 VkAttachmentDescription attach_desc = {};
3673 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3674 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3675 rpci.pAttachments = &attach_desc;
3676 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3677 VkRenderPass rp;
3678 subpass.pDepthStencilAttachment = &attach;
3679 subpass.pColorAttachments = NULL;
3680 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3681 m_errorMonitor->VerifyFound();
3682}
Chris Forbes26ec2122016-11-29 08:58:33 +13003683#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003684
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003685TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003686 TEST_DESCRIPTION(
3687 "Create a framebuffer where a subpass has a preserve "
3688 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003689
3690 ASSERT_NO_FATAL_FAILURE(InitState());
3691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003694
3695 VkAttachmentReference color_attach = {};
3696 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3697 color_attach.attachment = 0;
3698 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3699 VkSubpassDescription subpass = {};
3700 subpass.colorAttachmentCount = 1;
3701 subpass.pColorAttachments = &color_attach;
3702 subpass.preserveAttachmentCount = 1;
3703 subpass.pPreserveAttachments = &preserve_attachment;
3704
3705 VkRenderPassCreateInfo rpci = {};
3706 rpci.subpassCount = 1;
3707 rpci.pSubpasses = &subpass;
3708 rpci.attachmentCount = 1;
3709 VkAttachmentDescription attach_desc = {};
3710 attach_desc.format = VK_FORMAT_UNDEFINED;
3711 rpci.pAttachments = &attach_desc;
3712 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3713 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003714 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003715
3716 m_errorMonitor->VerifyFound();
3717
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003718 if (result == VK_SUCCESS) {
3719 vkDestroyRenderPass(m_device->device(), rp, NULL);
3720 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003721}
3722
Chris Forbesc5389742016-06-29 11:49:23 +12003723TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003724 TEST_DESCRIPTION(
3725 "Ensure that CreateRenderPass produces a validation error "
3726 "when the source of a subpass multisample resolve "
3727 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003728
Chris Forbesc5389742016-06-29 11:49:23 +12003729 ASSERT_NO_FATAL_FAILURE(InitState());
3730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3732 "Subpass 0 requests multisample resolve from attachment 0 which has "
3733 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003734
3735 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003736 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3737 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3738 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3739 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3740 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3741 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003742 };
3743
3744 VkAttachmentReference color = {
3745 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3746 };
3747
3748 VkAttachmentReference resolve = {
3749 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3750 };
3751
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003752 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003753
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003754 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003755
3756 VkRenderPass rp;
3757 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3758
3759 m_errorMonitor->VerifyFound();
3760
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003761 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003762}
3763
3764TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003765 TEST_DESCRIPTION(
3766 "Ensure CreateRenderPass produces a validation error "
3767 "when a subpass multisample resolve operation is "
3768 "requested, and the destination of that resolve has "
3769 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003770
Chris Forbesc5389742016-06-29 11:49:23 +12003771 ASSERT_NO_FATAL_FAILURE(InitState());
3772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3774 "Subpass 0 requests multisample resolve into attachment 1, which "
3775 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003776
3777 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003778 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3779 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3780 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3781 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3782 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3783 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003784 };
3785
3786 VkAttachmentReference color = {
3787 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3788 };
3789
3790 VkAttachmentReference resolve = {
3791 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3792 };
3793
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003794 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003796 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003797
3798 VkRenderPass rp;
3799 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3800
3801 m_errorMonitor->VerifyFound();
3802
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003803 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003804}
3805
Chris Forbes3f128ef2016-06-29 14:58:53 +12003806TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003807 TEST_DESCRIPTION(
3808 "Ensure CreateRenderPass produces a validation error "
3809 "when the color and depth attachments used by a subpass "
3810 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003811
Chris Forbes3f128ef2016-06-29 14:58:53 +12003812 ASSERT_NO_FATAL_FAILURE(InitState());
3813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3815 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003816
3817 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003818 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3819 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3820 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3821 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3822 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3823 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003824 };
3825
3826 VkAttachmentReference color[] = {
3827 {
3828 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3829 },
3830 {
3831 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3832 },
3833 };
3834
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003835 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003836
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003837 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003838
3839 VkRenderPass rp;
3840 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3841
3842 m_errorMonitor->VerifyFound();
3843
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003844 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003845}
3846
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003847TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003848 TEST_DESCRIPTION(
3849 "Hit errors when attempting to create a framebuffer :\n"
3850 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3851 " 2. Use a color image as depthStencil attachment\n"
3852 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3853 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3854 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3855 " 6. Framebuffer attachment where dimensions don't match\n"
3856 " 7. Framebuffer attachment w/o identity swizzle\n"
3857 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003858
3859 ASSERT_NO_FATAL_FAILURE(InitState());
3860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3861
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003862 m_errorMonitor->SetDesiredFailureMsg(
3863 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3864 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003865
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003866 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003867 VkAttachmentReference attach = {};
3868 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3869 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003870 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003871 VkRenderPassCreateInfo rpci = {};
3872 rpci.subpassCount = 1;
3873 rpci.pSubpasses = &subpass;
3874 rpci.attachmentCount = 1;
3875 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003876 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003877 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003878 rpci.pAttachments = &attach_desc;
3879 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3880 VkRenderPass rp;
3881 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3882 ASSERT_VK_SUCCESS(err);
3883
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003884 VkImageView ivs[2];
3885 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3886 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003887 VkFramebufferCreateInfo fb_info = {};
3888 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3889 fb_info.pNext = NULL;
3890 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003891 // Set mis-matching attachmentCount
3892 fb_info.attachmentCount = 2;
3893 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003894 fb_info.width = 100;
3895 fb_info.height = 100;
3896 fb_info.layers = 1;
3897
3898 VkFramebuffer fb;
3899 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3900
3901 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003902 if (err == VK_SUCCESS) {
3903 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3904 }
3905 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003906
3907 // Create a renderPass with a depth-stencil attachment created with
3908 // IMAGE_USAGE_COLOR_ATTACHMENT
3909 // Add our color attachment to pDepthStencilAttachment
3910 subpass.pDepthStencilAttachment = &attach;
3911 subpass.pColorAttachments = NULL;
3912 VkRenderPass rp_ds;
3913 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3914 ASSERT_VK_SUCCESS(err);
3915 // Set correct attachment count, but attachment has COLOR usage bit set
3916 fb_info.attachmentCount = 1;
3917 fb_info.renderPass = rp_ds;
3918
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003920 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3921
3922 m_errorMonitor->VerifyFound();
3923 if (err == VK_SUCCESS) {
3924 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3925 }
3926 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003927
3928 // Create new renderpass with alternate attachment format from fb
3929 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3930 subpass.pDepthStencilAttachment = NULL;
3931 subpass.pColorAttachments = &attach;
3932 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3933 ASSERT_VK_SUCCESS(err);
3934
3935 // Cause error due to mis-matched formats between rp & fb
3936 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3937 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3939 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003940 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3941
3942 m_errorMonitor->VerifyFound();
3943 if (err == VK_SUCCESS) {
3944 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3945 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003946 vkDestroyRenderPass(m_device->device(), rp, NULL);
3947
3948 // Create new renderpass with alternate sample count from fb
3949 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3950 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3951 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3952 ASSERT_VK_SUCCESS(err);
3953
3954 // Cause error due to mis-matched sample count between rp & fb
3955 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003957 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003958 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3959
3960 m_errorMonitor->VerifyFound();
3961 if (err == VK_SUCCESS) {
3962 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3963 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003964
3965 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003966
3967 // Create a custom imageView with non-1 mip levels
3968 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003969 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 -06003970 ASSERT_TRUE(image.initialized());
3971
3972 VkImageView view;
3973 VkImageViewCreateInfo ivci = {};
3974 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3975 ivci.image = image.handle();
3976 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3977 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3978 ivci.subresourceRange.layerCount = 1;
3979 ivci.subresourceRange.baseMipLevel = 0;
3980 // Set level count 2 (only 1 is allowed for FB attachment)
3981 ivci.subresourceRange.levelCount = 2;
3982 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3983 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3984 ASSERT_VK_SUCCESS(err);
3985 // Re-create renderpass to have matching sample count
3986 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3987 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3988 ASSERT_VK_SUCCESS(err);
3989
3990 fb_info.renderPass = rp;
3991 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003993 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3994
3995 m_errorMonitor->VerifyFound();
3996 if (err == VK_SUCCESS) {
3997 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3998 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003999 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004000 // Update view to original color buffer and grow FB dimensions too big
4001 fb_info.pAttachments = ivs;
4002 fb_info.height = 1024;
4003 fb_info.width = 1024;
4004 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004006 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4007
4008 m_errorMonitor->VerifyFound();
4009 if (err == VK_SUCCESS) {
4010 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4011 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004012 // Create view attachment with non-identity swizzle
4013 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4014 ivci.image = image.handle();
4015 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4016 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4017 ivci.subresourceRange.layerCount = 1;
4018 ivci.subresourceRange.baseMipLevel = 0;
4019 ivci.subresourceRange.levelCount = 1;
4020 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4021 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4022 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4023 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4024 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4025 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4026 ASSERT_VK_SUCCESS(err);
4027
4028 fb_info.pAttachments = &view;
4029 fb_info.height = 100;
4030 fb_info.width = 100;
4031 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004032 m_errorMonitor->SetDesiredFailureMsg(
4033 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4034 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004035 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4036
4037 m_errorMonitor->VerifyFound();
4038 if (err == VK_SUCCESS) {
4039 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4040 }
4041 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004042 // reset attachment to color attachment
4043 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004044
4045 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004046 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004047 fb_info.height = 100;
4048 fb_info.layers = 1;
4049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004050 m_errorMonitor->SetDesiredFailureMsg(
4051 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004052 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4053 "Here are the respective dimensions for attachment");
4054
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004055 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4056
4057 m_errorMonitor->VerifyFound();
4058 if (err == VK_SUCCESS) {
4059 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4060 }
4061
4062 // Request fb that exceeds max height
4063 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004064 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004065 fb_info.layers = 1;
4066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004067 m_errorMonitor->SetDesiredFailureMsg(
4068 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004069 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4070 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004071 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4072
4073 m_errorMonitor->VerifyFound();
4074 if (err == VK_SUCCESS) {
4075 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4076 }
4077
4078 // Request fb that exceeds max layers
4079 fb_info.width = 100;
4080 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004081 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004083 m_errorMonitor->SetDesiredFailureMsg(
4084 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004085 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4086 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004087 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4088
4089 m_errorMonitor->VerifyFound();
4090 if (err == VK_SUCCESS) {
4091 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4092 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004093
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004094 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004095}
4096
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004097TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004098 TEST_DESCRIPTION(
4099 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4100 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004101
Cody Northropc31a84f2016-08-22 10:41:47 -06004102 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004103 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4105 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004106 m_errorMonitor->VerifyFound();
4107}
4108
4109TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004110 TEST_DESCRIPTION(
4111 "Run a simple draw calls to validate failure when Line Width dynamic "
4112 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004113
Cody Northropc31a84f2016-08-22 10:41:47 -06004114 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004115 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4117 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004118 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004119}
4120
4121TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004122 TEST_DESCRIPTION(
4123 "Run a simple draw calls to validate failure when Viewport dynamic "
4124 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004125
Cody Northropc31a84f2016-08-22 10:41:47 -06004126 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004127 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4129 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004131 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004132}
4133
4134TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004135 TEST_DESCRIPTION(
4136 "Run a simple draw calls to validate failure when Scissor dynamic "
4137 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004138
Cody Northropc31a84f2016-08-22 10:41:47 -06004139 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004140 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4142 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004143 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004144 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004145}
4146
Cortd713fe82016-07-27 09:51:27 -07004147TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004148 TEST_DESCRIPTION(
4149 "Run a simple draw calls to validate failure when Blend Constants "
4150 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004151
4152 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004153 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4155 "Dynamic blend constants state not set for this command buffer");
4156 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004157 m_errorMonitor->VerifyFound();
4158}
4159
4160TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004161 TEST_DESCRIPTION(
4162 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4163 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004164
4165 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004166 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004167 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004168 return;
4169 }
4170 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4172 "Dynamic depth bounds state not set for this command buffer");
4173 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004174 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004175}
4176
4177TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004178 TEST_DESCRIPTION(
4179 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4180 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004181
4182 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004183 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4185 "Dynamic stencil read mask state not set for this command buffer");
4186 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004187 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004188}
4189
4190TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004191 TEST_DESCRIPTION(
4192 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4193 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004194
4195 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004196 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4198 "Dynamic stencil write mask state not set for this command buffer");
4199 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004200 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004201}
4202
4203TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004204 TEST_DESCRIPTION(
4205 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4206 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004207
4208 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004209 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4211 "Dynamic stencil reference state not set for this command buffer");
4212 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004213 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004214}
4215
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004216TEST_F(VkLayerTest, IndexBufferNotBound) {
4217 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004218
4219 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4221 "Index buffer object not bound to this command buffer when Indexed ");
4222 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004223 m_errorMonitor->VerifyFound();
4224}
4225
Karl Schultz6addd812016-02-02 17:17:23 -07004226TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4228 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4229 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004230
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004231 ASSERT_NO_FATAL_FAILURE(InitState());
4232 ASSERT_NO_FATAL_FAILURE(InitViewport());
4233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4234
Karl Schultz6addd812016-02-02 17:17:23 -07004235 // We luck out b/c by default the framework creates CB w/ the
4236 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004237 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004238 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004239 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004240
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004241 // Bypass framework since it does the waits automatically
4242 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004243 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004244 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4245 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004246 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004247 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004248 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004249 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004250 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004251 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004252 submit_info.pSignalSemaphores = NULL;
4253
Chris Forbes40028e22016-06-13 09:59:34 +12004254 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004255 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004256 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004257
Karl Schultz6addd812016-02-02 17:17:23 -07004258 // Cause validation error by re-submitting cmd buffer that should only be
4259 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004260 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004261 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004262
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004263 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004264}
4265
Karl Schultz6addd812016-02-02 17:17:23 -07004266TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004267 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004268 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004269
4270 ASSERT_NO_FATAL_FAILURE(InitState());
4271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004272
Karl Schultz6addd812016-02-02 17:17:23 -07004273 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4274 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004275 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004276 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004277 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004278
4279 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004280 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4281 ds_pool_ci.pNext = NULL;
4282 ds_pool_ci.flags = 0;
4283 ds_pool_ci.maxSets = 1;
4284 ds_pool_ci.poolSizeCount = 1;
4285 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004286
4287 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004288 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004289 ASSERT_VK_SUCCESS(err);
4290
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004291 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4292 dsl_binding_samp.binding = 0;
4293 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4294 dsl_binding_samp.descriptorCount = 1;
4295 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4296 dsl_binding_samp.pImmutableSamplers = NULL;
4297
4298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4300 ds_layout_ci.pNext = NULL;
4301 ds_layout_ci.bindingCount = 1;
4302 ds_layout_ci.pBindings = &dsl_binding_samp;
4303
4304 VkDescriptorSetLayout ds_layout_samp;
4305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4306 ASSERT_VK_SUCCESS(err);
4307
4308 // Try to allocate 2 sets when pool only has 1 set
4309 VkDescriptorSet descriptor_sets[2];
4310 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4311 VkDescriptorSetAllocateInfo alloc_info = {};
4312 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4313 alloc_info.descriptorSetCount = 2;
4314 alloc_info.descriptorPool = ds_pool;
4315 alloc_info.pSetLayouts = set_layouts;
4316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4317 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4318 m_errorMonitor->VerifyFound();
4319
4320 alloc_info.descriptorSetCount = 1;
4321 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004322 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004323 dsl_binding.binding = 0;
4324 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4325 dsl_binding.descriptorCount = 1;
4326 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4327 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004328
Karl Schultz6addd812016-02-02 17:17:23 -07004329 ds_layout_ci.bindingCount = 1;
4330 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004331
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004332 VkDescriptorSetLayout ds_layout_ub;
4333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004334 ASSERT_VK_SUCCESS(err);
4335
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004336 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004337 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004338 alloc_info.pSetLayouts = &ds_layout_ub;
4339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4340 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004341
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004342 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004343
Karl Schultz2825ab92016-12-02 08:23:14 -07004344 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004345 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004346 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004347}
4348
Karl Schultz6addd812016-02-02 17:17:23 -07004349TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4350 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004351
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004353
Tobin Ehlise735c692015-10-08 13:13:50 -06004354 ASSERT_NO_FATAL_FAILURE(InitState());
4355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004356
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004357 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004358 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4359 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004360
4361 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004362 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4363 ds_pool_ci.pNext = NULL;
4364 ds_pool_ci.maxSets = 1;
4365 ds_pool_ci.poolSizeCount = 1;
4366 ds_pool_ci.flags = 0;
4367 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4368 // app can only call vkResetDescriptorPool on this pool.;
4369 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004370
4371 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004372 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004373 ASSERT_VK_SUCCESS(err);
4374
4375 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004376 dsl_binding.binding = 0;
4377 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4378 dsl_binding.descriptorCount = 1;
4379 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4380 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004381
4382 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004383 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4384 ds_layout_ci.pNext = NULL;
4385 ds_layout_ci.bindingCount = 1;
4386 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004387
4388 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004389 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004390 ASSERT_VK_SUCCESS(err);
4391
4392 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004393 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004394 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004395 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004396 alloc_info.descriptorPool = ds_pool;
4397 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004398 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004399 ASSERT_VK_SUCCESS(err);
4400
4401 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004402 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004403
Chia-I Wuf7458c52015-10-26 21:10:41 +08004404 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4405 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004406}
4407
Karl Schultz6addd812016-02-02 17:17:23 -07004408TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004409 // Attempt to clear Descriptor Pool with bad object.
4410 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004411
4412 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004414 uint64_t fake_pool_handle = 0xbaad6001;
4415 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4416 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004417 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004418}
4419
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004420TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004421 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4422 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004423 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004424 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004425
4426 uint64_t fake_set_handle = 0xbaad6001;
4427 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004428 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004430
4431 ASSERT_NO_FATAL_FAILURE(InitState());
4432
4433 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4434 layout_bindings[0].binding = 0;
4435 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4436 layout_bindings[0].descriptorCount = 1;
4437 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4438 layout_bindings[0].pImmutableSamplers = NULL;
4439
4440 VkDescriptorSetLayout descriptor_set_layout;
4441 VkDescriptorSetLayoutCreateInfo dslci = {};
4442 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4443 dslci.pNext = NULL;
4444 dslci.bindingCount = 1;
4445 dslci.pBindings = layout_bindings;
4446 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004447 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004448
4449 VkPipelineLayout pipeline_layout;
4450 VkPipelineLayoutCreateInfo plci = {};
4451 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4452 plci.pNext = NULL;
4453 plci.setLayoutCount = 1;
4454 plci.pSetLayouts = &descriptor_set_layout;
4455 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004456 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004457
Tony Barbour552f6c02016-12-21 14:34:07 -07004458 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004459 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4460 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004461 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004462 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004463 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4464 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004465}
4466
Karl Schultz6addd812016-02-02 17:17:23 -07004467TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004468 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4469 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004470 uint64_t fake_layout_handle = 0xbaad6001;
4471 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004473 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004474 VkPipelineLayout pipeline_layout;
4475 VkPipelineLayoutCreateInfo plci = {};
4476 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4477 plci.pNext = NULL;
4478 plci.setLayoutCount = 1;
4479 plci.pSetLayouts = &bad_layout;
4480 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4481
4482 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004483}
4484
Mark Muellerd4914412016-06-13 17:52:06 -06004485TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004486 TEST_DESCRIPTION(
4487 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4488 "1) A uniform buffer update must have a valid buffer index."
4489 "2) When using an array of descriptors in a single WriteDescriptor,"
4490 " the descriptor types and stageflags must all be the same."
4491 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004492
Mike Weiblena6666382017-01-05 15:16:11 -07004493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004494
4495 ASSERT_NO_FATAL_FAILURE(InitState());
4496 VkDescriptorPoolSize ds_type_count[4] = {};
4497 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4498 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004499 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004500 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004501 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004502 ds_type_count[2].descriptorCount = 1;
4503 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4504 ds_type_count[3].descriptorCount = 1;
4505
4506 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4507 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4508 ds_pool_ci.maxSets = 1;
4509 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4510 ds_pool_ci.pPoolSizes = ds_type_count;
4511
4512 VkDescriptorPool ds_pool;
4513 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4514 ASSERT_VK_SUCCESS(err);
4515
Mark Muellerb9896722016-06-16 09:54:29 -06004516 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004517 layout_binding[0].binding = 0;
4518 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4519 layout_binding[0].descriptorCount = 1;
4520 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4521 layout_binding[0].pImmutableSamplers = NULL;
4522
4523 layout_binding[1].binding = 1;
4524 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4525 layout_binding[1].descriptorCount = 1;
4526 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4527 layout_binding[1].pImmutableSamplers = NULL;
4528
4529 VkSamplerCreateInfo sampler_ci = {};
4530 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4531 sampler_ci.pNext = NULL;
4532 sampler_ci.magFilter = VK_FILTER_NEAREST;
4533 sampler_ci.minFilter = VK_FILTER_NEAREST;
4534 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4535 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4536 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4537 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4538 sampler_ci.mipLodBias = 1.0;
4539 sampler_ci.anisotropyEnable = VK_FALSE;
4540 sampler_ci.maxAnisotropy = 1;
4541 sampler_ci.compareEnable = VK_FALSE;
4542 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4543 sampler_ci.minLod = 1.0;
4544 sampler_ci.maxLod = 1.0;
4545 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4546 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4547 VkSampler sampler;
4548
4549 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4550 ASSERT_VK_SUCCESS(err);
4551
4552 layout_binding[2].binding = 2;
4553 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4554 layout_binding[2].descriptorCount = 1;
4555 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4556 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4557
Mark Muellerd4914412016-06-13 17:52:06 -06004558 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4559 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4560 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4561 ds_layout_ci.pBindings = layout_binding;
4562 VkDescriptorSetLayout ds_layout;
4563 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4564 ASSERT_VK_SUCCESS(err);
4565
4566 VkDescriptorSetAllocateInfo alloc_info = {};
4567 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4568 alloc_info.descriptorSetCount = 1;
4569 alloc_info.descriptorPool = ds_pool;
4570 alloc_info.pSetLayouts = &ds_layout;
4571 VkDescriptorSet descriptorSet;
4572 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4573 ASSERT_VK_SUCCESS(err);
4574
4575 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4576 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4577 pipeline_layout_ci.pNext = NULL;
4578 pipeline_layout_ci.setLayoutCount = 1;
4579 pipeline_layout_ci.pSetLayouts = &ds_layout;
4580
4581 VkPipelineLayout pipeline_layout;
4582 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4583 ASSERT_VK_SUCCESS(err);
4584
Mark Mueller5c838ce2016-06-16 09:54:29 -06004585 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004586 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4587 descriptor_write.dstSet = descriptorSet;
4588 descriptor_write.dstBinding = 0;
4589 descriptor_write.descriptorCount = 1;
4590 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4591
Mark Mueller5c838ce2016-06-16 09:54:29 -06004592 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004593 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4594 m_errorMonitor->VerifyFound();
4595
4596 // Create a buffer to update the descriptor with
4597 uint32_t qfi = 0;
4598 VkBufferCreateInfo buffCI = {};
4599 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4600 buffCI.size = 1024;
4601 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4602 buffCI.queueFamilyIndexCount = 1;
4603 buffCI.pQueueFamilyIndices = &qfi;
4604
4605 VkBuffer dyub;
4606 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4607 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004608
Tony Barboure132c5f2016-12-12 11:50:20 -07004609 VkDeviceMemory mem;
4610 VkMemoryRequirements mem_reqs;
4611 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4612
4613 VkMemoryAllocateInfo mem_alloc_info = {};
4614 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4615 mem_alloc_info.allocationSize = mem_reqs.size;
4616 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4617 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4618 ASSERT_VK_SUCCESS(err);
4619
4620 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4621 ASSERT_VK_SUCCESS(err);
4622
4623 VkDescriptorBufferInfo buffInfo[2] = {};
4624 buffInfo[0].buffer = dyub;
4625 buffInfo[0].offset = 0;
4626 buffInfo[0].range = 1024;
4627 buffInfo[1].buffer = dyub;
4628 buffInfo[1].offset = 0;
4629 buffInfo[1].range = 1024;
4630 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004631 descriptor_write.descriptorCount = 2;
4632
Mark Mueller5c838ce2016-06-16 09:54:29 -06004633 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004635 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4636 m_errorMonitor->VerifyFound();
4637
Mark Mueller5c838ce2016-06-16 09:54:29 -06004638 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4639 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004640 descriptor_write.dstBinding = 1;
4641 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004642
Mark Mueller5c838ce2016-06-16 09:54:29 -06004643 // Make pImageInfo index non-null to avoid complaints of it missing
4644 VkDescriptorImageInfo imageInfo = {};
4645 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4646 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004648 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4649 m_errorMonitor->VerifyFound();
4650
Mark Muellerd4914412016-06-13 17:52:06 -06004651 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004652 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004653 vkDestroySampler(m_device->device(), sampler, NULL);
4654 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4657}
4658
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004659TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004660 TEST_DESCRIPTION(
4661 "Attempt to draw with a command buffer that is invalid "
4662 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004663 ASSERT_NO_FATAL_FAILURE(InitState());
4664
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004665 VkBuffer buffer;
4666 VkDeviceMemory mem;
4667 VkMemoryRequirements mem_reqs;
4668
4669 VkBufferCreateInfo buf_info = {};
4670 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004671 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004672 buf_info.size = 256;
4673 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4674 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4675 ASSERT_VK_SUCCESS(err);
4676
4677 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4678
4679 VkMemoryAllocateInfo alloc_info = {};
4680 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4681 alloc_info.allocationSize = 256;
4682 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004683 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 -06004684 if (!pass) {
4685 vkDestroyBuffer(m_device->device(), buffer, NULL);
4686 return;
4687 }
4688 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4689 ASSERT_VK_SUCCESS(err);
4690
4691 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4692 ASSERT_VK_SUCCESS(err);
4693
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004694 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004695 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004696 m_commandBuffer->EndCommandBuffer();
4697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004699 // Destroy buffer dependency prior to submit to cause ERROR
4700 vkDestroyBuffer(m_device->device(), buffer, NULL);
4701
4702 VkSubmitInfo submit_info = {};
4703 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4704 submit_info.commandBufferCount = 1;
4705 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4706 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4707
4708 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004709 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004710 vkFreeMemory(m_device->handle(), mem, NULL);
4711}
4712
Tobin Ehlisea413442016-09-28 10:23:59 -06004713TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4714 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4715
4716 ASSERT_NO_FATAL_FAILURE(InitState());
4717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4718
4719 VkDescriptorPoolSize ds_type_count;
4720 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4721 ds_type_count.descriptorCount = 1;
4722
4723 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4724 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4725 ds_pool_ci.maxSets = 1;
4726 ds_pool_ci.poolSizeCount = 1;
4727 ds_pool_ci.pPoolSizes = &ds_type_count;
4728
4729 VkDescriptorPool ds_pool;
4730 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4731 ASSERT_VK_SUCCESS(err);
4732
4733 VkDescriptorSetLayoutBinding layout_binding;
4734 layout_binding.binding = 0;
4735 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4736 layout_binding.descriptorCount = 1;
4737 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4738 layout_binding.pImmutableSamplers = NULL;
4739
4740 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4741 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4742 ds_layout_ci.bindingCount = 1;
4743 ds_layout_ci.pBindings = &layout_binding;
4744 VkDescriptorSetLayout ds_layout;
4745 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4746 ASSERT_VK_SUCCESS(err);
4747
4748 VkDescriptorSetAllocateInfo alloc_info = {};
4749 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4750 alloc_info.descriptorSetCount = 1;
4751 alloc_info.descriptorPool = ds_pool;
4752 alloc_info.pSetLayouts = &ds_layout;
4753 VkDescriptorSet descriptor_set;
4754 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4755 ASSERT_VK_SUCCESS(err);
4756
4757 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4758 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4759 pipeline_layout_ci.pNext = NULL;
4760 pipeline_layout_ci.setLayoutCount = 1;
4761 pipeline_layout_ci.pSetLayouts = &ds_layout;
4762
4763 VkPipelineLayout pipeline_layout;
4764 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4765 ASSERT_VK_SUCCESS(err);
4766
4767 VkBuffer buffer;
4768 uint32_t queue_family_index = 0;
4769 VkBufferCreateInfo buffer_create_info = {};
4770 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4771 buffer_create_info.size = 1024;
4772 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4773 buffer_create_info.queueFamilyIndexCount = 1;
4774 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4775
4776 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4777 ASSERT_VK_SUCCESS(err);
4778
4779 VkMemoryRequirements memory_reqs;
4780 VkDeviceMemory buffer_memory;
4781
4782 VkMemoryAllocateInfo memory_info = {};
4783 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4784 memory_info.allocationSize = 0;
4785 memory_info.memoryTypeIndex = 0;
4786
4787 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4788 memory_info.allocationSize = memory_reqs.size;
4789 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4790 ASSERT_TRUE(pass);
4791
4792 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4793 ASSERT_VK_SUCCESS(err);
4794 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4795 ASSERT_VK_SUCCESS(err);
4796
4797 VkBufferView view;
4798 VkBufferViewCreateInfo bvci = {};
4799 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4800 bvci.buffer = buffer;
4801 bvci.format = VK_FORMAT_R8_UNORM;
4802 bvci.range = VK_WHOLE_SIZE;
4803
4804 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4805 ASSERT_VK_SUCCESS(err);
4806
4807 VkWriteDescriptorSet descriptor_write = {};
4808 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4809 descriptor_write.dstSet = descriptor_set;
4810 descriptor_write.dstBinding = 0;
4811 descriptor_write.descriptorCount = 1;
4812 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4813 descriptor_write.pTexelBufferView = &view;
4814
4815 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4816
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004817 char const *vsSource =
4818 "#version 450\n"
4819 "\n"
4820 "out gl_PerVertex { \n"
4821 " vec4 gl_Position;\n"
4822 "};\n"
4823 "void main(){\n"
4824 " gl_Position = vec4(1);\n"
4825 "}\n";
4826 char const *fsSource =
4827 "#version 450\n"
4828 "\n"
4829 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4830 "layout(location=0) out vec4 x;\n"
4831 "void main(){\n"
4832 " x = imageLoad(s, 0);\n"
4833 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004834 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4836 VkPipelineObj pipe(m_device);
4837 pipe.AddShader(&vs);
4838 pipe.AddShader(&fs);
4839 pipe.AddColorAttachment();
4840 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4841
Tobin Ehlisea413442016-09-28 10:23:59 -06004842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4843
Tony Barbour552f6c02016-12-21 14:34:07 -07004844 m_commandBuffer->BeginCommandBuffer();
4845 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4846
Tobin Ehlisea413442016-09-28 10:23:59 -06004847 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4848 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4849 VkRect2D scissor = {{0, 0}, {16, 16}};
4850 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4851 // Bind pipeline to cmd buffer
4852 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4853 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4854 &descriptor_set, 0, nullptr);
4855 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004856 m_commandBuffer->EndRenderPass();
4857 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004858
4859 // Delete BufferView in order to invalidate cmd buffer
4860 vkDestroyBufferView(m_device->device(), view, NULL);
4861 // Now attempt submit of cmd buffer
4862 VkSubmitInfo submit_info = {};
4863 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4864 submit_info.commandBufferCount = 1;
4865 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4866 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4867 m_errorMonitor->VerifyFound();
4868
4869 // Clean-up
4870 vkDestroyBuffer(m_device->device(), buffer, NULL);
4871 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4872 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4873 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4874 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4875}
4876
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004877TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004878 TEST_DESCRIPTION(
4879 "Attempt to draw with a command buffer that is invalid "
4880 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004881 ASSERT_NO_FATAL_FAILURE(InitState());
4882
4883 VkImage image;
4884 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4885 VkImageCreateInfo image_create_info = {};
4886 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4887 image_create_info.pNext = NULL;
4888 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4889 image_create_info.format = tex_format;
4890 image_create_info.extent.width = 32;
4891 image_create_info.extent.height = 32;
4892 image_create_info.extent.depth = 1;
4893 image_create_info.mipLevels = 1;
4894 image_create_info.arrayLayers = 1;
4895 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4896 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004897 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004898 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004899 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004900 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004901 // Have to bind memory to image before recording cmd in cmd buffer using it
4902 VkMemoryRequirements mem_reqs;
4903 VkDeviceMemory image_mem;
4904 bool pass;
4905 VkMemoryAllocateInfo mem_alloc = {};
4906 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4907 mem_alloc.pNext = NULL;
4908 mem_alloc.memoryTypeIndex = 0;
4909 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4910 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004912 ASSERT_TRUE(pass);
4913 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4914 ASSERT_VK_SUCCESS(err);
4915 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4916 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004917
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004918 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004919 VkClearColorValue ccv;
4920 ccv.float32[0] = 1.0f;
4921 ccv.float32[1] = 1.0f;
4922 ccv.float32[2] = 1.0f;
4923 ccv.float32[3] = 1.0f;
4924 VkImageSubresourceRange isr = {};
4925 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004926 isr.baseArrayLayer = 0;
4927 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004928 isr.layerCount = 1;
4929 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004930 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004931 m_commandBuffer->EndCommandBuffer();
4932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004934 // Destroy image dependency prior to submit to cause ERROR
4935 vkDestroyImage(m_device->device(), image, NULL);
4936
4937 VkSubmitInfo submit_info = {};
4938 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4939 submit_info.commandBufferCount = 1;
4940 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4941 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4942
4943 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004944 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004945}
4946
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004947TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004948 TEST_DESCRIPTION(
4949 "Attempt to draw with a command buffer that is invalid "
4950 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004951 VkFormatProperties format_properties;
4952 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4954 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004955 return;
4956 }
4957
4958 ASSERT_NO_FATAL_FAILURE(InitState());
4959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4960
4961 VkImageCreateInfo image_ci = {};
4962 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4963 image_ci.pNext = NULL;
4964 image_ci.imageType = VK_IMAGE_TYPE_2D;
4965 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4966 image_ci.extent.width = 32;
4967 image_ci.extent.height = 32;
4968 image_ci.extent.depth = 1;
4969 image_ci.mipLevels = 1;
4970 image_ci.arrayLayers = 1;
4971 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4972 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004973 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004974 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4975 image_ci.flags = 0;
4976 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004977 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004978
4979 VkMemoryRequirements memory_reqs;
4980 VkDeviceMemory image_memory;
4981 bool pass;
4982 VkMemoryAllocateInfo memory_info = {};
4983 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4984 memory_info.pNext = NULL;
4985 memory_info.allocationSize = 0;
4986 memory_info.memoryTypeIndex = 0;
4987 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4988 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004989 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004990 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004991 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004992 ASSERT_VK_SUCCESS(err);
4993 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4994 ASSERT_VK_SUCCESS(err);
4995
4996 VkImageViewCreateInfo ivci = {
4997 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4998 nullptr,
4999 0,
5000 image,
5001 VK_IMAGE_VIEW_TYPE_2D,
5002 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005004 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5005 };
5006 VkImageView view;
5007 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5008 ASSERT_VK_SUCCESS(err);
5009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005011 VkFramebuffer fb;
5012 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5013 ASSERT_VK_SUCCESS(err);
5014
5015 // Just use default renderpass with our framebuffer
5016 m_renderPassBeginInfo.framebuffer = fb;
5017 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005018 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005019 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07005020 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5021 m_commandBuffer->EndRenderPass();
5022 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023 // Destroy image attached to framebuffer to invalidate cmd buffer
5024 vkDestroyImage(m_device->device(), image, NULL);
5025 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005027 QueueCommandBuffer(false);
5028 m_errorMonitor->VerifyFound();
5029
5030 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5031 vkDestroyImageView(m_device->device(), view, nullptr);
5032 vkFreeMemory(m_device->device(), image_memory, nullptr);
5033}
5034
Tobin Ehlisb329f992016-10-12 13:20:29 -06005035TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5036 TEST_DESCRIPTION("Delete in-use framebuffer.");
5037 VkFormatProperties format_properties;
5038 VkResult err = VK_SUCCESS;
5039 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5040
5041 ASSERT_NO_FATAL_FAILURE(InitState());
5042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5043
5044 VkImageObj image(m_device);
5045 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5046 ASSERT_TRUE(image.initialized());
5047 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5048
5049 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5050 VkFramebuffer fb;
5051 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5052 ASSERT_VK_SUCCESS(err);
5053
5054 // Just use default renderpass with our framebuffer
5055 m_renderPassBeginInfo.framebuffer = fb;
5056 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005057 m_commandBuffer->BeginCommandBuffer();
5058 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5059 m_commandBuffer->EndRenderPass();
5060 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005061 // Submit cmd buffer to put it in-flight
5062 VkSubmitInfo submit_info = {};
5063 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5064 submit_info.commandBufferCount = 1;
5065 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5066 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5067 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005069 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5070 m_errorMonitor->VerifyFound();
5071 // Wait for queue to complete so we can safely destroy everything
5072 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005073 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5074 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005075 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5076}
5077
Tobin Ehlis88becd72016-09-21 14:33:41 -06005078TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5079 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5080 VkFormatProperties format_properties;
5081 VkResult err = VK_SUCCESS;
5082 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005083
5084 ASSERT_NO_FATAL_FAILURE(InitState());
5085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5086
5087 VkImageCreateInfo image_ci = {};
5088 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5089 image_ci.pNext = NULL;
5090 image_ci.imageType = VK_IMAGE_TYPE_2D;
5091 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5092 image_ci.extent.width = 256;
5093 image_ci.extent.height = 256;
5094 image_ci.extent.depth = 1;
5095 image_ci.mipLevels = 1;
5096 image_ci.arrayLayers = 1;
5097 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5098 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005099 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005100 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5101 image_ci.flags = 0;
5102 VkImage image;
5103 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5104
5105 VkMemoryRequirements memory_reqs;
5106 VkDeviceMemory image_memory;
5107 bool pass;
5108 VkMemoryAllocateInfo memory_info = {};
5109 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5110 memory_info.pNext = NULL;
5111 memory_info.allocationSize = 0;
5112 memory_info.memoryTypeIndex = 0;
5113 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5114 memory_info.allocationSize = memory_reqs.size;
5115 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5116 ASSERT_TRUE(pass);
5117 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5118 ASSERT_VK_SUCCESS(err);
5119 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5120 ASSERT_VK_SUCCESS(err);
5121
5122 VkImageViewCreateInfo ivci = {
5123 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5124 nullptr,
5125 0,
5126 image,
5127 VK_IMAGE_VIEW_TYPE_2D,
5128 VK_FORMAT_B8G8R8A8_UNORM,
5129 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5130 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5131 };
5132 VkImageView view;
5133 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5134 ASSERT_VK_SUCCESS(err);
5135
5136 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5137 VkFramebuffer fb;
5138 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5139 ASSERT_VK_SUCCESS(err);
5140
5141 // Just use default renderpass with our framebuffer
5142 m_renderPassBeginInfo.framebuffer = fb;
5143 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005144 m_commandBuffer->BeginCommandBuffer();
5145 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5146 m_commandBuffer->EndRenderPass();
5147 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005148 // Submit cmd buffer to put it (and attached imageView) in-flight
5149 VkSubmitInfo submit_info = {};
5150 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5151 submit_info.commandBufferCount = 1;
5152 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5153 // Submit cmd buffer to put framebuffer and children in-flight
5154 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5155 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005157 vkDestroyImage(m_device->device(), image, NULL);
5158 m_errorMonitor->VerifyFound();
5159 // Wait for queue to complete so we can safely destroy image and other objects
5160 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005161 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5162 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005163 vkDestroyImage(m_device->device(), image, NULL);
5164 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5165 vkDestroyImageView(m_device->device(), view, nullptr);
5166 vkFreeMemory(m_device->device(), image_memory, nullptr);
5167}
5168
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005169TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5170 TEST_DESCRIPTION("Delete in-use renderPass.");
5171
5172 ASSERT_NO_FATAL_FAILURE(InitState());
5173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5174
5175 // Create simple renderpass
5176 VkAttachmentReference attach = {};
5177 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5178 VkSubpassDescription subpass = {};
5179 subpass.pColorAttachments = &attach;
5180 VkRenderPassCreateInfo rpci = {};
5181 rpci.subpassCount = 1;
5182 rpci.pSubpasses = &subpass;
5183 rpci.attachmentCount = 1;
5184 VkAttachmentDescription attach_desc = {};
5185 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5186 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5187 rpci.pAttachments = &attach_desc;
5188 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5189 VkRenderPass rp;
5190 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5191 ASSERT_VK_SUCCESS(err);
5192
5193 // Create a pipeline that uses the given renderpass
5194 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5195 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5196
5197 VkPipelineLayout pipeline_layout;
5198 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5199 ASSERT_VK_SUCCESS(err);
5200
5201 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5202 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5203 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005204 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005205 vp_state_ci.pViewports = &vp;
5206 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005207 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005208 vp_state_ci.pScissors = &scissors;
5209
5210 VkPipelineShaderStageCreateInfo shaderStages[2];
5211 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5212
5213 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005214 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 -06005215 // but add it to be able to run on more devices
5216 shaderStages[0] = vs.GetStageCreateInfo();
5217 shaderStages[1] = fs.GetStageCreateInfo();
5218
5219 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5220 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5221
5222 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5223 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5224 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5225
5226 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5227 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5228 rs_ci.rasterizerDiscardEnable = true;
5229 rs_ci.lineWidth = 1.0f;
5230
5231 VkPipelineColorBlendAttachmentState att = {};
5232 att.blendEnable = VK_FALSE;
5233 att.colorWriteMask = 0xf;
5234
5235 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5236 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5237 cb_ci.attachmentCount = 1;
5238 cb_ci.pAttachments = &att;
5239
5240 VkGraphicsPipelineCreateInfo gp_ci = {};
5241 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5242 gp_ci.stageCount = 2;
5243 gp_ci.pStages = shaderStages;
5244 gp_ci.pVertexInputState = &vi_ci;
5245 gp_ci.pInputAssemblyState = &ia_ci;
5246 gp_ci.pViewportState = &vp_state_ci;
5247 gp_ci.pRasterizationState = &rs_ci;
5248 gp_ci.pColorBlendState = &cb_ci;
5249 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5250 gp_ci.layout = pipeline_layout;
5251 gp_ci.renderPass = rp;
5252
5253 VkPipelineCacheCreateInfo pc_ci = {};
5254 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5255
5256 VkPipeline pipeline;
5257 VkPipelineCache pipe_cache;
5258 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5259 ASSERT_VK_SUCCESS(err);
5260
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005261 m_errorMonitor->SetUnexpectedError(
5262 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5263 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005264 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5265 ASSERT_VK_SUCCESS(err);
5266 // Bind pipeline to cmd buffer, will also bind renderpass
5267 m_commandBuffer->BeginCommandBuffer();
5268 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5269 m_commandBuffer->EndCommandBuffer();
5270
5271 VkSubmitInfo submit_info = {};
5272 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5273 submit_info.commandBufferCount = 1;
5274 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5275 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5276
5277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5278 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5279 m_errorMonitor->VerifyFound();
5280
5281 // Wait for queue to complete so we can safely destroy everything
5282 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005283 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5284 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005285 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5286 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5287 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5289}
5290
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005291TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005292 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005293 ASSERT_NO_FATAL_FAILURE(InitState());
5294
5295 VkImage image;
5296 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5297 VkImageCreateInfo image_create_info = {};
5298 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5299 image_create_info.pNext = NULL;
5300 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5301 image_create_info.format = tex_format;
5302 image_create_info.extent.width = 32;
5303 image_create_info.extent.height = 32;
5304 image_create_info.extent.depth = 1;
5305 image_create_info.mipLevels = 1;
5306 image_create_info.arrayLayers = 1;
5307 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5308 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005310 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005311 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005312 ASSERT_VK_SUCCESS(err);
5313 // Have to bind memory to image before recording cmd in cmd buffer using it
5314 VkMemoryRequirements mem_reqs;
5315 VkDeviceMemory image_mem;
5316 bool pass;
5317 VkMemoryAllocateInfo mem_alloc = {};
5318 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5319 mem_alloc.pNext = NULL;
5320 mem_alloc.memoryTypeIndex = 0;
5321 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5322 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005323 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005324 ASSERT_TRUE(pass);
5325 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5326 ASSERT_VK_SUCCESS(err);
5327
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005328 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005330 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005331
5332 m_commandBuffer->BeginCommandBuffer();
5333 VkClearColorValue ccv;
5334 ccv.float32[0] = 1.0f;
5335 ccv.float32[1] = 1.0f;
5336 ccv.float32[2] = 1.0f;
5337 ccv.float32[3] = 1.0f;
5338 VkImageSubresourceRange isr = {};
5339 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5340 isr.baseArrayLayer = 0;
5341 isr.baseMipLevel = 0;
5342 isr.layerCount = 1;
5343 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005344 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005345 m_commandBuffer->EndCommandBuffer();
5346
5347 m_errorMonitor->VerifyFound();
5348 vkDestroyImage(m_device->device(), image, NULL);
5349 vkFreeMemory(m_device->device(), image_mem, nullptr);
5350}
5351
5352TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005353 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005354 ASSERT_NO_FATAL_FAILURE(InitState());
5355
5356 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005357 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 -06005358 VK_IMAGE_TILING_OPTIMAL, 0);
5359 ASSERT_TRUE(image.initialized());
5360
5361 VkBuffer buffer;
5362 VkDeviceMemory mem;
5363 VkMemoryRequirements mem_reqs;
5364
5365 VkBufferCreateInfo buf_info = {};
5366 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005367 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005368 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005369 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5370 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5371 ASSERT_VK_SUCCESS(err);
5372
5373 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5374
5375 VkMemoryAllocateInfo alloc_info = {};
5376 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005377 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005378 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005379 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 -06005380 if (!pass) {
5381 vkDestroyBuffer(m_device->device(), buffer, NULL);
5382 return;
5383 }
5384 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5385 ASSERT_VK_SUCCESS(err);
5386
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005387 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005389 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005390 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005391 region.bufferRowLength = 16;
5392 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005393 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5394
5395 region.imageSubresource.layerCount = 1;
5396 region.imageExtent.height = 4;
5397 region.imageExtent.width = 4;
5398 region.imageExtent.depth = 1;
5399 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005400 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5401 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005402 m_commandBuffer->EndCommandBuffer();
5403
5404 m_errorMonitor->VerifyFound();
5405
5406 vkDestroyBuffer(m_device->device(), buffer, NULL);
5407 vkFreeMemory(m_device->handle(), mem, NULL);
5408}
5409
Tobin Ehlis85940f52016-07-07 16:57:21 -06005410TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005411 TEST_DESCRIPTION(
5412 "Attempt to draw with a command buffer that is invalid "
5413 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005414 ASSERT_NO_FATAL_FAILURE(InitState());
5415
5416 VkEvent event;
5417 VkEventCreateInfo evci = {};
5418 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5419 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5420 ASSERT_VK_SUCCESS(result);
5421
5422 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005423 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005424 m_commandBuffer->EndCommandBuffer();
5425
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005427 // Destroy event dependency prior to submit to cause ERROR
5428 vkDestroyEvent(m_device->device(), event, NULL);
5429
5430 VkSubmitInfo submit_info = {};
5431 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5432 submit_info.commandBufferCount = 1;
5433 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5434 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5435
5436 m_errorMonitor->VerifyFound();
5437}
5438
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005439TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005440 TEST_DESCRIPTION(
5441 "Attempt to draw with a command buffer that is invalid "
5442 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005443 ASSERT_NO_FATAL_FAILURE(InitState());
5444
5445 VkQueryPool query_pool;
5446 VkQueryPoolCreateInfo qpci{};
5447 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5448 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5449 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005450 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005451 ASSERT_VK_SUCCESS(result);
5452
5453 m_commandBuffer->BeginCommandBuffer();
5454 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5455 m_commandBuffer->EndCommandBuffer();
5456
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005458 // Destroy query pool dependency prior to submit to cause ERROR
5459 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5460
5461 VkSubmitInfo submit_info = {};
5462 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5463 submit_info.commandBufferCount = 1;
5464 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5465 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5466
5467 m_errorMonitor->VerifyFound();
5468}
5469
Tobin Ehlis24130d92016-07-08 15:50:53 -06005470TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005471 TEST_DESCRIPTION(
5472 "Attempt to draw with a command buffer that is invalid "
5473 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005474 ASSERT_NO_FATAL_FAILURE(InitState());
5475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5476
5477 VkResult err;
5478
5479 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5480 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5481
5482 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005483 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005484 ASSERT_VK_SUCCESS(err);
5485
5486 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5487 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5488 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005489 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005490 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005491 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005492 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005493 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005494
5495 VkPipelineShaderStageCreateInfo shaderStages[2];
5496 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005498 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005499 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 -06005500 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005501 shaderStages[0] = vs.GetStageCreateInfo();
5502 shaderStages[1] = fs.GetStageCreateInfo();
5503
5504 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5505 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5506
5507 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5508 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5509 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5510
5511 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5512 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005513 rs_ci.rasterizerDiscardEnable = true;
5514 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005515
5516 VkPipelineColorBlendAttachmentState att = {};
5517 att.blendEnable = VK_FALSE;
5518 att.colorWriteMask = 0xf;
5519
5520 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5521 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5522 cb_ci.attachmentCount = 1;
5523 cb_ci.pAttachments = &att;
5524
5525 VkGraphicsPipelineCreateInfo gp_ci = {};
5526 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5527 gp_ci.stageCount = 2;
5528 gp_ci.pStages = shaderStages;
5529 gp_ci.pVertexInputState = &vi_ci;
5530 gp_ci.pInputAssemblyState = &ia_ci;
5531 gp_ci.pViewportState = &vp_state_ci;
5532 gp_ci.pRasterizationState = &rs_ci;
5533 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005534 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5535 gp_ci.layout = pipeline_layout;
5536 gp_ci.renderPass = renderPass();
5537
5538 VkPipelineCacheCreateInfo pc_ci = {};
5539 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5540
5541 VkPipeline pipeline;
5542 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005543 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005544 ASSERT_VK_SUCCESS(err);
5545
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005546 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005547 ASSERT_VK_SUCCESS(err);
5548
5549 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005550 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005551 m_commandBuffer->EndCommandBuffer();
5552 // Now destroy pipeline in order to cause error when submitting
5553 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5554
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005556
5557 VkSubmitInfo submit_info = {};
5558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5559 submit_info.commandBufferCount = 1;
5560 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5561 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5562
5563 m_errorMonitor->VerifyFound();
5564 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5565 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5566}
5567
Tobin Ehlis31289162016-08-17 14:57:58 -06005568TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005569 TEST_DESCRIPTION(
5570 "Attempt to draw with a command buffer that is invalid "
5571 "due to a bound descriptor set with a buffer dependency "
5572 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005573 ASSERT_NO_FATAL_FAILURE(InitState());
5574 ASSERT_NO_FATAL_FAILURE(InitViewport());
5575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5576
5577 VkDescriptorPoolSize ds_type_count = {};
5578 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5579 ds_type_count.descriptorCount = 1;
5580
5581 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5582 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5583 ds_pool_ci.pNext = NULL;
5584 ds_pool_ci.maxSets = 1;
5585 ds_pool_ci.poolSizeCount = 1;
5586 ds_pool_ci.pPoolSizes = &ds_type_count;
5587
5588 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005589 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005590 ASSERT_VK_SUCCESS(err);
5591
5592 VkDescriptorSetLayoutBinding dsl_binding = {};
5593 dsl_binding.binding = 0;
5594 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5595 dsl_binding.descriptorCount = 1;
5596 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5597 dsl_binding.pImmutableSamplers = NULL;
5598
5599 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5600 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5601 ds_layout_ci.pNext = NULL;
5602 ds_layout_ci.bindingCount = 1;
5603 ds_layout_ci.pBindings = &dsl_binding;
5604 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005605 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005606 ASSERT_VK_SUCCESS(err);
5607
5608 VkDescriptorSet descriptorSet;
5609 VkDescriptorSetAllocateInfo alloc_info = {};
5610 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5611 alloc_info.descriptorSetCount = 1;
5612 alloc_info.descriptorPool = ds_pool;
5613 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005614 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005615 ASSERT_VK_SUCCESS(err);
5616
5617 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5618 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5619 pipeline_layout_ci.pNext = NULL;
5620 pipeline_layout_ci.setLayoutCount = 1;
5621 pipeline_layout_ci.pSetLayouts = &ds_layout;
5622
5623 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005624 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005625 ASSERT_VK_SUCCESS(err);
5626
5627 // Create a buffer to update the descriptor with
5628 uint32_t qfi = 0;
5629 VkBufferCreateInfo buffCI = {};
5630 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5631 buffCI.size = 1024;
5632 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5633 buffCI.queueFamilyIndexCount = 1;
5634 buffCI.pQueueFamilyIndices = &qfi;
5635
5636 VkBuffer buffer;
5637 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5638 ASSERT_VK_SUCCESS(err);
5639 // Allocate memory and bind to buffer so we can make it to the appropriate
5640 // error
5641 VkMemoryAllocateInfo mem_alloc = {};
5642 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5643 mem_alloc.pNext = NULL;
5644 mem_alloc.allocationSize = 1024;
5645 mem_alloc.memoryTypeIndex = 0;
5646
5647 VkMemoryRequirements memReqs;
5648 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005649 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005650 if (!pass) {
5651 vkDestroyBuffer(m_device->device(), buffer, NULL);
5652 return;
5653 }
5654
5655 VkDeviceMemory mem;
5656 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5657 ASSERT_VK_SUCCESS(err);
5658 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5659 ASSERT_VK_SUCCESS(err);
5660 // Correctly update descriptor to avoid "NOT_UPDATED" error
5661 VkDescriptorBufferInfo buffInfo = {};
5662 buffInfo.buffer = buffer;
5663 buffInfo.offset = 0;
5664 buffInfo.range = 1024;
5665
5666 VkWriteDescriptorSet descriptor_write;
5667 memset(&descriptor_write, 0, sizeof(descriptor_write));
5668 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5669 descriptor_write.dstSet = descriptorSet;
5670 descriptor_write.dstBinding = 0;
5671 descriptor_write.descriptorCount = 1;
5672 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5673 descriptor_write.pBufferInfo = &buffInfo;
5674
5675 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5676
5677 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005678 char const *vsSource =
5679 "#version 450\n"
5680 "\n"
5681 "out gl_PerVertex { \n"
5682 " vec4 gl_Position;\n"
5683 "};\n"
5684 "void main(){\n"
5685 " gl_Position = vec4(1);\n"
5686 "}\n";
5687 char const *fsSource =
5688 "#version 450\n"
5689 "\n"
5690 "layout(location=0) out vec4 x;\n"
5691 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5692 "void main(){\n"
5693 " x = vec4(bar.y);\n"
5694 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005695 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5696 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5697 VkPipelineObj pipe(m_device);
5698 pipe.AddShader(&vs);
5699 pipe.AddShader(&fs);
5700 pipe.AddColorAttachment();
5701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5702
Tony Barbour552f6c02016-12-21 14:34:07 -07005703 m_commandBuffer->BeginCommandBuffer();
5704 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005705 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5706 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5707 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005708
5709 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5710 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5711
Tobin Ehlis31289162016-08-17 14:57:58 -06005712 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005713 m_commandBuffer->EndRenderPass();
5714 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005716 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5717 vkDestroyBuffer(m_device->device(), buffer, NULL);
5718 // Attempt to submit cmd buffer
5719 VkSubmitInfo submit_info = {};
5720 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5721 submit_info.commandBufferCount = 1;
5722 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5723 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5724 m_errorMonitor->VerifyFound();
5725 // Cleanup
5726 vkFreeMemory(m_device->device(), mem, NULL);
5727
5728 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5729 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5730 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5731}
5732
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005733TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005734 TEST_DESCRIPTION(
5735 "Attempt to draw with a command buffer that is invalid "
5736 "due to a bound descriptor sets with a combined image "
5737 "sampler having their image, sampler, and descriptor set "
5738 "each respectively destroyed and then attempting to "
5739 "submit associated cmd buffers. Attempt to destroy a "
5740 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005741 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005742 ASSERT_NO_FATAL_FAILURE(InitViewport());
5743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5744
5745 VkDescriptorPoolSize ds_type_count = {};
5746 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5747 ds_type_count.descriptorCount = 1;
5748
5749 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5750 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5751 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005752 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005753 ds_pool_ci.maxSets = 1;
5754 ds_pool_ci.poolSizeCount = 1;
5755 ds_pool_ci.pPoolSizes = &ds_type_count;
5756
5757 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005758 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005759 ASSERT_VK_SUCCESS(err);
5760
5761 VkDescriptorSetLayoutBinding dsl_binding = {};
5762 dsl_binding.binding = 0;
5763 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5764 dsl_binding.descriptorCount = 1;
5765 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5766 dsl_binding.pImmutableSamplers = NULL;
5767
5768 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5769 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5770 ds_layout_ci.pNext = NULL;
5771 ds_layout_ci.bindingCount = 1;
5772 ds_layout_ci.pBindings = &dsl_binding;
5773 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005774 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005775 ASSERT_VK_SUCCESS(err);
5776
5777 VkDescriptorSet descriptorSet;
5778 VkDescriptorSetAllocateInfo alloc_info = {};
5779 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5780 alloc_info.descriptorSetCount = 1;
5781 alloc_info.descriptorPool = ds_pool;
5782 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005783 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005784 ASSERT_VK_SUCCESS(err);
5785
5786 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5787 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5788 pipeline_layout_ci.pNext = NULL;
5789 pipeline_layout_ci.setLayoutCount = 1;
5790 pipeline_layout_ci.pSetLayouts = &ds_layout;
5791
5792 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005794 ASSERT_VK_SUCCESS(err);
5795
5796 // Create images to update the descriptor with
5797 VkImage image;
5798 VkImage image2;
5799 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5800 const int32_t tex_width = 32;
5801 const int32_t tex_height = 32;
5802 VkImageCreateInfo image_create_info = {};
5803 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5804 image_create_info.pNext = NULL;
5805 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5806 image_create_info.format = tex_format;
5807 image_create_info.extent.width = tex_width;
5808 image_create_info.extent.height = tex_height;
5809 image_create_info.extent.depth = 1;
5810 image_create_info.mipLevels = 1;
5811 image_create_info.arrayLayers = 1;
5812 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5813 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5814 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5815 image_create_info.flags = 0;
5816 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5817 ASSERT_VK_SUCCESS(err);
5818 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5819 ASSERT_VK_SUCCESS(err);
5820
5821 VkMemoryRequirements memory_reqs;
5822 VkDeviceMemory image_memory;
5823 bool pass;
5824 VkMemoryAllocateInfo memory_info = {};
5825 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5826 memory_info.pNext = NULL;
5827 memory_info.allocationSize = 0;
5828 memory_info.memoryTypeIndex = 0;
5829 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5830 // Allocate enough memory for both images
5831 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005832 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005833 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005834 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005835 ASSERT_VK_SUCCESS(err);
5836 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5837 ASSERT_VK_SUCCESS(err);
5838 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005839 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005840 ASSERT_VK_SUCCESS(err);
5841
5842 VkImageViewCreateInfo image_view_create_info = {};
5843 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5844 image_view_create_info.image = image;
5845 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5846 image_view_create_info.format = tex_format;
5847 image_view_create_info.subresourceRange.layerCount = 1;
5848 image_view_create_info.subresourceRange.baseMipLevel = 0;
5849 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005850 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005851
5852 VkImageView view;
5853 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005854 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005855 ASSERT_VK_SUCCESS(err);
5856 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005857 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005858 ASSERT_VK_SUCCESS(err);
5859 // Create Samplers
5860 VkSamplerCreateInfo sampler_ci = {};
5861 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5862 sampler_ci.pNext = NULL;
5863 sampler_ci.magFilter = VK_FILTER_NEAREST;
5864 sampler_ci.minFilter = VK_FILTER_NEAREST;
5865 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5866 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5867 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5868 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5869 sampler_ci.mipLodBias = 1.0;
5870 sampler_ci.anisotropyEnable = VK_FALSE;
5871 sampler_ci.maxAnisotropy = 1;
5872 sampler_ci.compareEnable = VK_FALSE;
5873 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5874 sampler_ci.minLod = 1.0;
5875 sampler_ci.maxLod = 1.0;
5876 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5877 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5878 VkSampler sampler;
5879 VkSampler sampler2;
5880 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5881 ASSERT_VK_SUCCESS(err);
5882 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5883 ASSERT_VK_SUCCESS(err);
5884 // Update descriptor with image and sampler
5885 VkDescriptorImageInfo img_info = {};
5886 img_info.sampler = sampler;
5887 img_info.imageView = view;
5888 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5889
5890 VkWriteDescriptorSet descriptor_write;
5891 memset(&descriptor_write, 0, sizeof(descriptor_write));
5892 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5893 descriptor_write.dstSet = descriptorSet;
5894 descriptor_write.dstBinding = 0;
5895 descriptor_write.descriptorCount = 1;
5896 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5897 descriptor_write.pImageInfo = &img_info;
5898
5899 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5900
5901 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005902 char const *vsSource =
5903 "#version 450\n"
5904 "\n"
5905 "out gl_PerVertex { \n"
5906 " vec4 gl_Position;\n"
5907 "};\n"
5908 "void main(){\n"
5909 " gl_Position = vec4(1);\n"
5910 "}\n";
5911 char const *fsSource =
5912 "#version 450\n"
5913 "\n"
5914 "layout(set=0, binding=0) uniform sampler2D s;\n"
5915 "layout(location=0) out vec4 x;\n"
5916 "void main(){\n"
5917 " x = texture(s, vec2(1));\n"
5918 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5921 VkPipelineObj pipe(m_device);
5922 pipe.AddShader(&vs);
5923 pipe.AddShader(&fs);
5924 pipe.AddColorAttachment();
5925 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5926
5927 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005929 m_commandBuffer->BeginCommandBuffer();
5930 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005931 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5932 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5933 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005934 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5935 VkRect2D scissor = {{0, 0}, {16, 16}};
5936 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5937 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005938 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005939 m_commandBuffer->EndRenderPass();
5940 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005941 // Destroy sampler invalidates the cmd buffer, causing error on submit
5942 vkDestroySampler(m_device->device(), sampler, NULL);
5943 // Attempt to submit cmd buffer
5944 VkSubmitInfo submit_info = {};
5945 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5946 submit_info.commandBufferCount = 1;
5947 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5948 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5949 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005950
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005951 // Now re-update descriptor with valid sampler and delete image
5952 img_info.sampler = sampler2;
5953 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005954
5955 VkCommandBufferBeginInfo info = {};
5956 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5957 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005960 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005961 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005962 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5963 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5964 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005965 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5966 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005967 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005968 m_commandBuffer->EndRenderPass();
5969 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005970 // Destroy image invalidates the cmd buffer, causing error on submit
5971 vkDestroyImage(m_device->device(), image, NULL);
5972 // Attempt to submit cmd buffer
5973 submit_info = {};
5974 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5975 submit_info.commandBufferCount = 1;
5976 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5977 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5978 m_errorMonitor->VerifyFound();
5979 // Now update descriptor to be valid, but then free descriptor
5980 img_info.imageView = view2;
5981 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005982 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005983 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005984 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5985 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5986 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005987 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5988 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005989 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005990 m_commandBuffer->EndRenderPass();
5991 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005992 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005993
5994 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005996 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005997 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005998
5999 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006000 // 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 -07006001 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006002 m_errorMonitor->SetUnexpectedError(
6003 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6004 "either be a valid handle or VK_NULL_HANDLE");
6005 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006006 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6007
6008 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006009 submit_info = {};
6010 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6011 submit_info.commandBufferCount = 1;
6012 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006014 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6015 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006016
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006017 // Cleanup
6018 vkFreeMemory(m_device->device(), image_memory, NULL);
6019 vkDestroySampler(m_device->device(), sampler2, NULL);
6020 vkDestroyImage(m_device->device(), image2, NULL);
6021 vkDestroyImageView(m_device->device(), view, NULL);
6022 vkDestroyImageView(m_device->device(), view2, NULL);
6023 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6024 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6026}
6027
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006028TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6029 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6030 ASSERT_NO_FATAL_FAILURE(InitState());
6031 ASSERT_NO_FATAL_FAILURE(InitViewport());
6032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6033
6034 VkDescriptorPoolSize ds_type_count = {};
6035 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6036 ds_type_count.descriptorCount = 1;
6037
6038 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6039 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6040 ds_pool_ci.pNext = NULL;
6041 ds_pool_ci.maxSets = 1;
6042 ds_pool_ci.poolSizeCount = 1;
6043 ds_pool_ci.pPoolSizes = &ds_type_count;
6044
6045 VkDescriptorPool ds_pool;
6046 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6047 ASSERT_VK_SUCCESS(err);
6048
6049 VkDescriptorSetLayoutBinding dsl_binding = {};
6050 dsl_binding.binding = 0;
6051 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6052 dsl_binding.descriptorCount = 1;
6053 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6054 dsl_binding.pImmutableSamplers = NULL;
6055
6056 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6057 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6058 ds_layout_ci.pNext = NULL;
6059 ds_layout_ci.bindingCount = 1;
6060 ds_layout_ci.pBindings = &dsl_binding;
6061 VkDescriptorSetLayout ds_layout;
6062 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6063 ASSERT_VK_SUCCESS(err);
6064
6065 VkDescriptorSet descriptor_set;
6066 VkDescriptorSetAllocateInfo alloc_info = {};
6067 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6068 alloc_info.descriptorSetCount = 1;
6069 alloc_info.descriptorPool = ds_pool;
6070 alloc_info.pSetLayouts = &ds_layout;
6071 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6072 ASSERT_VK_SUCCESS(err);
6073
6074 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6075 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6076 pipeline_layout_ci.pNext = NULL;
6077 pipeline_layout_ci.setLayoutCount = 1;
6078 pipeline_layout_ci.pSetLayouts = &ds_layout;
6079
6080 VkPipelineLayout pipeline_layout;
6081 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6082 ASSERT_VK_SUCCESS(err);
6083
6084 // Create image to update the descriptor with
6085 VkImageObj image(m_device);
6086 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6087 ASSERT_TRUE(image.initialized());
6088
6089 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6090 // Create Sampler
6091 VkSamplerCreateInfo sampler_ci = {};
6092 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6093 sampler_ci.pNext = NULL;
6094 sampler_ci.magFilter = VK_FILTER_NEAREST;
6095 sampler_ci.minFilter = VK_FILTER_NEAREST;
6096 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6097 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6098 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6099 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6100 sampler_ci.mipLodBias = 1.0;
6101 sampler_ci.anisotropyEnable = VK_FALSE;
6102 sampler_ci.maxAnisotropy = 1;
6103 sampler_ci.compareEnable = VK_FALSE;
6104 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6105 sampler_ci.minLod = 1.0;
6106 sampler_ci.maxLod = 1.0;
6107 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6108 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6109 VkSampler sampler;
6110 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6111 ASSERT_VK_SUCCESS(err);
6112 // Update descriptor with image and sampler
6113 VkDescriptorImageInfo img_info = {};
6114 img_info.sampler = sampler;
6115 img_info.imageView = view;
6116 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6117
6118 VkWriteDescriptorSet descriptor_write;
6119 memset(&descriptor_write, 0, sizeof(descriptor_write));
6120 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6121 descriptor_write.dstSet = descriptor_set;
6122 descriptor_write.dstBinding = 0;
6123 descriptor_write.descriptorCount = 1;
6124 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6125 descriptor_write.pImageInfo = &img_info;
6126
6127 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6128
6129 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006130 char const *vsSource =
6131 "#version 450\n"
6132 "\n"
6133 "out gl_PerVertex { \n"
6134 " vec4 gl_Position;\n"
6135 "};\n"
6136 "void main(){\n"
6137 " gl_Position = vec4(1);\n"
6138 "}\n";
6139 char const *fsSource =
6140 "#version 450\n"
6141 "\n"
6142 "layout(set=0, binding=0) uniform sampler2D s;\n"
6143 "layout(location=0) out vec4 x;\n"
6144 "void main(){\n"
6145 " x = texture(s, vec2(1));\n"
6146 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006147 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6148 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6149 VkPipelineObj pipe(m_device);
6150 pipe.AddShader(&vs);
6151 pipe.AddShader(&fs);
6152 pipe.AddColorAttachment();
6153 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6154
Tony Barbour552f6c02016-12-21 14:34:07 -07006155 m_commandBuffer->BeginCommandBuffer();
6156 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006157 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6158 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6159 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006160
6161 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6162 VkRect2D scissor = {{0, 0}, {16, 16}};
6163 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6164 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6165
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006166 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006167 m_commandBuffer->EndRenderPass();
6168 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006169 // Submit cmd buffer to put pool in-flight
6170 VkSubmitInfo submit_info = {};
6171 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6172 submit_info.commandBufferCount = 1;
6173 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6174 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6175 // Destroy pool while in-flight, causing error
6176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6177 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6178 m_errorMonitor->VerifyFound();
6179 vkQueueWaitIdle(m_device->m_queue);
6180 // Cleanup
6181 vkDestroySampler(m_device->device(), sampler, NULL);
6182 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6183 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006184 m_errorMonitor->SetUnexpectedError(
6185 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6186 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006187 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006188 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006189}
6190
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006191TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6192 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6193 ASSERT_NO_FATAL_FAILURE(InitState());
6194 ASSERT_NO_FATAL_FAILURE(InitViewport());
6195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6196
6197 VkDescriptorPoolSize ds_type_count = {};
6198 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6199 ds_type_count.descriptorCount = 1;
6200
6201 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6202 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6203 ds_pool_ci.pNext = NULL;
6204 ds_pool_ci.maxSets = 1;
6205 ds_pool_ci.poolSizeCount = 1;
6206 ds_pool_ci.pPoolSizes = &ds_type_count;
6207
6208 VkDescriptorPool ds_pool;
6209 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6210 ASSERT_VK_SUCCESS(err);
6211
6212 VkDescriptorSetLayoutBinding dsl_binding = {};
6213 dsl_binding.binding = 0;
6214 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6215 dsl_binding.descriptorCount = 1;
6216 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6217 dsl_binding.pImmutableSamplers = NULL;
6218
6219 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6220 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6221 ds_layout_ci.pNext = NULL;
6222 ds_layout_ci.bindingCount = 1;
6223 ds_layout_ci.pBindings = &dsl_binding;
6224 VkDescriptorSetLayout ds_layout;
6225 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6226 ASSERT_VK_SUCCESS(err);
6227
6228 VkDescriptorSet descriptorSet;
6229 VkDescriptorSetAllocateInfo alloc_info = {};
6230 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6231 alloc_info.descriptorSetCount = 1;
6232 alloc_info.descriptorPool = ds_pool;
6233 alloc_info.pSetLayouts = &ds_layout;
6234 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6235 ASSERT_VK_SUCCESS(err);
6236
6237 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6238 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6239 pipeline_layout_ci.pNext = NULL;
6240 pipeline_layout_ci.setLayoutCount = 1;
6241 pipeline_layout_ci.pSetLayouts = &ds_layout;
6242
6243 VkPipelineLayout pipeline_layout;
6244 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6245 ASSERT_VK_SUCCESS(err);
6246
6247 // Create images to update the descriptor with
6248 VkImage image;
6249 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6250 const int32_t tex_width = 32;
6251 const int32_t tex_height = 32;
6252 VkImageCreateInfo image_create_info = {};
6253 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6254 image_create_info.pNext = NULL;
6255 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6256 image_create_info.format = tex_format;
6257 image_create_info.extent.width = tex_width;
6258 image_create_info.extent.height = tex_height;
6259 image_create_info.extent.depth = 1;
6260 image_create_info.mipLevels = 1;
6261 image_create_info.arrayLayers = 1;
6262 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6263 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6264 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6265 image_create_info.flags = 0;
6266 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6267 ASSERT_VK_SUCCESS(err);
6268 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6269 VkMemoryRequirements memory_reqs;
6270 VkDeviceMemory image_memory;
6271 bool pass;
6272 VkMemoryAllocateInfo memory_info = {};
6273 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6274 memory_info.pNext = NULL;
6275 memory_info.allocationSize = 0;
6276 memory_info.memoryTypeIndex = 0;
6277 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6278 // Allocate enough memory for image
6279 memory_info.allocationSize = memory_reqs.size;
6280 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6281 ASSERT_TRUE(pass);
6282 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6283 ASSERT_VK_SUCCESS(err);
6284 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6285 ASSERT_VK_SUCCESS(err);
6286
6287 VkImageViewCreateInfo image_view_create_info = {};
6288 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6289 image_view_create_info.image = image;
6290 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6291 image_view_create_info.format = tex_format;
6292 image_view_create_info.subresourceRange.layerCount = 1;
6293 image_view_create_info.subresourceRange.baseMipLevel = 0;
6294 image_view_create_info.subresourceRange.levelCount = 1;
6295 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6296
6297 VkImageView view;
6298 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6299 ASSERT_VK_SUCCESS(err);
6300 // Create Samplers
6301 VkSamplerCreateInfo sampler_ci = {};
6302 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6303 sampler_ci.pNext = NULL;
6304 sampler_ci.magFilter = VK_FILTER_NEAREST;
6305 sampler_ci.minFilter = VK_FILTER_NEAREST;
6306 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6307 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6308 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6309 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6310 sampler_ci.mipLodBias = 1.0;
6311 sampler_ci.anisotropyEnable = VK_FALSE;
6312 sampler_ci.maxAnisotropy = 1;
6313 sampler_ci.compareEnable = VK_FALSE;
6314 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6315 sampler_ci.minLod = 1.0;
6316 sampler_ci.maxLod = 1.0;
6317 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6318 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6319 VkSampler sampler;
6320 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6321 ASSERT_VK_SUCCESS(err);
6322 // Update descriptor with image and sampler
6323 VkDescriptorImageInfo img_info = {};
6324 img_info.sampler = sampler;
6325 img_info.imageView = view;
6326 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6327
6328 VkWriteDescriptorSet descriptor_write;
6329 memset(&descriptor_write, 0, sizeof(descriptor_write));
6330 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6331 descriptor_write.dstSet = descriptorSet;
6332 descriptor_write.dstBinding = 0;
6333 descriptor_write.descriptorCount = 1;
6334 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6335 descriptor_write.pImageInfo = &img_info;
6336 // Break memory binding and attempt update
6337 vkFreeMemory(m_device->device(), image_memory, nullptr);
6338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006339 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6341 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6342 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6343 m_errorMonitor->VerifyFound();
6344 // Cleanup
6345 vkDestroyImage(m_device->device(), image, NULL);
6346 vkDestroySampler(m_device->device(), sampler, NULL);
6347 vkDestroyImageView(m_device->device(), view, NULL);
6348 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6349 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6350 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6351}
6352
Karl Schultz6addd812016-02-02 17:17:23 -07006353TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006354 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6355 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006356 // Create a valid cmd buffer
6357 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006358 uint64_t fake_pipeline_handle = 0xbaad6001;
6359 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006360 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6362
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006364 m_commandBuffer->BeginCommandBuffer();
6365 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006366 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006367 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006368
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006369 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 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 -06006371 Draw(1, 0, 0, 0);
6372 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006373
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006374 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006375 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 -07006376 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006377 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6378 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006379}
6380
Karl Schultz6addd812016-02-02 17:17:23 -07006381TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006382 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006383 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006386
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006387 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006388 ASSERT_NO_FATAL_FAILURE(InitViewport());
6389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006390 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006391 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6392 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006393
6394 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006395 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6396 ds_pool_ci.pNext = NULL;
6397 ds_pool_ci.maxSets = 1;
6398 ds_pool_ci.poolSizeCount = 1;
6399 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006400
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006401 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006402 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006403 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006404
Tony Barboureb254902015-07-15 12:50:33 -06006405 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006406 dsl_binding.binding = 0;
6407 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6408 dsl_binding.descriptorCount = 1;
6409 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6410 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006411
Tony Barboureb254902015-07-15 12:50:33 -06006412 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006413 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6414 ds_layout_ci.pNext = NULL;
6415 ds_layout_ci.bindingCount = 1;
6416 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006417 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006419 ASSERT_VK_SUCCESS(err);
6420
6421 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006422 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006423 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006424 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006425 alloc_info.descriptorPool = ds_pool;
6426 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006427 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006428 ASSERT_VK_SUCCESS(err);
6429
Tony Barboureb254902015-07-15 12:50:33 -06006430 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006431 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6432 pipeline_layout_ci.pNext = NULL;
6433 pipeline_layout_ci.setLayoutCount = 1;
6434 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006435
6436 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006437 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006438 ASSERT_VK_SUCCESS(err);
6439
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006441 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006442 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006444
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006445 VkPipelineObj pipe(m_device);
6446 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006447 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006448 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006449 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006450
Tony Barbour552f6c02016-12-21 14:34:07 -07006451 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006452 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6453 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6454 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006455
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006456 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006457
Chia-I Wuf7458c52015-10-26 21:10:41 +08006458 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6459 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006461}
6462
Karl Schultz6addd812016-02-02 17:17:23 -07006463TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006464 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006465 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006466
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006468
6469 ASSERT_NO_FATAL_FAILURE(InitState());
6470 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006471 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6472 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006473
6474 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006475 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6476 ds_pool_ci.pNext = NULL;
6477 ds_pool_ci.maxSets = 1;
6478 ds_pool_ci.poolSizeCount = 1;
6479 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006480
6481 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006482 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006483 ASSERT_VK_SUCCESS(err);
6484
6485 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006486 dsl_binding.binding = 0;
6487 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6488 dsl_binding.descriptorCount = 1;
6489 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6490 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006491
6492 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006493 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6494 ds_layout_ci.pNext = NULL;
6495 ds_layout_ci.bindingCount = 1;
6496 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006497 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006498 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006499 ASSERT_VK_SUCCESS(err);
6500
6501 VkDescriptorSet descriptorSet;
6502 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006503 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006504 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006505 alloc_info.descriptorPool = ds_pool;
6506 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006507 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006508 ASSERT_VK_SUCCESS(err);
6509
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006510 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006511 VkWriteDescriptorSet descriptor_write;
6512 memset(&descriptor_write, 0, sizeof(descriptor_write));
6513 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6514 descriptor_write.dstSet = descriptorSet;
6515 descriptor_write.dstBinding = 0;
6516 descriptor_write.descriptorCount = 1;
6517 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6518 descriptor_write.pTexelBufferView = &view;
6519
6520 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6521
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006522 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006523
6524 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6525 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6526}
6527
Mark Youngd339ba32016-05-30 13:28:35 -06006528TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006529 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 -06006530
6531 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006533 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006534
6535 ASSERT_NO_FATAL_FAILURE(InitState());
6536
6537 // Create a buffer with no bound memory and then attempt to create
6538 // a buffer view.
6539 VkBufferCreateInfo buff_ci = {};
6540 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006541 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006542 buff_ci.size = 256;
6543 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6544 VkBuffer buffer;
6545 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6546 ASSERT_VK_SUCCESS(err);
6547
6548 VkBufferViewCreateInfo buff_view_ci = {};
6549 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6550 buff_view_ci.buffer = buffer;
6551 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6552 buff_view_ci.range = VK_WHOLE_SIZE;
6553 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006555
6556 m_errorMonitor->VerifyFound();
6557 vkDestroyBuffer(m_device->device(), buffer, NULL);
6558 // If last error is success, it still created the view, so delete it.
6559 if (err == VK_SUCCESS) {
6560 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6561 }
6562}
6563
Karl Schultz6addd812016-02-02 17:17:23 -07006564TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6565 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6566 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006567 // 1. No dynamicOffset supplied
6568 // 2. Too many dynamicOffsets supplied
6569 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006570 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6572 " requires 1 dynamicOffsets, but only "
6573 "0 dynamicOffsets are left in "
6574 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006575
6576 ASSERT_NO_FATAL_FAILURE(InitState());
6577 ASSERT_NO_FATAL_FAILURE(InitViewport());
6578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6579
6580 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006581 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6582 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006583
6584 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006585 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6586 ds_pool_ci.pNext = NULL;
6587 ds_pool_ci.maxSets = 1;
6588 ds_pool_ci.poolSizeCount = 1;
6589 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006590
6591 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006592 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006593 ASSERT_VK_SUCCESS(err);
6594
6595 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006596 dsl_binding.binding = 0;
6597 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6598 dsl_binding.descriptorCount = 1;
6599 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6600 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006601
6602 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006603 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6604 ds_layout_ci.pNext = NULL;
6605 ds_layout_ci.bindingCount = 1;
6606 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006607 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006608 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006609 ASSERT_VK_SUCCESS(err);
6610
6611 VkDescriptorSet descriptorSet;
6612 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006614 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006615 alloc_info.descriptorPool = ds_pool;
6616 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006617 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006618 ASSERT_VK_SUCCESS(err);
6619
6620 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006621 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6622 pipeline_layout_ci.pNext = NULL;
6623 pipeline_layout_ci.setLayoutCount = 1;
6624 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006625
6626 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006627 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006628 ASSERT_VK_SUCCESS(err);
6629
6630 // Create a buffer to update the descriptor with
6631 uint32_t qfi = 0;
6632 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006633 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6634 buffCI.size = 1024;
6635 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6636 buffCI.queueFamilyIndexCount = 1;
6637 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006638
6639 VkBuffer dyub;
6640 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6641 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006642 // Allocate memory and bind to buffer so we can make it to the appropriate
6643 // error
6644 VkMemoryAllocateInfo mem_alloc = {};
6645 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6646 mem_alloc.pNext = NULL;
6647 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006648 mem_alloc.memoryTypeIndex = 0;
6649
6650 VkMemoryRequirements memReqs;
6651 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006652 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006653 if (!pass) {
6654 vkDestroyBuffer(m_device->device(), dyub, NULL);
6655 return;
6656 }
6657
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006658 VkDeviceMemory mem;
6659 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6660 ASSERT_VK_SUCCESS(err);
6661 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6662 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006663 // Correctly update descriptor to avoid "NOT_UPDATED" error
6664 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006665 buffInfo.buffer = dyub;
6666 buffInfo.offset = 0;
6667 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006668
6669 VkWriteDescriptorSet descriptor_write;
6670 memset(&descriptor_write, 0, sizeof(descriptor_write));
6671 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6672 descriptor_write.dstSet = descriptorSet;
6673 descriptor_write.dstBinding = 0;
6674 descriptor_write.descriptorCount = 1;
6675 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6676 descriptor_write.pBufferInfo = &buffInfo;
6677
6678 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6679
Tony Barbour552f6c02016-12-21 14:34:07 -07006680 m_commandBuffer->BeginCommandBuffer();
6681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006682 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6683 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006684 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006685 uint32_t pDynOff[2] = {512, 756};
6686 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6688 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6689 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6690 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006691 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006692 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6694 " dynamic offset 512 combined with "
6695 "offset 0 and range 1024 that "
6696 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006697 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006698 char const *vsSource =
6699 "#version 450\n"
6700 "\n"
6701 "out gl_PerVertex { \n"
6702 " vec4 gl_Position;\n"
6703 "};\n"
6704 "void main(){\n"
6705 " gl_Position = vec4(1);\n"
6706 "}\n";
6707 char const *fsSource =
6708 "#version 450\n"
6709 "\n"
6710 "layout(location=0) out vec4 x;\n"
6711 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6712 "void main(){\n"
6713 " x = vec4(bar.y);\n"
6714 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6717 VkPipelineObj pipe(m_device);
6718 pipe.AddShader(&vs);
6719 pipe.AddShader(&fs);
6720 pipe.AddColorAttachment();
6721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6722
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006723 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6724 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6725 VkRect2D scissor = {{0, 0}, {16, 16}};
6726 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006728 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006729 // This update should succeed, but offset size of 512 will overstep buffer
6730 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006731 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6732 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006733 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006734 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006735
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006736 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006737 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006738
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006739 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006740 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006741 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6742}
6743
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006744TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006745 TEST_DESCRIPTION(
6746 "Attempt to update a descriptor with a non-sparse buffer "
6747 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006748 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006750 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6752 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006753
6754 ASSERT_NO_FATAL_FAILURE(InitState());
6755 ASSERT_NO_FATAL_FAILURE(InitViewport());
6756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6757
6758 VkDescriptorPoolSize ds_type_count = {};
6759 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6760 ds_type_count.descriptorCount = 1;
6761
6762 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6763 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6764 ds_pool_ci.pNext = NULL;
6765 ds_pool_ci.maxSets = 1;
6766 ds_pool_ci.poolSizeCount = 1;
6767 ds_pool_ci.pPoolSizes = &ds_type_count;
6768
6769 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006770 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006771 ASSERT_VK_SUCCESS(err);
6772
6773 VkDescriptorSetLayoutBinding dsl_binding = {};
6774 dsl_binding.binding = 0;
6775 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6776 dsl_binding.descriptorCount = 1;
6777 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6778 dsl_binding.pImmutableSamplers = NULL;
6779
6780 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6781 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6782 ds_layout_ci.pNext = NULL;
6783 ds_layout_ci.bindingCount = 1;
6784 ds_layout_ci.pBindings = &dsl_binding;
6785 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006787 ASSERT_VK_SUCCESS(err);
6788
6789 VkDescriptorSet descriptorSet;
6790 VkDescriptorSetAllocateInfo alloc_info = {};
6791 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6792 alloc_info.descriptorSetCount = 1;
6793 alloc_info.descriptorPool = ds_pool;
6794 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006795 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006796 ASSERT_VK_SUCCESS(err);
6797
6798 // Create a buffer to update the descriptor with
6799 uint32_t qfi = 0;
6800 VkBufferCreateInfo buffCI = {};
6801 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6802 buffCI.size = 1024;
6803 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6804 buffCI.queueFamilyIndexCount = 1;
6805 buffCI.pQueueFamilyIndices = &qfi;
6806
6807 VkBuffer dyub;
6808 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6809 ASSERT_VK_SUCCESS(err);
6810
6811 // Attempt to update descriptor without binding memory to it
6812 VkDescriptorBufferInfo buffInfo = {};
6813 buffInfo.buffer = dyub;
6814 buffInfo.offset = 0;
6815 buffInfo.range = 1024;
6816
6817 VkWriteDescriptorSet descriptor_write;
6818 memset(&descriptor_write, 0, sizeof(descriptor_write));
6819 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6820 descriptor_write.dstSet = descriptorSet;
6821 descriptor_write.dstBinding = 0;
6822 descriptor_write.descriptorCount = 1;
6823 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6824 descriptor_write.pBufferInfo = &buffInfo;
6825
6826 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6827 m_errorMonitor->VerifyFound();
6828
6829 vkDestroyBuffer(m_device->device(), dyub, NULL);
6830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6832}
6833
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006834TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006835 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006836 ASSERT_NO_FATAL_FAILURE(InitState());
6837 ASSERT_NO_FATAL_FAILURE(InitViewport());
6838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6839
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006840 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006841 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006842 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6843 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6844 pipeline_layout_ci.pushConstantRangeCount = 1;
6845 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6846
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006847 //
6848 // Check for invalid push constant ranges in pipeline layouts.
6849 //
6850 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006851 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006852 char const *msg;
6853 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006854
Karl Schultzc81037d2016-05-12 08:11:23 -06006855 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6856 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6857 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6858 "vkCreatePipelineLayout() call has push constants index 0 with "
6859 "size 0."},
6860 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6861 "vkCreatePipelineLayout() call has push constants index 0 with "
6862 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006863 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006864 "vkCreatePipelineLayout() call has push constants index 0 with "
6865 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006866 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006867 "vkCreatePipelineLayout() call has push constants index 0 with "
6868 "size 0."},
6869 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6870 "vkCreatePipelineLayout() call has push constants index 0 with "
6871 "offset 1. Offset must"},
6872 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6873 "vkCreatePipelineLayout() call has push constants index 0 "
6874 "with offset "},
6875 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6876 "vkCreatePipelineLayout() call has push constants "
6877 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006878 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006879 "vkCreatePipelineLayout() call has push constants index 0 "
6880 "with offset "},
6881 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6882 "vkCreatePipelineLayout() call has push "
6883 "constants index 0 with offset "},
6884 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6885 "vkCreatePipelineLayout() call has push "
6886 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006887 }};
6888
6889 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006890 for (const auto &iter : range_tests) {
6891 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006894 m_errorMonitor->VerifyFound();
6895 if (VK_SUCCESS == err) {
6896 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6897 }
6898 }
6899
6900 // Check for invalid stage flag
6901 pc_range.offset = 0;
6902 pc_range.size = 16;
6903 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006904 m_errorMonitor->SetDesiredFailureMsg(
6905 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6906 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006907 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006908 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006909 if (VK_SUCCESS == err) {
6910 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6911 }
6912
6913 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006914 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006915 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006916 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006917 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006918 };
6919
Karl Schultzc81037d2016-05-12 08:11:23 -06006920 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006921 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6922 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6923 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6924 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6925 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006926 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6927 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6928 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6929 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6930 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6931 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6932 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6933 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6934 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6935 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006936 {
6937 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6938 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6939 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6940 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6941 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006942 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006943 },
6944 {
6945 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6946 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6947 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6948 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6949 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006950 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006951 },
6952 {
6953 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6954 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6955 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6956 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6957 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006958 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006959 },
6960 {
6961 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6962 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6963 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6964 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6965 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006966 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6967 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6968 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6969 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006970 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006971
Karl Schultzc81037d2016-05-12 08:11:23 -06006972 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006973 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006974 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006976 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006977 m_errorMonitor->VerifyFound();
6978 if (VK_SUCCESS == err) {
6979 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6980 }
6981 }
6982
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006983 //
6984 // CmdPushConstants tests
6985 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006986 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006987
6988 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006989 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6990 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006991 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006992 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6993 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006994 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006995 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6996 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006997 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006998 "vkCmdPushConstants() call has push constants with offset 1. "
6999 "Offset must be a multiple of 4."},
7000 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
7001 "vkCmdPushConstants() call has push constants with offset 1. "
7002 "Offset must be a multiple of 4."},
7003 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
7004 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
7005 "0x1 not within flag-matching ranges in pipeline layout"},
7006 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
7007 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
7008 "0x1 not within flag-matching ranges in pipeline layout"},
7009 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
7010 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
7011 "0x1 not within flag-matching ranges in pipeline layout"},
7012 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
7013 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
7014 "0x1 not within flag-matching ranges in pipeline layout"},
7015 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
7016 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
7017 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007018 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06007019 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
7020 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007021 }};
7022
Tony Barbour552f6c02016-12-21 14:34:07 -07007023 m_commandBuffer->BeginCommandBuffer();
7024 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007025
7026 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06007027 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007028 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007029 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007030 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007031 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007032 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007033 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007034 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7036 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007037 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007038 m_errorMonitor->VerifyFound();
7039 }
7040
7041 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007043 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007044 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06007045 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007046
Karl Schultzc81037d2016-05-12 08:11:23 -06007047 // overlapping range tests with cmd
7048 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
7049 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
7050 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
7051 "0x1 not within flag-matching ranges in pipeline layout"},
7052 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
7053 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
7054 "0x1 not within flag-matching ranges in pipeline layout"},
7055 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
7056 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
7057 "0x1 not within flag-matching ranges in pipeline layout"},
7058 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007059 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06007060 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007061 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
7062 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06007063 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007064 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06007065 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007066 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06007067 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007068 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7070 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007071 iter.range.size, dummy_values);
7072 m_errorMonitor->VerifyFound();
7073 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007074 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7075
Tony Barbour552f6c02016-12-21 14:34:07 -07007076 m_commandBuffer->EndRenderPass();
7077 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007078}
7079
Karl Schultz6addd812016-02-02 17:17:23 -07007080TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007081 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007082 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007083
7084 ASSERT_NO_FATAL_FAILURE(InitState());
7085 ASSERT_NO_FATAL_FAILURE(InitViewport());
7086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7087
7088 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7089 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007090 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7091 ds_type_count[0].descriptorCount = 10;
7092 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7093 ds_type_count[1].descriptorCount = 2;
7094 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7095 ds_type_count[2].descriptorCount = 2;
7096 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7097 ds_type_count[3].descriptorCount = 5;
7098 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7099 // type
7100 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7101 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7102 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007103
7104 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007105 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7106 ds_pool_ci.pNext = NULL;
7107 ds_pool_ci.maxSets = 5;
7108 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7109 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007110
7111 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007112 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007113 ASSERT_VK_SUCCESS(err);
7114
7115 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7116 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007117 dsl_binding[0].binding = 0;
7118 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7119 dsl_binding[0].descriptorCount = 5;
7120 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7121 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007122
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007123 // Create layout identical to set0 layout but w/ different stageFlags
7124 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007125 dsl_fs_stage_only.binding = 0;
7126 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7127 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007128 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7129 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007130 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007131 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007132 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7133 ds_layout_ci.pNext = NULL;
7134 ds_layout_ci.bindingCount = 1;
7135 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007136 static const uint32_t NUM_LAYOUTS = 4;
7137 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007138 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007139 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7140 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007141 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007142 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007143 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007144 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007145 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007146 dsl_binding[0].binding = 0;
7147 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007148 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007149 dsl_binding[1].binding = 1;
7150 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7151 dsl_binding[1].descriptorCount = 2;
7152 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7153 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007154 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007155 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007156 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007157 ASSERT_VK_SUCCESS(err);
7158 dsl_binding[0].binding = 0;
7159 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007160 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007161 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007162 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007163 ASSERT_VK_SUCCESS(err);
7164 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007165 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007166 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007167 ASSERT_VK_SUCCESS(err);
7168
7169 static const uint32_t NUM_SETS = 4;
7170 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7171 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007172 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007173 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007174 alloc_info.descriptorPool = ds_pool;
7175 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007176 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007177 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007178 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007179 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007180 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007181 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007182 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007183
7184 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007185 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7186 pipeline_layout_ci.pNext = NULL;
7187 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7188 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007189
7190 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007191 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007192 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007193 // Create pipelineLayout with only one setLayout
7194 pipeline_layout_ci.setLayoutCount = 1;
7195 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007197 ASSERT_VK_SUCCESS(err);
7198 // Create pipelineLayout with 2 descriptor setLayout at index 0
7199 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7200 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007201 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007202 ASSERT_VK_SUCCESS(err);
7203 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7204 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7205 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007206 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007207 ASSERT_VK_SUCCESS(err);
7208 // Create pipelineLayout with UB type, but stageFlags for FS only
7209 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7210 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007211 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007212 ASSERT_VK_SUCCESS(err);
7213 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7214 VkDescriptorSetLayout pl_bad_s0[2] = {};
7215 pl_bad_s0[0] = ds_layout_fs_only;
7216 pl_bad_s0[1] = ds_layout[1];
7217 pipeline_layout_ci.setLayoutCount = 2;
7218 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7219 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007220 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007221 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007222
Tobin Ehlis88452832015-12-03 09:40:56 -07007223 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007224 char const *vsSource =
7225 "#version 450\n"
7226 "\n"
7227 "out gl_PerVertex {\n"
7228 " vec4 gl_Position;\n"
7229 "};\n"
7230 "void main(){\n"
7231 " gl_Position = vec4(1);\n"
7232 "}\n";
7233 char const *fsSource =
7234 "#version 450\n"
7235 "\n"
7236 "layout(location=0) out vec4 x;\n"
7237 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7238 "void main(){\n"
7239 " x = vec4(bar.y);\n"
7240 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007241 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7242 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007243 VkPipelineObj pipe(m_device);
7244 pipe.AddShader(&vs);
7245 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007246 pipe.AddColorAttachment();
7247 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007248
Tony Barbour552f6c02016-12-21 14:34:07 -07007249 m_commandBuffer->BeginCommandBuffer();
7250 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007251
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007252 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007253 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7254 // of PSO
7255 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7256 // cmd_pipeline.c
7257 // due to the fact that cmd_alloc_dset_data() has not been called in
7258 // cmd_bind_graphics_pipeline()
7259 // TODO : Want to cause various binding incompatibility issues here to test
7260 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007261 // First cause various verify_layout_compatibility() fails
7262 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007263 // verify_set_layout_compatibility fail cases:
7264 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007266 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7267 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007268 m_errorMonitor->VerifyFound();
7269
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007270 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7272 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7273 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007274 m_errorMonitor->VerifyFound();
7275
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007276 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007277 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7278 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7280 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7281 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007282 m_errorMonitor->VerifyFound();
7283
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007284 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7285 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7287 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7288 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007289 m_errorMonitor->VerifyFound();
7290
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007291 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7292 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7294 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7295 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7296 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007297 m_errorMonitor->VerifyFound();
7298
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007299 // Cause INFO messages due to disturbing previously bound Sets
7300 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007301 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7302 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007303 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7305 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7306 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007307 m_errorMonitor->VerifyFound();
7308
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007309 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7310 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007311 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7313 " newly bound as set #0 so set #1 and "
7314 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007315 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7316 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007317 m_errorMonitor->VerifyFound();
7318
Tobin Ehlis10fad692016-07-07 12:00:36 -06007319 // Now that we're done actively using the pipelineLayout that gfx pipeline
7320 // was created with, we should be able to delete it. Do that now to verify
7321 // that validation obeys pipelineLayout lifetime
7322 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7323
Tobin Ehlis88452832015-12-03 09:40:56 -07007324 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007325 // 1. Error due to not binding required set (we actually use same code as
7326 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007327 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7328 &descriptorSet[0], 0, NULL);
7329 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7330 &descriptorSet[1], 0, NULL);
7331 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 -07007332
7333 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7334 VkRect2D scissor = {{0, 0}, {16, 16}};
7335 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7336 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7337
Tobin Ehlis88452832015-12-03 09:40:56 -07007338 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007339 m_errorMonitor->VerifyFound();
7340
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007341 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007342 // 2. Error due to bound set not being compatible with PSO's
7343 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007344 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7345 &descriptorSet[0], 0, NULL);
7346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007347 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007348 m_errorMonitor->VerifyFound();
7349
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007350 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007351 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007352 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7353 }
7354 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007355 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7356 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7357}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007358
Karl Schultz6addd812016-02-02 17:17:23 -07007359TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7361 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007362
7363 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007364 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007365 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007366 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007367
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007368 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007369}
7370
Karl Schultz6addd812016-02-02 17:17:23 -07007371TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7372 VkResult err;
7373 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007374
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007376
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007377 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007378
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007379 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007380 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007381 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007382 cmd.commandPool = m_commandPool;
7383 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007384 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007385
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007386 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007387 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007388
7389 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007390 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007391 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7392
7393 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007394 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007395 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007396 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 -07007397 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007398
7399 // The error should be caught by validation of the BeginCommandBuffer call
7400 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7401
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007402 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007403 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007404}
7405
Karl Schultz6addd812016-02-02 17:17:23 -07007406TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007407 // Cause error due to Begin while recording CB
7408 // Then cause 2 errors for attempting to reset CB w/o having
7409 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7410 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007412
7413 ASSERT_NO_FATAL_FAILURE(InitState());
7414
7415 // Calls AllocateCommandBuffers
7416 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7417
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007418 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007419 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007420 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7421 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007422 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7423 cmd_buf_info.pNext = NULL;
7424 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007425 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007426
7427 // Begin CB to transition to recording state
7428 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7429 // Can't re-begin. This should trigger error
7430 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007431 m_errorMonitor->VerifyFound();
7432
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007434 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007435 // Reset attempt will trigger error due to incorrect CommandPool state
7436 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007437 m_errorMonitor->VerifyFound();
7438
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007440 // Transition CB to RECORDED state
7441 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7442 // Now attempting to Begin will implicitly reset, which triggers error
7443 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007444 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007445}
7446
Karl Schultz6addd812016-02-02 17:17:23 -07007447TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007448 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007449 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007450
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7452 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007453
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007454 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007456
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007457 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007458 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7459 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007460
7461 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007462 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7463 ds_pool_ci.pNext = NULL;
7464 ds_pool_ci.maxSets = 1;
7465 ds_pool_ci.poolSizeCount = 1;
7466 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007467
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007468 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007469 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007470 ASSERT_VK_SUCCESS(err);
7471
Tony Barboureb254902015-07-15 12:50:33 -06007472 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007473 dsl_binding.binding = 0;
7474 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7475 dsl_binding.descriptorCount = 1;
7476 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7477 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007478
Tony Barboureb254902015-07-15 12:50:33 -06007479 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007480 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7481 ds_layout_ci.pNext = NULL;
7482 ds_layout_ci.bindingCount = 1;
7483 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007484
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007485 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007487 ASSERT_VK_SUCCESS(err);
7488
7489 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007490 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007491 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007492 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007493 alloc_info.descriptorPool = ds_pool;
7494 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007495 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007496 ASSERT_VK_SUCCESS(err);
7497
Tony Barboureb254902015-07-15 12:50:33 -06007498 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007499 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7500 pipeline_layout_ci.setLayoutCount = 1;
7501 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007502
7503 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007504 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007505 ASSERT_VK_SUCCESS(err);
7506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007507 VkViewport vp = {}; // Just need dummy vp to point to
7508 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007509
7510 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007511 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7512 vp_state_ci.scissorCount = 1;
7513 vp_state_ci.pScissors = &sc;
7514 vp_state_ci.viewportCount = 1;
7515 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007516
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007517 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7518 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7519 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7520 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7521 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7522 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007523 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007524 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007525 rs_state_ci.lineWidth = 1.0f;
7526
7527 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7528 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7529 vi_ci.pNext = nullptr;
7530 vi_ci.vertexBindingDescriptionCount = 0;
7531 vi_ci.pVertexBindingDescriptions = nullptr;
7532 vi_ci.vertexAttributeDescriptionCount = 0;
7533 vi_ci.pVertexAttributeDescriptions = nullptr;
7534
7535 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7536 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7537 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7538
7539 VkPipelineShaderStageCreateInfo shaderStages[2];
7540 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7541
7542 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7543 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007544 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007545 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007546
Tony Barboureb254902015-07-15 12:50:33 -06007547 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007548 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7549 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007550 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007551 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7552 gp_ci.layout = pipeline_layout;
7553 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007554 gp_ci.pVertexInputState = &vi_ci;
7555 gp_ci.pInputAssemblyState = &ia_ci;
7556
7557 gp_ci.stageCount = 1;
7558 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007559
7560 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007561 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7562 pc_ci.initialDataSize = 0;
7563 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007564
7565 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007566 VkPipelineCache pipelineCache;
7567
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007568 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007569 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007570 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007571 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007572
Chia-I Wuf7458c52015-10-26 21:10:41 +08007573 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7574 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007577}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007578
Tobin Ehlis912df022015-09-17 08:46:18 -06007579/*// TODO : This test should be good, but needs Tess support in compiler to run
7580TEST_F(VkLayerTest, InvalidPatchControlPoints)
7581{
7582 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007583 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007584
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007586 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7587primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007588
Tobin Ehlis912df022015-09-17 08:46:18 -06007589 ASSERT_NO_FATAL_FAILURE(InitState());
7590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007591
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007592 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007593 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007594 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007595
7596 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7597 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7598 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007599 ds_pool_ci.poolSizeCount = 1;
7600 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007601
7602 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007603 err = vkCreateDescriptorPool(m_device->device(),
7604VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 ASSERT_VK_SUCCESS(err);
7606
7607 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007608 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007609 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007610 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007611 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7612 dsl_binding.pImmutableSamplers = NULL;
7613
7614 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007615 ds_layout_ci.sType =
7616VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007617 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007618 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007619 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007620
7621 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007622 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7623&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007624 ASSERT_VK_SUCCESS(err);
7625
7626 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007627 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7628VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007629 ASSERT_VK_SUCCESS(err);
7630
7631 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007632 pipeline_layout_ci.sType =
7633VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007634 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007635 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007636 pipeline_layout_ci.pSetLayouts = &ds_layout;
7637
7638 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007639 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7640&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007641 ASSERT_VK_SUCCESS(err);
7642
7643 VkPipelineShaderStageCreateInfo shaderStages[3];
7644 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7645
Karl Schultz6addd812016-02-02 17:17:23 -07007646 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7647this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007648 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007649 VkShaderObj
7650tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7651this);
7652 VkShaderObj
7653te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7654this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007655
Karl Schultz6addd812016-02-02 17:17:23 -07007656 shaderStages[0].sType =
7657VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007658 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007659 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007660 shaderStages[1].sType =
7661VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007662 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007663 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007664 shaderStages[2].sType =
7665VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007666 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007667 shaderStages[2].shader = te.handle();
7668
7669 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007670 iaCI.sType =
7671VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007672 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007673
7674 VkPipelineTessellationStateCreateInfo tsCI = {};
7675 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7676 tsCI.patchControlPoints = 0; // This will cause an error
7677
7678 VkGraphicsPipelineCreateInfo gp_ci = {};
7679 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7680 gp_ci.pNext = NULL;
7681 gp_ci.stageCount = 3;
7682 gp_ci.pStages = shaderStages;
7683 gp_ci.pVertexInputState = NULL;
7684 gp_ci.pInputAssemblyState = &iaCI;
7685 gp_ci.pTessellationState = &tsCI;
7686 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007687 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007688 gp_ci.pMultisampleState = NULL;
7689 gp_ci.pDepthStencilState = NULL;
7690 gp_ci.pColorBlendState = NULL;
7691 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7692 gp_ci.layout = pipeline_layout;
7693 gp_ci.renderPass = renderPass();
7694
7695 VkPipelineCacheCreateInfo pc_ci = {};
7696 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7697 pc_ci.pNext = NULL;
7698 pc_ci.initialSize = 0;
7699 pc_ci.initialData = 0;
7700 pc_ci.maxSize = 0;
7701
7702 VkPipeline pipeline;
7703 VkPipelineCache pipelineCache;
7704
Karl Schultz6addd812016-02-02 17:17:23 -07007705 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7706&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007707 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007708 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7709&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007710
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007711 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007712
Chia-I Wuf7458c52015-10-26 21:10:41 +08007713 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7714 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7716 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007717}
7718*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007719
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007720TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007721 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007722
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007723 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007724
Tobin Ehlise68360f2015-10-01 11:15:13 -06007725 ASSERT_NO_FATAL_FAILURE(InitState());
7726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007727
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007728 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007729 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7730 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007731
7732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7734 ds_pool_ci.maxSets = 1;
7735 ds_pool_ci.poolSizeCount = 1;
7736 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007737
7738 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007739 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007740 ASSERT_VK_SUCCESS(err);
7741
7742 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007743 dsl_binding.binding = 0;
7744 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7745 dsl_binding.descriptorCount = 1;
7746 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007747
7748 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007749 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7750 ds_layout_ci.bindingCount = 1;
7751 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007752
7753 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007754 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007755 ASSERT_VK_SUCCESS(err);
7756
7757 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007758 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007759 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007760 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007761 alloc_info.descriptorPool = ds_pool;
7762 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007763 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007764 ASSERT_VK_SUCCESS(err);
7765
7766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7768 pipeline_layout_ci.setLayoutCount = 1;
7769 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007770
7771 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007773 ASSERT_VK_SUCCESS(err);
7774
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007775 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007776 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007777 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007778 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007779 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007780 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007781
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007782 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7783 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7784 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7785 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7786 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7787 rs_state_ci.depthClampEnable = VK_FALSE;
7788 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7789 rs_state_ci.depthBiasEnable = VK_FALSE;
7790
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007791 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7792 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7793 vi_ci.pNext = nullptr;
7794 vi_ci.vertexBindingDescriptionCount = 0;
7795 vi_ci.pVertexBindingDescriptions = nullptr;
7796 vi_ci.vertexAttributeDescriptionCount = 0;
7797 vi_ci.pVertexAttributeDescriptions = nullptr;
7798
7799 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7800 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7801 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7802
7803 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7804 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7805 pipe_ms_state_ci.pNext = NULL;
7806 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7807 pipe_ms_state_ci.sampleShadingEnable = 0;
7808 pipe_ms_state_ci.minSampleShading = 1.0;
7809 pipe_ms_state_ci.pSampleMask = NULL;
7810
Cody Northropeb3a6c12015-10-05 14:44:45 -06007811 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007812 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007814 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007815 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007816 shaderStages[0] = vs.GetStageCreateInfo();
7817 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007818
7819 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007820 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7821 gp_ci.stageCount = 2;
7822 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007823 gp_ci.pVertexInputState = &vi_ci;
7824 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007825 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007826 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007827 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007828 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7829 gp_ci.layout = pipeline_layout;
7830 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007831
7832 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007833 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007834
7835 VkPipeline pipeline;
7836 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007837 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007838 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007839
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007840 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007841 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007842
7843 // Check case where multiViewport is disabled and viewport count is not 1
7844 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7847 vp_state_ci.scissorCount = 0;
7848 vp_state_ci.viewportCount = 0;
7849 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7850 m_errorMonitor->VerifyFound();
7851 } else {
7852 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007853 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007854 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007855 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007856
7857 // Check is that viewportcount and scissorcount match
7858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7859 vp_state_ci.scissorCount = 1;
7860 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7861 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7862 m_errorMonitor->VerifyFound();
7863
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007864 // Check case where multiViewport is enabled and viewport count is greater than max
7865 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7868 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7869 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7870 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7871 m_errorMonitor->VerifyFound();
7872 }
7873 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007874
Chia-I Wuf7458c52015-10-26 21:10:41 +08007875 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7876 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7877 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7878 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007879}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007880
7881// 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
7882// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007883TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007884 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007885
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007886 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7887
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007889
Tobin Ehlise68360f2015-10-01 11:15:13 -06007890 ASSERT_NO_FATAL_FAILURE(InitState());
7891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007892
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007893 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007894 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7895 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007896
7897 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007898 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7899 ds_pool_ci.maxSets = 1;
7900 ds_pool_ci.poolSizeCount = 1;
7901 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007902
7903 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007904 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007905 ASSERT_VK_SUCCESS(err);
7906
7907 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007908 dsl_binding.binding = 0;
7909 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7910 dsl_binding.descriptorCount = 1;
7911 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007912
7913 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007914 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7915 ds_layout_ci.bindingCount = 1;
7916 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007917
7918 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007919 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007920 ASSERT_VK_SUCCESS(err);
7921
7922 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007923 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007924 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007925 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007926 alloc_info.descriptorPool = ds_pool;
7927 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007928 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007929 ASSERT_VK_SUCCESS(err);
7930
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007931 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7932 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7933 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7934
7935 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7936 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7937 vi_ci.pNext = nullptr;
7938 vi_ci.vertexBindingDescriptionCount = 0;
7939 vi_ci.pVertexBindingDescriptions = nullptr;
7940 vi_ci.vertexAttributeDescriptionCount = 0;
7941 vi_ci.pVertexAttributeDescriptions = nullptr;
7942
7943 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7944 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7945 pipe_ms_state_ci.pNext = NULL;
7946 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7947 pipe_ms_state_ci.sampleShadingEnable = 0;
7948 pipe_ms_state_ci.minSampleShading = 1.0;
7949 pipe_ms_state_ci.pSampleMask = NULL;
7950
Tobin Ehlise68360f2015-10-01 11:15:13 -06007951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7953 pipeline_layout_ci.setLayoutCount = 1;
7954 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007955
7956 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007957 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007958 ASSERT_VK_SUCCESS(err);
7959
7960 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7961 // Set scissor as dynamic to avoid second error
7962 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007963 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7964 dyn_state_ci.dynamicStateCount = 1;
7965 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007966
Cody Northropeb3a6c12015-10-05 14:44:45 -06007967 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007968 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007970 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007971 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7972 // 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 +08007973 shaderStages[0] = vs.GetStageCreateInfo();
7974 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007976 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7977 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7978 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7979 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7980 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7981 rs_state_ci.depthClampEnable = VK_FALSE;
7982 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7983 rs_state_ci.depthBiasEnable = VK_FALSE;
7984
Tobin Ehlise68360f2015-10-01 11:15:13 -06007985 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007986 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7987 gp_ci.stageCount = 2;
7988 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007989 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007990 // Not setting VP state w/o dynamic vp state should cause validation error
7991 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007992 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007993 gp_ci.pVertexInputState = &vi_ci;
7994 gp_ci.pInputAssemblyState = &ia_ci;
7995 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007996 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7997 gp_ci.layout = pipeline_layout;
7998 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007999
8000 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008001 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008002
8003 VkPipeline pipeline;
8004 VkPipelineCache pipelineCache;
8005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008006 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008007 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008008 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008009
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008010 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008011
Chia-I Wuf7458c52015-10-26 21:10:41 +08008012 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8013 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8014 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8015 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008016}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008017
8018// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8019// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008020TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8021 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008022
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008024
Tobin Ehlise68360f2015-10-01 11:15:13 -06008025 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008026
8027 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008028 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008029 return;
8030 }
8031
Tobin Ehlise68360f2015-10-01 11:15:13 -06008032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008033
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008034 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008035 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8036 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008037
8038 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008039 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8040 ds_pool_ci.maxSets = 1;
8041 ds_pool_ci.poolSizeCount = 1;
8042 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008043
8044 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008045 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008046 ASSERT_VK_SUCCESS(err);
8047
8048 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008049 dsl_binding.binding = 0;
8050 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8051 dsl_binding.descriptorCount = 1;
8052 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008053
8054 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008055 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8056 ds_layout_ci.bindingCount = 1;
8057 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008058
8059 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008061 ASSERT_VK_SUCCESS(err);
8062
8063 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008064 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008065 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008066 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008067 alloc_info.descriptorPool = ds_pool;
8068 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008069 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008070 ASSERT_VK_SUCCESS(err);
8071
8072 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008073 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8074 pipeline_layout_ci.setLayoutCount = 1;
8075 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008076
8077 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008078 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008079 ASSERT_VK_SUCCESS(err);
8080
8081 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008082 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8083 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008084 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008085 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008086 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008087
8088 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8089 // Set scissor as dynamic to avoid that error
8090 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008091 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8092 dyn_state_ci.dynamicStateCount = 1;
8093 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008094
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008095 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8096 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8097 pipe_ms_state_ci.pNext = NULL;
8098 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8099 pipe_ms_state_ci.sampleShadingEnable = 0;
8100 pipe_ms_state_ci.minSampleShading = 1.0;
8101 pipe_ms_state_ci.pSampleMask = NULL;
8102
Cody Northropeb3a6c12015-10-05 14:44:45 -06008103 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008104 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008106 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008107 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8108 // 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 +08008109 shaderStages[0] = vs.GetStageCreateInfo();
8110 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008111
Cody Northropf6622dc2015-10-06 10:33:21 -06008112 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8113 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8114 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008115 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008116 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008117 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008118 vi_ci.pVertexAttributeDescriptions = nullptr;
8119
8120 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8121 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8122 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8123
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008124 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008125 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008126 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008127 rs_ci.pNext = nullptr;
8128
Mark Youngc89c6312016-03-31 16:03:20 -06008129 VkPipelineColorBlendAttachmentState att = {};
8130 att.blendEnable = VK_FALSE;
8131 att.colorWriteMask = 0xf;
8132
Cody Northropf6622dc2015-10-06 10:33:21 -06008133 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8134 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8135 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008136 cb_ci.attachmentCount = 1;
8137 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008138
Tobin Ehlise68360f2015-10-01 11:15:13 -06008139 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008140 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8141 gp_ci.stageCount = 2;
8142 gp_ci.pStages = shaderStages;
8143 gp_ci.pVertexInputState = &vi_ci;
8144 gp_ci.pInputAssemblyState = &ia_ci;
8145 gp_ci.pViewportState = &vp_state_ci;
8146 gp_ci.pRasterizationState = &rs_ci;
8147 gp_ci.pColorBlendState = &cb_ci;
8148 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008149 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008150 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8151 gp_ci.layout = pipeline_layout;
8152 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008153
8154 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008155 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008156
8157 VkPipeline pipeline;
8158 VkPipelineCache pipelineCache;
8159
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008160 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008161 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008162 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008164 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008165
Tobin Ehlisd332f282015-10-02 11:00:56 -06008166 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008167 // First need to successfully create the PSO from above by setting
8168 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008169 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 -07008170
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008171 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008172 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008174 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008175 m_commandBuffer->BeginCommandBuffer();
8176 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008177 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008178 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008179 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008180 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008181 Draw(1, 0, 0, 0);
8182
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008183 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008184
8185 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8186 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8187 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8188 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008189 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008190}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008191
8192// 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 -07008193// viewportCount
8194TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8195 VkResult err;
8196
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008198
8199 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008200
8201 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008202 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008203 return;
8204 }
8205
Karl Schultz6addd812016-02-02 17:17:23 -07008206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8207
8208 VkDescriptorPoolSize ds_type_count = {};
8209 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8210 ds_type_count.descriptorCount = 1;
8211
8212 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8213 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8214 ds_pool_ci.maxSets = 1;
8215 ds_pool_ci.poolSizeCount = 1;
8216 ds_pool_ci.pPoolSizes = &ds_type_count;
8217
8218 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008219 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008220 ASSERT_VK_SUCCESS(err);
8221
8222 VkDescriptorSetLayoutBinding dsl_binding = {};
8223 dsl_binding.binding = 0;
8224 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8225 dsl_binding.descriptorCount = 1;
8226 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8227
8228 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8229 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8230 ds_layout_ci.bindingCount = 1;
8231 ds_layout_ci.pBindings = &dsl_binding;
8232
8233 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008234 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008235 ASSERT_VK_SUCCESS(err);
8236
8237 VkDescriptorSet descriptorSet;
8238 VkDescriptorSetAllocateInfo alloc_info = {};
8239 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8240 alloc_info.descriptorSetCount = 1;
8241 alloc_info.descriptorPool = ds_pool;
8242 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008243 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008244 ASSERT_VK_SUCCESS(err);
8245
8246 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8247 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8248 pipeline_layout_ci.setLayoutCount = 1;
8249 pipeline_layout_ci.pSetLayouts = &ds_layout;
8250
8251 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008252 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008253 ASSERT_VK_SUCCESS(err);
8254
8255 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8256 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8257 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008258 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008259 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008260 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008261
8262 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8263 // Set scissor as dynamic to avoid that error
8264 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8265 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8266 dyn_state_ci.dynamicStateCount = 1;
8267 dyn_state_ci.pDynamicStates = &vp_state;
8268
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008269 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8270 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8271 pipe_ms_state_ci.pNext = NULL;
8272 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8273 pipe_ms_state_ci.sampleShadingEnable = 0;
8274 pipe_ms_state_ci.minSampleShading = 1.0;
8275 pipe_ms_state_ci.pSampleMask = NULL;
8276
Karl Schultz6addd812016-02-02 17:17:23 -07008277 VkPipelineShaderStageCreateInfo shaderStages[2];
8278 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8279
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008281 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8282 // 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 -07008283 shaderStages[0] = vs.GetStageCreateInfo();
8284 shaderStages[1] = fs.GetStageCreateInfo();
8285
8286 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8287 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8288 vi_ci.pNext = nullptr;
8289 vi_ci.vertexBindingDescriptionCount = 0;
8290 vi_ci.pVertexBindingDescriptions = nullptr;
8291 vi_ci.vertexAttributeDescriptionCount = 0;
8292 vi_ci.pVertexAttributeDescriptions = nullptr;
8293
8294 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8295 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8296 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8297
8298 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8299 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008300 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008301 rs_ci.pNext = nullptr;
8302
Mark Youngc89c6312016-03-31 16:03:20 -06008303 VkPipelineColorBlendAttachmentState att = {};
8304 att.blendEnable = VK_FALSE;
8305 att.colorWriteMask = 0xf;
8306
Karl Schultz6addd812016-02-02 17:17:23 -07008307 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8308 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8309 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008310 cb_ci.attachmentCount = 1;
8311 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008312
8313 VkGraphicsPipelineCreateInfo gp_ci = {};
8314 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8315 gp_ci.stageCount = 2;
8316 gp_ci.pStages = shaderStages;
8317 gp_ci.pVertexInputState = &vi_ci;
8318 gp_ci.pInputAssemblyState = &ia_ci;
8319 gp_ci.pViewportState = &vp_state_ci;
8320 gp_ci.pRasterizationState = &rs_ci;
8321 gp_ci.pColorBlendState = &cb_ci;
8322 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008323 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008324 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8325 gp_ci.layout = pipeline_layout;
8326 gp_ci.renderPass = renderPass();
8327
8328 VkPipelineCacheCreateInfo pc_ci = {};
8329 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8330
8331 VkPipeline pipeline;
8332 VkPipelineCache pipelineCache;
8333
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008334 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008335 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008336 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008337
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008338 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008339
8340 // Now hit second fail case where we set scissor w/ different count than PSO
8341 // First need to successfully create the PSO from above by setting
8342 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8344 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008345
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008346 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008347 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008349 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008350 m_commandBuffer->BeginCommandBuffer();
8351 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008352 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008353 VkViewport viewports[1] = {};
8354 viewports[0].width = 8;
8355 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008356 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008357 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008358 Draw(1, 0, 0, 0);
8359
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008360 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008361
Chia-I Wuf7458c52015-10-26 21:10:41 +08008362 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8363 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8364 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8365 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008366 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008367}
8368
Mark Young7394fdd2016-03-31 14:56:43 -06008369TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8370 VkResult err;
8371
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008373
8374 ASSERT_NO_FATAL_FAILURE(InitState());
8375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8376
8377 VkDescriptorPoolSize ds_type_count = {};
8378 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8379 ds_type_count.descriptorCount = 1;
8380
8381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8383 ds_pool_ci.maxSets = 1;
8384 ds_pool_ci.poolSizeCount = 1;
8385 ds_pool_ci.pPoolSizes = &ds_type_count;
8386
8387 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008388 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008389 ASSERT_VK_SUCCESS(err);
8390
8391 VkDescriptorSetLayoutBinding dsl_binding = {};
8392 dsl_binding.binding = 0;
8393 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8394 dsl_binding.descriptorCount = 1;
8395 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8396
8397 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8398 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8399 ds_layout_ci.bindingCount = 1;
8400 ds_layout_ci.pBindings = &dsl_binding;
8401
8402 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008404 ASSERT_VK_SUCCESS(err);
8405
8406 VkDescriptorSet descriptorSet;
8407 VkDescriptorSetAllocateInfo alloc_info = {};
8408 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8409 alloc_info.descriptorSetCount = 1;
8410 alloc_info.descriptorPool = ds_pool;
8411 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008412 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008413 ASSERT_VK_SUCCESS(err);
8414
8415 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8416 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8417 pipeline_layout_ci.setLayoutCount = 1;
8418 pipeline_layout_ci.pSetLayouts = &ds_layout;
8419
8420 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008421 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008422 ASSERT_VK_SUCCESS(err);
8423
8424 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8425 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8426 vp_state_ci.scissorCount = 1;
8427 vp_state_ci.pScissors = NULL;
8428 vp_state_ci.viewportCount = 1;
8429 vp_state_ci.pViewports = NULL;
8430
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008431 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008432 // Set scissor as dynamic to avoid that error
8433 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8434 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8435 dyn_state_ci.dynamicStateCount = 2;
8436 dyn_state_ci.pDynamicStates = dynamic_states;
8437
8438 VkPipelineShaderStageCreateInfo shaderStages[2];
8439 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008441 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8442 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008443 this); // TODO - We shouldn't need a fragment shader
8444 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008445 shaderStages[0] = vs.GetStageCreateInfo();
8446 shaderStages[1] = fs.GetStageCreateInfo();
8447
8448 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8449 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8450 vi_ci.pNext = nullptr;
8451 vi_ci.vertexBindingDescriptionCount = 0;
8452 vi_ci.pVertexBindingDescriptions = nullptr;
8453 vi_ci.vertexAttributeDescriptionCount = 0;
8454 vi_ci.pVertexAttributeDescriptions = nullptr;
8455
8456 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8457 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8458 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8459
8460 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8461 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8462 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008463 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008464
Mark Young47107952016-05-02 15:59:55 -06008465 // Check too low (line width of -1.0f).
8466 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008467
8468 VkPipelineColorBlendAttachmentState att = {};
8469 att.blendEnable = VK_FALSE;
8470 att.colorWriteMask = 0xf;
8471
8472 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8473 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8474 cb_ci.pNext = nullptr;
8475 cb_ci.attachmentCount = 1;
8476 cb_ci.pAttachments = &att;
8477
8478 VkGraphicsPipelineCreateInfo gp_ci = {};
8479 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8480 gp_ci.stageCount = 2;
8481 gp_ci.pStages = shaderStages;
8482 gp_ci.pVertexInputState = &vi_ci;
8483 gp_ci.pInputAssemblyState = &ia_ci;
8484 gp_ci.pViewportState = &vp_state_ci;
8485 gp_ci.pRasterizationState = &rs_ci;
8486 gp_ci.pColorBlendState = &cb_ci;
8487 gp_ci.pDynamicState = &dyn_state_ci;
8488 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8489 gp_ci.layout = pipeline_layout;
8490 gp_ci.renderPass = renderPass();
8491
8492 VkPipelineCacheCreateInfo pc_ci = {};
8493 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8494
8495 VkPipeline pipeline;
8496 VkPipelineCache pipelineCache;
8497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008498 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008499 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008500 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008501
8502 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008503 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008504
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008506
8507 // Check too high (line width of 65536.0f).
8508 rs_ci.lineWidth = 65536.0f;
8509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008510 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008511 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008512 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008513
8514 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008515 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008516
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008518
8519 dyn_state_ci.dynamicStateCount = 3;
8520
8521 rs_ci.lineWidth = 1.0f;
8522
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008523 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008524 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008525 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008526 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008527 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008528
8529 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008530 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008531 m_errorMonitor->VerifyFound();
8532
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008534
8535 // Check too high with dynamic setting.
8536 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8537 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008538 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008539
8540 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8541 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8543 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008544 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008545}
8546
Karl Schultz6addd812016-02-02 17:17:23 -07008547TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008548 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008550 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008551
8552 ASSERT_NO_FATAL_FAILURE(InitState());
8553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008554
Tony Barbour552f6c02016-12-21 14:34:07 -07008555 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008556 // Don't care about RenderPass handle b/c error should be flagged before
8557 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008558 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008559
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008560 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008561}
8562
Karl Schultz6addd812016-02-02 17:17:23 -07008563TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008564 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8566 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008567
8568 ASSERT_NO_FATAL_FAILURE(InitState());
8569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008570
Tony Barbour552f6c02016-12-21 14:34:07 -07008571 m_commandBuffer->BeginCommandBuffer();
8572 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008573 // Just create a dummy Renderpass that's non-NULL so we can get to the
8574 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008575 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008576
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008577 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008578}
8579
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008580TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008581 TEST_DESCRIPTION(
8582 "Begin a renderPass where clearValueCount is less than"
8583 "the number of renderPass attachments that use loadOp"
8584 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008585
8586 ASSERT_NO_FATAL_FAILURE(InitState());
8587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8588
8589 // Create a renderPass with a single attachment that uses loadOp CLEAR
8590 VkAttachmentReference attach = {};
8591 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8592 VkSubpassDescription subpass = {};
8593 subpass.inputAttachmentCount = 1;
8594 subpass.pInputAttachments = &attach;
8595 VkRenderPassCreateInfo rpci = {};
8596 rpci.subpassCount = 1;
8597 rpci.pSubpasses = &subpass;
8598 rpci.attachmentCount = 1;
8599 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008600 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008601 // Set loadOp to CLEAR
8602 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8603 rpci.pAttachments = &attach_desc;
8604 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8605 VkRenderPass rp;
8606 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8607
8608 VkCommandBufferInheritanceInfo hinfo = {};
8609 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8610 hinfo.renderPass = VK_NULL_HANDLE;
8611 hinfo.subpass = 0;
8612 hinfo.framebuffer = VK_NULL_HANDLE;
8613 hinfo.occlusionQueryEnable = VK_FALSE;
8614 hinfo.queryFlags = 0;
8615 hinfo.pipelineStatistics = 0;
8616 VkCommandBufferBeginInfo info = {};
8617 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8618 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8619 info.pInheritanceInfo = &hinfo;
8620
8621 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8622 VkRenderPassBeginInfo rp_begin = {};
8623 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8624 rp_begin.pNext = NULL;
8625 rp_begin.renderPass = renderPass();
8626 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008627 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008628
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008630
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008631 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008632
8633 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008634
8635 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008636}
8637
Slawomir Cygan0808f392016-11-28 17:53:23 +01008638TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008639 TEST_DESCRIPTION(
8640 "Begin a renderPass where clearValueCount is greater than"
8641 "the number of renderPass attachments that use loadOp"
8642 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008643
8644 ASSERT_NO_FATAL_FAILURE(InitState());
8645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8646
8647 // Create a renderPass with a single attachment that uses loadOp CLEAR
8648 VkAttachmentReference attach = {};
8649 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8650 VkSubpassDescription subpass = {};
8651 subpass.inputAttachmentCount = 1;
8652 subpass.pInputAttachments = &attach;
8653 VkRenderPassCreateInfo rpci = {};
8654 rpci.subpassCount = 1;
8655 rpci.pSubpasses = &subpass;
8656 rpci.attachmentCount = 1;
8657 VkAttachmentDescription attach_desc = {};
8658 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8659 // Set loadOp to CLEAR
8660 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8661 rpci.pAttachments = &attach_desc;
8662 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8663 VkRenderPass rp;
8664 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8665
8666 VkCommandBufferBeginInfo info = {};
8667 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8668 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8669
8670 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8671 VkRenderPassBeginInfo rp_begin = {};
8672 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8673 rp_begin.pNext = NULL;
8674 rp_begin.renderPass = renderPass();
8675 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008676 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008677
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8679 " has a clearValueCount of"
8680 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008681
8682 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8683
8684 m_errorMonitor->VerifyFound();
8685
8686 vkDestroyRenderPass(m_device->device(), rp, NULL);
8687}
8688
Cody Northrop3bb4d962016-05-09 16:15:57 -06008689TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008690 TEST_DESCRIPTION("End a command buffer with an active render pass");
8691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8693 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008694
8695 ASSERT_NO_FATAL_FAILURE(InitState());
8696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8697
Tony Barbour552f6c02016-12-21 14:34:07 -07008698 m_commandBuffer->BeginCommandBuffer();
8699 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8700 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008701
8702 m_errorMonitor->VerifyFound();
8703
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008704 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8705 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008706}
8707
Karl Schultz6addd812016-02-02 17:17:23 -07008708TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008709 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8711 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008712
8713 ASSERT_NO_FATAL_FAILURE(InitState());
8714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008715
Tony Barbour552f6c02016-12-21 14:34:07 -07008716 m_commandBuffer->BeginCommandBuffer();
8717 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008718
8719 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008720 vk_testing::Buffer dstBuffer;
8721 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008722
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008723 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008724
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008725 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008726}
8727
Karl Schultz6addd812016-02-02 17:17:23 -07008728TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008729 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8731 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008732
8733 ASSERT_NO_FATAL_FAILURE(InitState());
8734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008735
Tony Barbour552f6c02016-12-21 14:34:07 -07008736 m_commandBuffer->BeginCommandBuffer();
8737 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008738
8739 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008740 vk_testing::Buffer dstBuffer;
8741 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008742
Karl Schultz6addd812016-02-02 17:17:23 -07008743 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008744 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8745 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8746 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008747
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008748 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008749}
8750
Karl Schultz6addd812016-02-02 17:17:23 -07008751TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008752 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8754 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008755
8756 ASSERT_NO_FATAL_FAILURE(InitState());
8757 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008758
Tony Barbour552f6c02016-12-21 14:34:07 -07008759 m_commandBuffer->BeginCommandBuffer();
8760 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008761
Michael Lentine0a369f62016-02-03 16:51:46 -06008762 VkClearColorValue clear_color;
8763 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008764 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8765 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8766 const int32_t tex_width = 32;
8767 const int32_t tex_height = 32;
8768 VkImageCreateInfo image_create_info = {};
8769 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8770 image_create_info.pNext = NULL;
8771 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8772 image_create_info.format = tex_format;
8773 image_create_info.extent.width = tex_width;
8774 image_create_info.extent.height = tex_height;
8775 image_create_info.extent.depth = 1;
8776 image_create_info.mipLevels = 1;
8777 image_create_info.arrayLayers = 1;
8778 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8779 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8780 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008781
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008782 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008783 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008785 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008786
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008787 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008788 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008789
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008790 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008791}
8792
Karl Schultz6addd812016-02-02 17:17:23 -07008793TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008794 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8796 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008797
8798 ASSERT_NO_FATAL_FAILURE(InitState());
8799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008800
Tony Barbour552f6c02016-12-21 14:34:07 -07008801 m_commandBuffer->BeginCommandBuffer();
8802 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008803
8804 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008805 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008806 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8807 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8808 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8809 image_create_info.extent.width = 64;
8810 image_create_info.extent.height = 64;
8811 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8812 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008813
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008814 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008815 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008816
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008817 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008818
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008819 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8820 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008821
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008822 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008823}
8824
Karl Schultz6addd812016-02-02 17:17:23 -07008825TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008826 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008827 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008828
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8830 "vkCmdClearAttachments(): This call "
8831 "must be issued inside an active "
8832 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008833
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008834 ASSERT_NO_FATAL_FAILURE(InitState());
8835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008836
8837 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008838 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008839 ASSERT_VK_SUCCESS(err);
8840
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008841 VkClearAttachment color_attachment;
8842 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8843 color_attachment.clearValue.color.float32[0] = 0;
8844 color_attachment.clearValue.color.float32[1] = 0;
8845 color_attachment.clearValue.color.float32[2] = 0;
8846 color_attachment.clearValue.color.float32[3] = 0;
8847 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008848 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008849 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008850
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008851 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008852}
8853
Chris Forbes3b97e932016-09-07 11:29:24 +12008854TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008855 TEST_DESCRIPTION(
8856 "Test that an error is produced when CmdNextSubpass is "
8857 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008858
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8860 "vkCmdNextSubpass(): Attempted to advance "
8861 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008862
8863 ASSERT_NO_FATAL_FAILURE(InitState());
8864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8865
Tony Barbour552f6c02016-12-21 14:34:07 -07008866 m_commandBuffer->BeginCommandBuffer();
8867 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008868
8869 // error here.
8870 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8871 m_errorMonitor->VerifyFound();
8872
Tony Barbour552f6c02016-12-21 14:34:07 -07008873 m_commandBuffer->EndRenderPass();
8874 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008875}
8876
Chris Forbes6d624702016-09-07 13:57:05 +12008877TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008878 TEST_DESCRIPTION(
8879 "Test that an error is produced when CmdEndRenderPass is "
8880 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008881
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8883 "vkCmdEndRenderPass(): Called before reaching "
8884 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008885
8886 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008887 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8888 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008890 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008891
8892 VkRenderPass rp;
8893 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8894 ASSERT_VK_SUCCESS(err);
8895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008896 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008897
8898 VkFramebuffer fb;
8899 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8900 ASSERT_VK_SUCCESS(err);
8901
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008902 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008904 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 +12008905
8906 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8907
8908 // Error here.
8909 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8910 m_errorMonitor->VerifyFound();
8911
8912 // Clean up.
8913 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8914 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8915}
8916
Karl Schultz9e66a292016-04-21 15:57:51 -06008917TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8918 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8920 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008921
8922 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008923 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008924
8925 VkBufferMemoryBarrier buf_barrier = {};
8926 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8927 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8928 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8929 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8930 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8931 buf_barrier.buffer = VK_NULL_HANDLE;
8932 buf_barrier.offset = 0;
8933 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8935 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008936
8937 m_errorMonitor->VerifyFound();
8938}
8939
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008940TEST_F(VkLayerTest, InvalidBarriers) {
8941 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8942
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008944
8945 ASSERT_NO_FATAL_FAILURE(InitState());
8946 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8947
8948 VkMemoryBarrier mem_barrier = {};
8949 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8950 mem_barrier.pNext = NULL;
8951 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8952 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008953 m_commandBuffer->BeginCommandBuffer();
8954 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008955 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008957 &mem_barrier, 0, nullptr, 0, nullptr);
8958 m_errorMonitor->VerifyFound();
8959
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008961 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008962 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 -06008963 ASSERT_TRUE(image.initialized());
8964 VkImageMemoryBarrier img_barrier = {};
8965 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8966 img_barrier.pNext = NULL;
8967 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8968 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8969 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8970 // New layout can't be UNDEFINED
8971 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8972 img_barrier.image = image.handle();
8973 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8974 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8975 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8976 img_barrier.subresourceRange.baseArrayLayer = 0;
8977 img_barrier.subresourceRange.baseMipLevel = 0;
8978 img_barrier.subresourceRange.layerCount = 1;
8979 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008980 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8981 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008982 m_errorMonitor->VerifyFound();
8983 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8984
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8986 "Subresource must have the sum of the "
8987 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008988 // baseArrayLayer + layerCount must be <= image's arrayLayers
8989 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008990 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8991 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008992 m_errorMonitor->VerifyFound();
8993 img_barrier.subresourceRange.baseArrayLayer = 0;
8994
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008996 // baseMipLevel + levelCount must be <= image's mipLevels
8997 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008998 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8999 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009000 m_errorMonitor->VerifyFound();
9001 img_barrier.subresourceRange.baseMipLevel = 0;
9002
Mike Weiblen7053aa32017-01-25 15:21:10 -07009003 // levelCount must be non-zero.
9004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9005 img_barrier.subresourceRange.levelCount = 0;
9006 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9007 nullptr, 0, nullptr, 1, &img_barrier);
9008 m_errorMonitor->VerifyFound();
9009 img_barrier.subresourceRange.levelCount = 1;
9010
9011 // layerCount must be non-zero.
9012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
9013 img_barrier.subresourceRange.layerCount = 0;
9014 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9015 nullptr, 0, nullptr, 1, &img_barrier);
9016 m_errorMonitor->VerifyFound();
9017 img_barrier.subresourceRange.layerCount = 1;
9018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009019 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 -06009020 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009021 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9022 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009023 VkBufferMemoryBarrier buf_barrier = {};
9024 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9025 buf_barrier.pNext = NULL;
9026 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9027 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9028 buf_barrier.buffer = buffer.handle();
9029 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9030 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9031 buf_barrier.offset = 0;
9032 buf_barrier.size = VK_WHOLE_SIZE;
9033 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009034 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9035 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009036 m_errorMonitor->VerifyFound();
9037 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9038
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009040 buf_barrier.offset = 257;
9041 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009042 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9043 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009044 m_errorMonitor->VerifyFound();
9045 buf_barrier.offset = 0;
9046
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009048 buf_barrier.size = 257;
9049 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009050 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9051 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009052 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009053
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009054 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009055 m_errorMonitor->SetDesiredFailureMsg(
9056 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009057 "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 -06009058 VkDepthStencilObj ds_image(m_device);
9059 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9060 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009061 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9062 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009063 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009064
9065 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009066 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009067 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9068 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009069 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009070
9071 // Having anything other than DEPTH or STENCIL is an error
9072 m_errorMonitor->SetDesiredFailureMsg(
9073 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9074 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9075 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9076 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9077 nullptr, 0, nullptr, 1, &img_barrier);
9078 m_errorMonitor->VerifyFound();
9079
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009080 // Now test depth-only
9081 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009082 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9083 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009084 VkDepthStencilObj d_image(m_device);
9085 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9086 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009087 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009088 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009089 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009090
9091 // DEPTH bit must be set
9092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9093 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009094 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009095 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9096 0, nullptr, 0, nullptr, 1, &img_barrier);
9097 m_errorMonitor->VerifyFound();
9098
9099 // No bits other than DEPTH may be set
9100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9101 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9102 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009103 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9104 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009105 m_errorMonitor->VerifyFound();
9106 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009107
9108 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009109 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9110 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009111 VkDepthStencilObj s_image(m_device);
9112 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9113 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009114 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009115 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009116 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009117 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9119 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009120 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009121 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9122 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009123 m_errorMonitor->VerifyFound();
9124 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009125
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009126 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009127 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009128 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 -06009129 ASSERT_TRUE(c_image.initialized());
9130 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9131 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9132 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009133
9134 // COLOR bit must be set
9135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9136 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009137 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009138 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9139 nullptr, 0, nullptr, 1, &img_barrier);
9140 m_errorMonitor->VerifyFound();
9141
9142 // No bits other than COLOR may be set
9143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9144 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9145 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009146 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9147 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009148 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009149
9150 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9151
9152 // Create command pool with incompatible queueflags
9153 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9154 uint32_t queue_family_index = UINT32_MAX;
9155 for (uint32_t i = 0; i < queue_props.size(); i++) {
9156 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9157 queue_family_index = i;
9158 break;
9159 }
9160 }
9161 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009162 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009163 return;
9164 }
9165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9166
9167 VkCommandPool command_pool;
9168 VkCommandPoolCreateInfo pool_create_info{};
9169 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9170 pool_create_info.queueFamilyIndex = queue_family_index;
9171 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9172 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9173
9174 // Allocate a command buffer
9175 VkCommandBuffer bad_command_buffer;
9176 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9177 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9178 command_buffer_allocate_info.commandPool = command_pool;
9179 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9180 command_buffer_allocate_info.commandBufferCount = 1;
9181 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9182
9183 VkCommandBufferBeginInfo cbbi = {};
9184 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9185 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9186 buf_barrier.offset = 0;
9187 buf_barrier.size = VK_WHOLE_SIZE;
9188 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9189 &buf_barrier, 0, nullptr);
9190 m_errorMonitor->VerifyFound();
9191
9192 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9193 vkEndCommandBuffer(bad_command_buffer);
9194 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009195 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009196 return;
9197 }
9198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9199 VkEvent event;
9200 VkEventCreateInfo event_create_info{};
9201 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9202 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9203 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9204 nullptr, 0, nullptr);
9205 m_errorMonitor->VerifyFound();
9206
9207 vkEndCommandBuffer(bad_command_buffer);
9208 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009209}
9210
Tony Barbour18ba25c2016-09-29 13:42:40 -06009211TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9212 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9213
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009215 ASSERT_NO_FATAL_FAILURE(InitState());
9216 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009217 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 -06009218 ASSERT_TRUE(image.initialized());
9219
9220 VkImageMemoryBarrier barrier = {};
9221 VkImageSubresourceRange range;
9222 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9223 barrier.srcAccessMask = 0;
9224 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9225 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9226 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9227 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9228 barrier.image = image.handle();
9229 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9230 range.baseMipLevel = 0;
9231 range.levelCount = 1;
9232 range.baseArrayLayer = 0;
9233 range.layerCount = 1;
9234 barrier.subresourceRange = range;
9235 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9236 cmdbuf.BeginCommandBuffer();
9237 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9238 &barrier);
9239 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9240 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9241 barrier.srcAccessMask = 0;
9242 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9243 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9244 &barrier);
9245
9246 m_errorMonitor->VerifyFound();
9247}
9248
Karl Schultz6addd812016-02-02 17:17:23 -07009249TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009250 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009251 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009252
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009254
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009255 ASSERT_NO_FATAL_FAILURE(InitState());
9256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009257 uint32_t qfi = 0;
9258 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009259 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9260 buffCI.size = 1024;
9261 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9262 buffCI.queueFamilyIndexCount = 1;
9263 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009264
9265 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009266 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009267 ASSERT_VK_SUCCESS(err);
9268
Tony Barbour552f6c02016-12-21 14:34:07 -07009269 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009270 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009271 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9272 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009273 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009274 m_errorMonitor->SetUnexpectedError(
9275 "If buffer is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009276 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009277
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009278 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009279
Chia-I Wuf7458c52015-10-26 21:10:41 +08009280 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009281}
9282
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009283TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9284 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9286 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9287 "of the indices specified when the device was created, via the "
9288 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009289
9290 ASSERT_NO_FATAL_FAILURE(InitState());
9291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9292 VkBufferCreateInfo buffCI = {};
9293 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9294 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009295 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009296 buffCI.queueFamilyIndexCount = 1;
9297 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009298 uint32_t qfi[2];
9299 qfi[0] = 777;
9300
9301 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009302 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009303
9304 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009305 m_errorMonitor->SetUnexpectedError(
9306 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009307 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9308
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009309 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009310
9311 if (m_device->queue_props.size() > 2) {
9312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9313
9314 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9315 buffCI.queueFamilyIndexCount = 2;
9316 qfi[0] = 1;
9317 qfi[1] = 2;
9318 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9319 VkDeviceMemory mem;
9320 VkMemoryRequirements mem_reqs;
9321 vkGetBufferMemoryRequirements(m_device->device(), ib, &mem_reqs);
9322
9323 VkMemoryAllocateInfo alloc_info = {};
9324 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9325 alloc_info.allocationSize = 1024;
9326 bool pass = false;
9327 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9328 if (!pass) {
9329 vkDestroyBuffer(m_device->device(), ib, NULL);
9330 return;
9331 }
9332 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
9333 vkBindBufferMemory(m_device->device(), ib, mem, 0);
9334
9335 m_commandBuffer->begin();
9336 vkCmdFillBuffer(m_commandBuffer->handle(), ib, 0, 16, 5);
9337 m_commandBuffer->end();
9338 QueueCommandBuffer(false);
9339 m_errorMonitor->VerifyFound();
9340 }
9341
Tony Barbourdf4c0042016-06-01 15:55:43 -06009342 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009343}
9344
Karl Schultz6addd812016-02-02 17:17:23 -07009345TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009346 TEST_DESCRIPTION(
9347 "Attempt vkCmdExecuteCommands with a primary command buffer"
9348 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009349
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009350 ASSERT_NO_FATAL_FAILURE(InitState());
9351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009352
Chris Forbesf29a84f2016-10-06 18:39:28 +13009353 // An empty primary command buffer
9354 VkCommandBufferObj cb(m_device, m_commandPool);
9355 cb.BeginCommandBuffer();
9356 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009357
Chris Forbesf29a84f2016-10-06 18:39:28 +13009358 m_commandBuffer->BeginCommandBuffer();
9359 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9360 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009361
Chris Forbesf29a84f2016-10-06 18:39:28 +13009362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9363 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009364 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009365
9366 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009367}
9368
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009369TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009370 TEST_DESCRIPTION(
9371 "Attempt to update descriptor sets for images and buffers "
9372 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009373 VkResult err;
9374
9375 ASSERT_NO_FATAL_FAILURE(InitState());
9376 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9377 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9378 ds_type_count[i].type = VkDescriptorType(i);
9379 ds_type_count[i].descriptorCount = 1;
9380 }
9381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9383 ds_pool_ci.pNext = NULL;
9384 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9385 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9386 ds_pool_ci.pPoolSizes = ds_type_count;
9387
9388 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009389 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009390 ASSERT_VK_SUCCESS(err);
9391
9392 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009393 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009394 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9395 dsl_binding[i].binding = 0;
9396 dsl_binding[i].descriptorType = VkDescriptorType(i);
9397 dsl_binding[i].descriptorCount = 1;
9398 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9399 dsl_binding[i].pImmutableSamplers = NULL;
9400 }
9401
9402 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9403 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9404 ds_layout_ci.pNext = NULL;
9405 ds_layout_ci.bindingCount = 1;
9406 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9407 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9408 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009409 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009410 ASSERT_VK_SUCCESS(err);
9411 }
9412 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9413 VkDescriptorSetAllocateInfo alloc_info = {};
9414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9415 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9416 alloc_info.descriptorPool = ds_pool;
9417 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009419 ASSERT_VK_SUCCESS(err);
9420
9421 // Create a buffer & bufferView to be used for invalid updates
9422 VkBufferCreateInfo buff_ci = {};
9423 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009424 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009425 buff_ci.size = 256;
9426 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009427 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009428 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9429 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009430
9431 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9432 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9433 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9434 ASSERT_VK_SUCCESS(err);
9435
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009436 VkMemoryRequirements mem_reqs;
9437 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9438 VkMemoryAllocateInfo mem_alloc_info = {};
9439 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9440 mem_alloc_info.pNext = NULL;
9441 mem_alloc_info.memoryTypeIndex = 0;
9442 mem_alloc_info.allocationSize = mem_reqs.size;
9443 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9444 if (!pass) {
9445 vkDestroyBuffer(m_device->device(), buffer, NULL);
9446 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9447 return;
9448 }
9449 VkDeviceMemory mem;
9450 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9451 ASSERT_VK_SUCCESS(err);
9452 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9453 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009454
9455 VkBufferViewCreateInfo buff_view_ci = {};
9456 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9457 buff_view_ci.buffer = buffer;
9458 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9459 buff_view_ci.range = VK_WHOLE_SIZE;
9460 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009461 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009462 ASSERT_VK_SUCCESS(err);
9463
Tony Barbour415497c2017-01-24 10:06:09 -07009464 // Now get resources / view for storage_texel_buffer
9465 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9466 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9467 if (!pass) {
9468 vkDestroyBuffer(m_device->device(), buffer, NULL);
9469 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9470 vkFreeMemory(m_device->device(), mem, NULL);
9471 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9472 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9473 return;
9474 }
9475 VkDeviceMemory storage_texel_buffer_mem;
9476 VkBufferView storage_texel_buffer_view;
9477 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9478 ASSERT_VK_SUCCESS(err);
9479 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9480 ASSERT_VK_SUCCESS(err);
9481 buff_view_ci.buffer = storage_texel_buffer;
9482 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9483 ASSERT_VK_SUCCESS(err);
9484
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009485 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009486 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009487 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009488 image_ci.format = VK_FORMAT_UNDEFINED;
9489 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9490 VkFormat format = static_cast<VkFormat>(f);
9491 VkFormatProperties fProps = m_device->format_properties(format);
9492 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9493 image_ci.format = format;
9494 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9495 break;
9496 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9497 image_ci.format = format;
9498 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9499 break;
9500 }
9501 }
9502 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9503 return;
9504 }
9505
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009506 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9507 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009508 image_ci.extent.width = 64;
9509 image_ci.extent.height = 64;
9510 image_ci.extent.depth = 1;
9511 image_ci.mipLevels = 1;
9512 image_ci.arrayLayers = 1;
9513 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009514 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009515 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009516 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9517 VkImage image;
9518 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9519 ASSERT_VK_SUCCESS(err);
9520 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009521 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009522
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009523 VkMemoryAllocateInfo mem_alloc = {};
9524 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9525 mem_alloc.pNext = NULL;
9526 mem_alloc.allocationSize = 0;
9527 mem_alloc.memoryTypeIndex = 0;
9528 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9529 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009530 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009531 ASSERT_TRUE(pass);
9532 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9533 ASSERT_VK_SUCCESS(err);
9534 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9535 ASSERT_VK_SUCCESS(err);
9536 // Now create view for image
9537 VkImageViewCreateInfo image_view_ci = {};
9538 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9539 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009540 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009541 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9542 image_view_ci.subresourceRange.layerCount = 1;
9543 image_view_ci.subresourceRange.baseArrayLayer = 0;
9544 image_view_ci.subresourceRange.levelCount = 1;
9545 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9546 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009547 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009548 ASSERT_VK_SUCCESS(err);
9549
9550 VkDescriptorBufferInfo buff_info = {};
9551 buff_info.buffer = buffer;
9552 VkDescriptorImageInfo img_info = {};
9553 img_info.imageView = image_view;
9554 VkWriteDescriptorSet descriptor_write = {};
9555 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9556 descriptor_write.dstBinding = 0;
9557 descriptor_write.descriptorCount = 1;
9558 descriptor_write.pTexelBufferView = &buff_view;
9559 descriptor_write.pBufferInfo = &buff_info;
9560 descriptor_write.pImageInfo = &img_info;
9561
9562 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009563 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009564 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9565 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9566 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9567 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9568 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9569 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9570 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9571 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9572 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9573 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9574 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009575 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009576 // Start loop at 1 as SAMPLER desc type has no usage bit error
9577 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009578 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9579 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9580 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9581 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009582 descriptor_write.descriptorType = VkDescriptorType(i);
9583 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009586 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009587
9588 m_errorMonitor->VerifyFound();
9589 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009590 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9591 descriptor_write.pTexelBufferView = &buff_view;
9592 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009593 }
Tony Barbour415497c2017-01-24 10:06:09 -07009594
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009595 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9596 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009597 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009598 vkDestroyImageView(m_device->device(), image_view, NULL);
9599 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009600 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009601 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009602 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009603 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009604 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009605 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9606}
9607
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009608TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009609 TEST_DESCRIPTION(
9610 "Attempt to update buffer descriptor set that has incorrect "
9611 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9612 "1. offset value greater than buffer size\n"
9613 "2. range value of 0\n"
9614 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009615 VkResult err;
9616
9617 ASSERT_NO_FATAL_FAILURE(InitState());
9618 VkDescriptorPoolSize ds_type_count = {};
9619 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9620 ds_type_count.descriptorCount = 1;
9621
9622 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9623 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9624 ds_pool_ci.pNext = NULL;
9625 ds_pool_ci.maxSets = 1;
9626 ds_pool_ci.poolSizeCount = 1;
9627 ds_pool_ci.pPoolSizes = &ds_type_count;
9628
9629 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009630 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009631 ASSERT_VK_SUCCESS(err);
9632
9633 // Create layout with single uniform buffer descriptor
9634 VkDescriptorSetLayoutBinding dsl_binding = {};
9635 dsl_binding.binding = 0;
9636 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9637 dsl_binding.descriptorCount = 1;
9638 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9639 dsl_binding.pImmutableSamplers = NULL;
9640
9641 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9642 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9643 ds_layout_ci.pNext = NULL;
9644 ds_layout_ci.bindingCount = 1;
9645 ds_layout_ci.pBindings = &dsl_binding;
9646 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009647 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009648 ASSERT_VK_SUCCESS(err);
9649
9650 VkDescriptorSet descriptor_set = {};
9651 VkDescriptorSetAllocateInfo alloc_info = {};
9652 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9653 alloc_info.descriptorSetCount = 1;
9654 alloc_info.descriptorPool = ds_pool;
9655 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009656 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009657 ASSERT_VK_SUCCESS(err);
9658
9659 // Create a buffer to be used for invalid updates
9660 VkBufferCreateInfo buff_ci = {};
9661 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9662 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9663 buff_ci.size = 256;
9664 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9665 VkBuffer buffer;
9666 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9667 ASSERT_VK_SUCCESS(err);
9668 // Have to bind memory to buffer before descriptor update
9669 VkMemoryAllocateInfo mem_alloc = {};
9670 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9671 mem_alloc.pNext = NULL;
9672 mem_alloc.allocationSize = 256;
9673 mem_alloc.memoryTypeIndex = 0;
9674
9675 VkMemoryRequirements mem_reqs;
9676 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009677 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009678 if (!pass) {
9679 vkDestroyBuffer(m_device->device(), buffer, NULL);
9680 return;
9681 }
9682
9683 VkDeviceMemory mem;
9684 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9685 ASSERT_VK_SUCCESS(err);
9686 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9687 ASSERT_VK_SUCCESS(err);
9688
9689 VkDescriptorBufferInfo buff_info = {};
9690 buff_info.buffer = buffer;
9691 // First make offset 1 larger than buffer size
9692 buff_info.offset = 257;
9693 buff_info.range = VK_WHOLE_SIZE;
9694 VkWriteDescriptorSet descriptor_write = {};
9695 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9696 descriptor_write.dstBinding = 0;
9697 descriptor_write.descriptorCount = 1;
9698 descriptor_write.pTexelBufferView = nullptr;
9699 descriptor_write.pBufferInfo = &buff_info;
9700 descriptor_write.pImageInfo = nullptr;
9701
9702 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9703 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009705
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009706 m_errorMonitor->SetUnexpectedError(
9707 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9708 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009709 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9710
9711 m_errorMonitor->VerifyFound();
9712 // Now cause error due to range of 0
9713 buff_info.offset = 0;
9714 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009716
9717 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9718
9719 m_errorMonitor->VerifyFound();
9720 // Now cause error due to range exceeding buffer size - offset
9721 buff_info.offset = 128;
9722 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009724
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009725 m_errorMonitor->SetUnexpectedError(
9726 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9727 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009728 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9729
9730 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009731 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009732 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9733 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009734 m_errorMonitor->SetUnexpectedError(
9735 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009736 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9737 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9738}
9739
Tobin Ehlis845887e2017-02-02 19:01:44 -07009740TEST_F(VkLayerTest, DSBufferLimitErrors) {
9741 TEST_DESCRIPTION(
9742 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9743 "Test cases include:\n"
9744 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9745 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9746 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9747 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9748 VkResult err;
9749
9750 ASSERT_NO_FATAL_FAILURE(InitState());
9751 VkDescriptorPoolSize ds_type_count[2] = {};
9752 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9753 ds_type_count[0].descriptorCount = 1;
9754 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9755 ds_type_count[1].descriptorCount = 1;
9756
9757 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9758 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9759 ds_pool_ci.pNext = NULL;
9760 ds_pool_ci.maxSets = 1;
9761 ds_pool_ci.poolSizeCount = 2;
9762 ds_pool_ci.pPoolSizes = ds_type_count;
9763
9764 VkDescriptorPool ds_pool;
9765 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9766 ASSERT_VK_SUCCESS(err);
9767
9768 // Create layout with single uniform buffer & single storage buffer descriptor
9769 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9770 dsl_binding[0].binding = 0;
9771 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9772 dsl_binding[0].descriptorCount = 1;
9773 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9774 dsl_binding[0].pImmutableSamplers = NULL;
9775 dsl_binding[1].binding = 1;
9776 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9777 dsl_binding[1].descriptorCount = 1;
9778 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9779 dsl_binding[1].pImmutableSamplers = NULL;
9780
9781 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9782 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9783 ds_layout_ci.pNext = NULL;
9784 ds_layout_ci.bindingCount = 2;
9785 ds_layout_ci.pBindings = dsl_binding;
9786 VkDescriptorSetLayout ds_layout;
9787 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9788 ASSERT_VK_SUCCESS(err);
9789
9790 VkDescriptorSet descriptor_set = {};
9791 VkDescriptorSetAllocateInfo alloc_info = {};
9792 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9793 alloc_info.descriptorSetCount = 1;
9794 alloc_info.descriptorPool = ds_pool;
9795 alloc_info.pSetLayouts = &ds_layout;
9796 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9797 ASSERT_VK_SUCCESS(err);
9798
9799 // Create a buffer to be used for invalid updates
9800 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9801 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9802 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9803 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9804 VkBufferCreateInfo ub_ci = {};
9805 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9806 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9807 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9808 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9809 VkBuffer uniform_buffer;
9810 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9811 ASSERT_VK_SUCCESS(err);
9812 VkBufferCreateInfo sb_ci = {};
9813 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9814 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9815 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9816 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9817 VkBuffer storage_buffer;
9818 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9819 ASSERT_VK_SUCCESS(err);
9820 // Have to bind memory to buffer before descriptor update
9821 VkMemoryAllocateInfo mem_alloc = {};
9822 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9823 mem_alloc.pNext = NULL;
9824 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9825 mem_alloc.memoryTypeIndex = 0;
9826
9827 VkMemoryRequirements mem_reqs;
9828 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9829 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9830 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9831 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9832 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009834 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009835 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9836 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009837 return;
9838 }
9839
9840 VkDeviceMemory mem;
9841 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009842 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009843 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009844 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9845 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9846 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9847 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9848 return;
9849 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009850 ASSERT_VK_SUCCESS(err);
9851 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9852 ASSERT_VK_SUCCESS(err);
9853 auto sb_offset = ub_ci.size + 1024;
9854 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9855 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9856 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9857 ASSERT_VK_SUCCESS(err);
9858
9859 VkDescriptorBufferInfo buff_info = {};
9860 buff_info.buffer = uniform_buffer;
9861 buff_info.range = ub_ci.size; // This will exceed limit
9862 VkWriteDescriptorSet descriptor_write = {};
9863 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9864 descriptor_write.dstBinding = 0;
9865 descriptor_write.descriptorCount = 1;
9866 descriptor_write.pTexelBufferView = nullptr;
9867 descriptor_write.pBufferInfo = &buff_info;
9868 descriptor_write.pImageInfo = nullptr;
9869
9870 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9871 descriptor_write.dstSet = descriptor_set;
9872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9873 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9874 m_errorMonitor->VerifyFound();
9875
9876 // Reduce size of range to acceptable limit & cause offset error
9877 buff_info.range = max_ub_range;
9878 buff_info.offset = min_ub_align - 1;
9879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9880 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9881 m_errorMonitor->VerifyFound();
9882
9883 // Now break storage updates
9884 buff_info.buffer = storage_buffer;
9885 buff_info.range = sb_ci.size; // This will exceed limit
9886 buff_info.offset = 0; // Reset offset for this update
9887
9888 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9889 descriptor_write.dstBinding = 1;
9890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9891 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9892 m_errorMonitor->VerifyFound();
9893
9894 // Reduce size of range to acceptable limit & cause offset error
9895 buff_info.range = max_sb_range;
9896 buff_info.offset = min_sb_align - 1;
9897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9898 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9899 m_errorMonitor->VerifyFound();
9900
9901 vkFreeMemory(m_device->device(), mem, NULL);
9902 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9903 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9904 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9905 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9906}
9907
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009908TEST_F(VkLayerTest, DSAspectBitsErrors) {
9909 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9910 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009911 TEST_DESCRIPTION(
9912 "Attempt to update descriptor sets for images "
9913 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009914 VkResult err;
9915
9916 ASSERT_NO_FATAL_FAILURE(InitState());
9917 VkDescriptorPoolSize ds_type_count = {};
9918 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9919 ds_type_count.descriptorCount = 1;
9920
9921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9923 ds_pool_ci.pNext = NULL;
9924 ds_pool_ci.maxSets = 5;
9925 ds_pool_ci.poolSizeCount = 1;
9926 ds_pool_ci.pPoolSizes = &ds_type_count;
9927
9928 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009929 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009930 ASSERT_VK_SUCCESS(err);
9931
9932 VkDescriptorSetLayoutBinding dsl_binding = {};
9933 dsl_binding.binding = 0;
9934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9935 dsl_binding.descriptorCount = 1;
9936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9937 dsl_binding.pImmutableSamplers = NULL;
9938
9939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9940 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9941 ds_layout_ci.pNext = NULL;
9942 ds_layout_ci.bindingCount = 1;
9943 ds_layout_ci.pBindings = &dsl_binding;
9944 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009945 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009946 ASSERT_VK_SUCCESS(err);
9947
9948 VkDescriptorSet descriptor_set = {};
9949 VkDescriptorSetAllocateInfo alloc_info = {};
9950 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9951 alloc_info.descriptorSetCount = 1;
9952 alloc_info.descriptorPool = ds_pool;
9953 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009954 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009955 ASSERT_VK_SUCCESS(err);
9956
9957 // Create an image to be used for invalid updates
9958 VkImageCreateInfo image_ci = {};
9959 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9960 image_ci.imageType = VK_IMAGE_TYPE_2D;
9961 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9962 image_ci.extent.width = 64;
9963 image_ci.extent.height = 64;
9964 image_ci.extent.depth = 1;
9965 image_ci.mipLevels = 1;
9966 image_ci.arrayLayers = 1;
9967 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -07009968 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009969 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9970 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9971 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9972 VkImage image;
9973 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9974 ASSERT_VK_SUCCESS(err);
9975 // Bind memory to image
9976 VkMemoryRequirements mem_reqs;
9977 VkDeviceMemory image_mem;
9978 bool pass;
9979 VkMemoryAllocateInfo mem_alloc = {};
9980 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9981 mem_alloc.pNext = NULL;
9982 mem_alloc.allocationSize = 0;
9983 mem_alloc.memoryTypeIndex = 0;
9984 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9985 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009987 ASSERT_TRUE(pass);
9988 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9989 ASSERT_VK_SUCCESS(err);
9990 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9991 ASSERT_VK_SUCCESS(err);
9992 // Now create view for image
9993 VkImageViewCreateInfo image_view_ci = {};
9994 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9995 image_view_ci.image = image;
9996 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9997 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9998 image_view_ci.subresourceRange.layerCount = 1;
9999 image_view_ci.subresourceRange.baseArrayLayer = 0;
10000 image_view_ci.subresourceRange.levelCount = 1;
10001 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010002 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010003
10004 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010005 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010006 ASSERT_VK_SUCCESS(err);
10007
10008 VkDescriptorImageInfo img_info = {};
10009 img_info.imageView = image_view;
10010 VkWriteDescriptorSet descriptor_write = {};
10011 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10012 descriptor_write.dstBinding = 0;
10013 descriptor_write.descriptorCount = 1;
10014 descriptor_write.pTexelBufferView = NULL;
10015 descriptor_write.pBufferInfo = NULL;
10016 descriptor_write.pImageInfo = &img_info;
10017 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10018 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010019 const char *error_msg =
10020 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10021 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010023
10024 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10025
10026 m_errorMonitor->VerifyFound();
10027 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10028 vkDestroyImage(m_device->device(), image, NULL);
10029 vkFreeMemory(m_device->device(), image_mem, NULL);
10030 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010031 m_errorMonitor->SetUnexpectedError(
10032 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010033 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10035}
10036
Karl Schultz6addd812016-02-02 17:17:23 -070010037TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010038 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010039 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10042 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10043 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010044
Tobin Ehlis3b780662015-05-28 12:11:26 -060010045 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010046 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010047 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010048 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10049 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010050
10051 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010052 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10053 ds_pool_ci.pNext = NULL;
10054 ds_pool_ci.maxSets = 1;
10055 ds_pool_ci.poolSizeCount = 1;
10056 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010057
Tobin Ehlis3b780662015-05-28 12:11:26 -060010058 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010059 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010060 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010061 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010062 dsl_binding.binding = 0;
10063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10064 dsl_binding.descriptorCount = 1;
10065 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10066 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010067
Tony Barboureb254902015-07-15 12:50:33 -060010068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10070 ds_layout_ci.pNext = NULL;
10071 ds_layout_ci.bindingCount = 1;
10072 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010073
Tobin Ehlis3b780662015-05-28 12:11:26 -060010074 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010076 ASSERT_VK_SUCCESS(err);
10077
10078 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010079 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010080 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010081 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010082 alloc_info.descriptorPool = ds_pool;
10083 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010084 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010085 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010086
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010087 VkSamplerCreateInfo sampler_ci = {};
10088 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10089 sampler_ci.pNext = NULL;
10090 sampler_ci.magFilter = VK_FILTER_NEAREST;
10091 sampler_ci.minFilter = VK_FILTER_NEAREST;
10092 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10093 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10094 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10095 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10096 sampler_ci.mipLodBias = 1.0;
10097 sampler_ci.anisotropyEnable = VK_FALSE;
10098 sampler_ci.maxAnisotropy = 1;
10099 sampler_ci.compareEnable = VK_FALSE;
10100 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10101 sampler_ci.minLod = 1.0;
10102 sampler_ci.maxLod = 1.0;
10103 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10104 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10105 VkSampler sampler;
10106 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10107 ASSERT_VK_SUCCESS(err);
10108
10109 VkDescriptorImageInfo info = {};
10110 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010111
10112 VkWriteDescriptorSet descriptor_write;
10113 memset(&descriptor_write, 0, sizeof(descriptor_write));
10114 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010115 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010116 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010117 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010118 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010119 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010120
10121 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10122
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010123 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010124
Chia-I Wuf7458c52015-10-26 21:10:41 +080010125 vkDestroySampler(m_device->device(), sampler, NULL);
10126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010128}
10129
Karl Schultz6addd812016-02-02 17:17:23 -070010130TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010131 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010132 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010133
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010135
Tobin Ehlis3b780662015-05-28 12:11:26 -060010136 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010137 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010138 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010139 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10140 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010141
10142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10144 ds_pool_ci.pNext = NULL;
10145 ds_pool_ci.maxSets = 1;
10146 ds_pool_ci.poolSizeCount = 1;
10147 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010148
Tobin Ehlis3b780662015-05-28 12:11:26 -060010149 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010150 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010151 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010152
Tony Barboureb254902015-07-15 12:50:33 -060010153 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010154 dsl_binding.binding = 0;
10155 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10156 dsl_binding.descriptorCount = 1;
10157 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10158 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010159
10160 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010161 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10162 ds_layout_ci.pNext = NULL;
10163 ds_layout_ci.bindingCount = 1;
10164 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010165
Tobin Ehlis3b780662015-05-28 12:11:26 -060010166 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010167 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010168 ASSERT_VK_SUCCESS(err);
10169
10170 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010171 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010172 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010173 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010174 alloc_info.descriptorPool = ds_pool;
10175 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010176 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010177 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010178
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010179 // Correctly update descriptor to avoid "NOT_UPDATED" error
10180 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010181 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010182 buff_info.offset = 0;
10183 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010184
10185 VkWriteDescriptorSet descriptor_write;
10186 memset(&descriptor_write, 0, sizeof(descriptor_write));
10187 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010188 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010190 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010191 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10192 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010193
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010194 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010195 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10196
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010197 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010198
Chia-I Wuf7458c52015-10-26 21:10:41 +080010199 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10200 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010201}
10202
Karl Schultz6addd812016-02-02 17:17:23 -070010203TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010204 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010205 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010206
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010208
Tobin Ehlis3b780662015-05-28 12:11:26 -060010209 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010210 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010211 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010212 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10213 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010214
10215 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010216 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10217 ds_pool_ci.pNext = NULL;
10218 ds_pool_ci.maxSets = 1;
10219 ds_pool_ci.poolSizeCount = 1;
10220 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010221
Tobin Ehlis3b780662015-05-28 12:11:26 -060010222 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010223 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010224 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010225
Tony Barboureb254902015-07-15 12:50:33 -060010226 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010227 dsl_binding.binding = 0;
10228 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10229 dsl_binding.descriptorCount = 1;
10230 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10231 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010232
10233 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010234 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10235 ds_layout_ci.pNext = NULL;
10236 ds_layout_ci.bindingCount = 1;
10237 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010238 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010239 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010240 ASSERT_VK_SUCCESS(err);
10241
10242 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010243 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010244 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010245 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010246 alloc_info.descriptorPool = ds_pool;
10247 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010248 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010249 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010250
Tony Barboureb254902015-07-15 12:50:33 -060010251 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010252 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10253 sampler_ci.pNext = NULL;
10254 sampler_ci.magFilter = VK_FILTER_NEAREST;
10255 sampler_ci.minFilter = VK_FILTER_NEAREST;
10256 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10257 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10258 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10259 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10260 sampler_ci.mipLodBias = 1.0;
10261 sampler_ci.anisotropyEnable = VK_FALSE;
10262 sampler_ci.maxAnisotropy = 1;
10263 sampler_ci.compareEnable = VK_FALSE;
10264 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10265 sampler_ci.minLod = 1.0;
10266 sampler_ci.maxLod = 1.0;
10267 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10268 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010269
Tobin Ehlis3b780662015-05-28 12:11:26 -060010270 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010271 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010272 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010273
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010274 VkDescriptorImageInfo info = {};
10275 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010276
10277 VkWriteDescriptorSet descriptor_write;
10278 memset(&descriptor_write, 0, sizeof(descriptor_write));
10279 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010280 descriptor_write.dstSet = descriptorSet;
10281 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010282 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010283 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010284 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010285 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010286
10287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10288
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010289 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010290
Chia-I Wuf7458c52015-10-26 21:10:41 +080010291 vkDestroySampler(m_device->device(), sampler, NULL);
10292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010294}
10295
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010296TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10297 // Create layout w/ empty binding and attempt to update it
10298 VkResult err;
10299
10300 ASSERT_NO_FATAL_FAILURE(InitState());
10301
10302 VkDescriptorPoolSize ds_type_count = {};
10303 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10304 ds_type_count.descriptorCount = 1;
10305
10306 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10307 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10308 ds_pool_ci.pNext = NULL;
10309 ds_pool_ci.maxSets = 1;
10310 ds_pool_ci.poolSizeCount = 1;
10311 ds_pool_ci.pPoolSizes = &ds_type_count;
10312
10313 VkDescriptorPool ds_pool;
10314 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10315 ASSERT_VK_SUCCESS(err);
10316
10317 VkDescriptorSetLayoutBinding dsl_binding = {};
10318 dsl_binding.binding = 0;
10319 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10320 dsl_binding.descriptorCount = 0;
10321 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10322 dsl_binding.pImmutableSamplers = NULL;
10323
10324 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10325 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10326 ds_layout_ci.pNext = NULL;
10327 ds_layout_ci.bindingCount = 1;
10328 ds_layout_ci.pBindings = &dsl_binding;
10329 VkDescriptorSetLayout ds_layout;
10330 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10331 ASSERT_VK_SUCCESS(err);
10332
10333 VkDescriptorSet descriptor_set;
10334 VkDescriptorSetAllocateInfo alloc_info = {};
10335 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10336 alloc_info.descriptorSetCount = 1;
10337 alloc_info.descriptorPool = ds_pool;
10338 alloc_info.pSetLayouts = &ds_layout;
10339 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10340 ASSERT_VK_SUCCESS(err);
10341
10342 VkSamplerCreateInfo sampler_ci = {};
10343 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10344 sampler_ci.magFilter = VK_FILTER_NEAREST;
10345 sampler_ci.minFilter = VK_FILTER_NEAREST;
10346 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10347 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10348 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10349 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10350 sampler_ci.mipLodBias = 1.0;
10351 sampler_ci.maxAnisotropy = 1;
10352 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10353 sampler_ci.minLod = 1.0;
10354 sampler_ci.maxLod = 1.0;
10355 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10356
10357 VkSampler sampler;
10358 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10359 ASSERT_VK_SUCCESS(err);
10360
10361 VkDescriptorImageInfo info = {};
10362 info.sampler = sampler;
10363
10364 VkWriteDescriptorSet descriptor_write;
10365 memset(&descriptor_write, 0, sizeof(descriptor_write));
10366 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10367 descriptor_write.dstSet = descriptor_set;
10368 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010369 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010370 // This is the wrong type, but empty binding error will be flagged first
10371 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10372 descriptor_write.pImageInfo = &info;
10373
10374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10375 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10376 m_errorMonitor->VerifyFound();
10377
10378 vkDestroySampler(m_device->device(), sampler, NULL);
10379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10381}
10382
Karl Schultz6addd812016-02-02 17:17:23 -070010383TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10384 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10385 // types
10386 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010388 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 -060010389
Tobin Ehlis3b780662015-05-28 12:11:26 -060010390 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010391
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010392 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010393 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10394 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010395
10396 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010397 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10398 ds_pool_ci.pNext = NULL;
10399 ds_pool_ci.maxSets = 1;
10400 ds_pool_ci.poolSizeCount = 1;
10401 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010402
Tobin Ehlis3b780662015-05-28 12:11:26 -060010403 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010405 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010406 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010407 dsl_binding.binding = 0;
10408 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10409 dsl_binding.descriptorCount = 1;
10410 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10411 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010412
Tony Barboureb254902015-07-15 12:50:33 -060010413 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010414 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10415 ds_layout_ci.pNext = NULL;
10416 ds_layout_ci.bindingCount = 1;
10417 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010418
Tobin Ehlis3b780662015-05-28 12:11:26 -060010419 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010421 ASSERT_VK_SUCCESS(err);
10422
10423 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010424 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010425 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010426 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010427 alloc_info.descriptorPool = ds_pool;
10428 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010429 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010430 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010431
Tony Barboureb254902015-07-15 12:50:33 -060010432 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010433 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10434 sampler_ci.pNext = NULL;
10435 sampler_ci.magFilter = VK_FILTER_NEAREST;
10436 sampler_ci.minFilter = VK_FILTER_NEAREST;
10437 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10438 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10439 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10440 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10441 sampler_ci.mipLodBias = 1.0;
10442 sampler_ci.anisotropyEnable = VK_FALSE;
10443 sampler_ci.maxAnisotropy = 1;
10444 sampler_ci.compareEnable = VK_FALSE;
10445 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10446 sampler_ci.minLod = 1.0;
10447 sampler_ci.maxLod = 1.0;
10448 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10449 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010450 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010451 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010452 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010453
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010454 VkDescriptorImageInfo info = {};
10455 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010456
10457 VkWriteDescriptorSet descriptor_write;
10458 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010459 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010460 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010461 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010462 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010463 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010464 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010465
10466 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10467
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010468 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010469
Chia-I Wuf7458c52015-10-26 21:10:41 +080010470 vkDestroySampler(m_device->device(), sampler, NULL);
10471 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10472 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010473}
10474
Karl Schultz6addd812016-02-02 17:17:23 -070010475TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010476 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010477 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010478
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010480
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010481 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010482 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10483 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010484 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010485 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10486 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010487
10488 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010489 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10490 ds_pool_ci.pNext = NULL;
10491 ds_pool_ci.maxSets = 1;
10492 ds_pool_ci.poolSizeCount = 1;
10493 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010494
10495 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010496 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010497 ASSERT_VK_SUCCESS(err);
10498
10499 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010500 dsl_binding.binding = 0;
10501 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10502 dsl_binding.descriptorCount = 1;
10503 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10504 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010505
10506 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010507 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10508 ds_layout_ci.pNext = NULL;
10509 ds_layout_ci.bindingCount = 1;
10510 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010511 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010512 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010513 ASSERT_VK_SUCCESS(err);
10514
10515 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010516 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010517 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010518 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010519 alloc_info.descriptorPool = ds_pool;
10520 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010522 ASSERT_VK_SUCCESS(err);
10523
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010524 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010525
10526 VkDescriptorImageInfo descriptor_info;
10527 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10528 descriptor_info.sampler = sampler;
10529
10530 VkWriteDescriptorSet descriptor_write;
10531 memset(&descriptor_write, 0, sizeof(descriptor_write));
10532 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010533 descriptor_write.dstSet = descriptorSet;
10534 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010535 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010536 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10537 descriptor_write.pImageInfo = &descriptor_info;
10538
10539 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10540
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010541 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010542
Chia-I Wuf7458c52015-10-26 21:10:41 +080010543 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10544 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010545}
10546
Karl Schultz6addd812016-02-02 17:17:23 -070010547TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10548 // Create a single combined Image/Sampler descriptor and send it an invalid
10549 // imageView
10550 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010551
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010553
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010554 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010555 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010556 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10557 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010558
10559 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010560 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10561 ds_pool_ci.pNext = NULL;
10562 ds_pool_ci.maxSets = 1;
10563 ds_pool_ci.poolSizeCount = 1;
10564 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010565
10566 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010567 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010568 ASSERT_VK_SUCCESS(err);
10569
10570 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010571 dsl_binding.binding = 0;
10572 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10573 dsl_binding.descriptorCount = 1;
10574 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10575 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010576
10577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10579 ds_layout_ci.pNext = NULL;
10580 ds_layout_ci.bindingCount = 1;
10581 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010582 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010583 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010584 ASSERT_VK_SUCCESS(err);
10585
10586 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010587 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010588 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010589 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010590 alloc_info.descriptorPool = ds_pool;
10591 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010592 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010593 ASSERT_VK_SUCCESS(err);
10594
10595 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010596 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10597 sampler_ci.pNext = NULL;
10598 sampler_ci.magFilter = VK_FILTER_NEAREST;
10599 sampler_ci.minFilter = VK_FILTER_NEAREST;
10600 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10601 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10602 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10603 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10604 sampler_ci.mipLodBias = 1.0;
10605 sampler_ci.anisotropyEnable = VK_FALSE;
10606 sampler_ci.maxAnisotropy = 1;
10607 sampler_ci.compareEnable = VK_FALSE;
10608 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10609 sampler_ci.minLod = 1.0;
10610 sampler_ci.maxLod = 1.0;
10611 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10612 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010613
10614 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010615 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010616 ASSERT_VK_SUCCESS(err);
10617
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010618 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010619
10620 VkDescriptorImageInfo descriptor_info;
10621 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10622 descriptor_info.sampler = sampler;
10623 descriptor_info.imageView = view;
10624
10625 VkWriteDescriptorSet descriptor_write;
10626 memset(&descriptor_write, 0, sizeof(descriptor_write));
10627 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010628 descriptor_write.dstSet = descriptorSet;
10629 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010630 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010631 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10632 descriptor_write.pImageInfo = &descriptor_info;
10633
10634 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10635
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010636 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010637
Chia-I Wuf7458c52015-10-26 21:10:41 +080010638 vkDestroySampler(m_device->device(), sampler, NULL);
10639 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10640 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010641}
10642
Karl Schultz6addd812016-02-02 17:17:23 -070010643TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10644 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10645 // into the other
10646 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010647
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10649 " binding #1 with type "
10650 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10651 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010652
Tobin Ehlis04356f92015-10-27 16:35:27 -060010653 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010654 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010655 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010656 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10657 ds_type_count[0].descriptorCount = 1;
10658 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10659 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010660
10661 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010662 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10663 ds_pool_ci.pNext = NULL;
10664 ds_pool_ci.maxSets = 1;
10665 ds_pool_ci.poolSizeCount = 2;
10666 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010667
10668 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010669 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010670 ASSERT_VK_SUCCESS(err);
10671 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010672 dsl_binding[0].binding = 0;
10673 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10674 dsl_binding[0].descriptorCount = 1;
10675 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10676 dsl_binding[0].pImmutableSamplers = NULL;
10677 dsl_binding[1].binding = 1;
10678 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10679 dsl_binding[1].descriptorCount = 1;
10680 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10681 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010682
10683 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010684 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10685 ds_layout_ci.pNext = NULL;
10686 ds_layout_ci.bindingCount = 2;
10687 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010688
10689 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010690 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010691 ASSERT_VK_SUCCESS(err);
10692
10693 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010694 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010695 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010696 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010697 alloc_info.descriptorPool = ds_pool;
10698 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010699 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010700 ASSERT_VK_SUCCESS(err);
10701
10702 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010703 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10704 sampler_ci.pNext = NULL;
10705 sampler_ci.magFilter = VK_FILTER_NEAREST;
10706 sampler_ci.minFilter = VK_FILTER_NEAREST;
10707 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10708 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10709 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10710 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10711 sampler_ci.mipLodBias = 1.0;
10712 sampler_ci.anisotropyEnable = VK_FALSE;
10713 sampler_ci.maxAnisotropy = 1;
10714 sampler_ci.compareEnable = VK_FALSE;
10715 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10716 sampler_ci.minLod = 1.0;
10717 sampler_ci.maxLod = 1.0;
10718 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10719 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010720
10721 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010722 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010723 ASSERT_VK_SUCCESS(err);
10724
10725 VkDescriptorImageInfo info = {};
10726 info.sampler = sampler;
10727
10728 VkWriteDescriptorSet descriptor_write;
10729 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10730 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010731 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010732 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010733 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010734 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10735 descriptor_write.pImageInfo = &info;
10736 // This write update should succeed
10737 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10738 // Now perform a copy update that fails due to type mismatch
10739 VkCopyDescriptorSet copy_ds_update;
10740 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10741 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10742 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010743 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010744 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010745 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10746 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010747 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10748
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010749 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010750 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010751 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 -060010752 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10753 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10754 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010755 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010756 copy_ds_update.dstSet = descriptorSet;
10757 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010758 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010759 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10760
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010761 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010762
Tobin Ehlis04356f92015-10-27 16:35:27 -060010763 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10765 " binding#1 with offset index of 1 plus "
10766 "update array offset of 0 and update of "
10767 "5 descriptors oversteps total number "
10768 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010769
Tobin Ehlis04356f92015-10-27 16:35:27 -060010770 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10771 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10772 copy_ds_update.srcSet = descriptorSet;
10773 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010774 copy_ds_update.dstSet = descriptorSet;
10775 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010776 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010777 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10778
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010779 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010780
Chia-I Wuf7458c52015-10-26 21:10:41 +080010781 vkDestroySampler(m_device->device(), sampler, NULL);
10782 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10783 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010784}
10785
Karl Schultz6addd812016-02-02 17:17:23 -070010786TEST_F(VkLayerTest, NumSamplesMismatch) {
10787 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10788 // sampleCount
10789 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010792
Tobin Ehlis3b780662015-05-28 12:11:26 -060010793 ASSERT_NO_FATAL_FAILURE(InitState());
10794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010795 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010796 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010797 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010798
10799 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010800 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10801 ds_pool_ci.pNext = NULL;
10802 ds_pool_ci.maxSets = 1;
10803 ds_pool_ci.poolSizeCount = 1;
10804 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010805
Tobin Ehlis3b780662015-05-28 12:11:26 -060010806 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010807 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010808 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010809
Tony Barboureb254902015-07-15 12:50:33 -060010810 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010811 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010812 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010813 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010814 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10815 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010816
Tony Barboureb254902015-07-15 12:50:33 -060010817 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10818 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10819 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010820 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010821 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010822
Tobin Ehlis3b780662015-05-28 12:11:26 -060010823 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010824 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010825 ASSERT_VK_SUCCESS(err);
10826
10827 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010828 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010829 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010830 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010831 alloc_info.descriptorPool = ds_pool;
10832 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010834 ASSERT_VK_SUCCESS(err);
10835
Tony Barboureb254902015-07-15 12:50:33 -060010836 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010837 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010838 pipe_ms_state_ci.pNext = NULL;
10839 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10840 pipe_ms_state_ci.sampleShadingEnable = 0;
10841 pipe_ms_state_ci.minSampleShading = 1.0;
10842 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010843
Tony Barboureb254902015-07-15 12:50:33 -060010844 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010845 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10846 pipeline_layout_ci.pNext = NULL;
10847 pipeline_layout_ci.setLayoutCount = 1;
10848 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010849
10850 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010851 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010852 ASSERT_VK_SUCCESS(err);
10853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010854 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010855 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 -060010856 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010857 VkPipelineObj pipe(m_device);
10858 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010859 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010860 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010861 pipe.SetMSAA(&pipe_ms_state_ci);
10862 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010863
Tony Barbour552f6c02016-12-21 14:34:07 -070010864 m_commandBuffer->BeginCommandBuffer();
10865 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010866 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010867
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010868 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10869 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10870 VkRect2D scissor = {{0, 0}, {16, 16}};
10871 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10872
Mark Young29927482016-05-04 14:38:51 -060010873 // Render triangle (the error should trigger on the attempt to draw).
10874 Draw(3, 1, 0, 0);
10875
10876 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010877 m_commandBuffer->EndRenderPass();
10878 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010879
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010880 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010881
Chia-I Wuf7458c52015-10-26 21:10:41 +080010882 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10883 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10884 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010885}
Mark Young29927482016-05-04 14:38:51 -060010886
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010887TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010888 TEST_DESCRIPTION(
10889 "Hit RenderPass incompatible cases. "
10890 "Initial case is drawing with an active renderpass that's "
10891 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010892 VkResult err;
10893
10894 ASSERT_NO_FATAL_FAILURE(InitState());
10895 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10896
10897 VkDescriptorSetLayoutBinding dsl_binding = {};
10898 dsl_binding.binding = 0;
10899 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10900 dsl_binding.descriptorCount = 1;
10901 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10902 dsl_binding.pImmutableSamplers = NULL;
10903
10904 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10905 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10906 ds_layout_ci.pNext = NULL;
10907 ds_layout_ci.bindingCount = 1;
10908 ds_layout_ci.pBindings = &dsl_binding;
10909
10910 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010911 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010912 ASSERT_VK_SUCCESS(err);
10913
10914 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10915 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10916 pipeline_layout_ci.pNext = NULL;
10917 pipeline_layout_ci.setLayoutCount = 1;
10918 pipeline_layout_ci.pSetLayouts = &ds_layout;
10919
10920 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010921 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010922 ASSERT_VK_SUCCESS(err);
10923
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010924 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010925 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 -060010926 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010927 // Create a renderpass that will be incompatible with default renderpass
10928 VkAttachmentReference attach = {};
10929 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10930 VkAttachmentReference color_att = {};
10931 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10932 VkSubpassDescription subpass = {};
10933 subpass.inputAttachmentCount = 1;
10934 subpass.pInputAttachments = &attach;
10935 subpass.colorAttachmentCount = 1;
10936 subpass.pColorAttachments = &color_att;
10937 VkRenderPassCreateInfo rpci = {};
10938 rpci.subpassCount = 1;
10939 rpci.pSubpasses = &subpass;
10940 rpci.attachmentCount = 1;
10941 VkAttachmentDescription attach_desc = {};
10942 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010943 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10944 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010945 rpci.pAttachments = &attach_desc;
10946 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10947 VkRenderPass rp;
10948 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10949 VkPipelineObj pipe(m_device);
10950 pipe.AddShader(&vs);
10951 pipe.AddShader(&fs);
10952 pipe.AddColorAttachment();
10953 VkViewport view_port = {};
10954 m_viewports.push_back(view_port);
10955 pipe.SetViewport(m_viewports);
10956 VkRect2D rect = {};
10957 m_scissors.push_back(rect);
10958 pipe.SetScissor(m_scissors);
10959 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10960
10961 VkCommandBufferInheritanceInfo cbii = {};
10962 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10963 cbii.renderPass = rp;
10964 cbii.subpass = 0;
10965 VkCommandBufferBeginInfo cbbi = {};
10966 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10967 cbbi.pInheritanceInfo = &cbii;
10968 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10969 VkRenderPassBeginInfo rpbi = {};
10970 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10971 rpbi.framebuffer = m_framebuffer;
10972 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010973 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10974 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010977 // Render triangle (the error should trigger on the attempt to draw).
10978 Draw(3, 1, 0, 0);
10979
10980 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010981 m_commandBuffer->EndRenderPass();
10982 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010983
10984 m_errorMonitor->VerifyFound();
10985
10986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10988 vkDestroyRenderPass(m_device->device(), rp, NULL);
10989}
10990
Mark Youngc89c6312016-03-31 16:03:20 -060010991TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10992 // Create Pipeline where the number of blend attachments doesn't match the
10993 // number of color attachments. In this case, we don't add any color
10994 // blend attachments even though we have a color attachment.
10995 VkResult err;
10996
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010998
10999 ASSERT_NO_FATAL_FAILURE(InitState());
11000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11001 VkDescriptorPoolSize ds_type_count = {};
11002 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11003 ds_type_count.descriptorCount = 1;
11004
11005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11006 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11007 ds_pool_ci.pNext = NULL;
11008 ds_pool_ci.maxSets = 1;
11009 ds_pool_ci.poolSizeCount = 1;
11010 ds_pool_ci.pPoolSizes = &ds_type_count;
11011
11012 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011013 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011014 ASSERT_VK_SUCCESS(err);
11015
11016 VkDescriptorSetLayoutBinding dsl_binding = {};
11017 dsl_binding.binding = 0;
11018 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11019 dsl_binding.descriptorCount = 1;
11020 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11021 dsl_binding.pImmutableSamplers = NULL;
11022
11023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11025 ds_layout_ci.pNext = NULL;
11026 ds_layout_ci.bindingCount = 1;
11027 ds_layout_ci.pBindings = &dsl_binding;
11028
11029 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011030 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011031 ASSERT_VK_SUCCESS(err);
11032
11033 VkDescriptorSet descriptorSet;
11034 VkDescriptorSetAllocateInfo alloc_info = {};
11035 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11036 alloc_info.descriptorSetCount = 1;
11037 alloc_info.descriptorPool = ds_pool;
11038 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011039 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011040 ASSERT_VK_SUCCESS(err);
11041
11042 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011043 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011044 pipe_ms_state_ci.pNext = NULL;
11045 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11046 pipe_ms_state_ci.sampleShadingEnable = 0;
11047 pipe_ms_state_ci.minSampleShading = 1.0;
11048 pipe_ms_state_ci.pSampleMask = NULL;
11049
11050 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11051 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11052 pipeline_layout_ci.pNext = NULL;
11053 pipeline_layout_ci.setLayoutCount = 1;
11054 pipeline_layout_ci.pSetLayouts = &ds_layout;
11055
11056 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011057 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011058 ASSERT_VK_SUCCESS(err);
11059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011060 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011061 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 -060011062 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011063 VkPipelineObj pipe(m_device);
11064 pipe.AddShader(&vs);
11065 pipe.AddShader(&fs);
11066 pipe.SetMSAA(&pipe_ms_state_ci);
11067 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011068 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011069
11070 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11071 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11072 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11073}
Mark Young29927482016-05-04 14:38:51 -060011074
Mark Muellerd4914412016-06-13 17:52:06 -060011075TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011076 TEST_DESCRIPTION(
11077 "Points to a wrong colorAttachment index in a VkClearAttachment "
11078 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011079 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011081
11082 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11083 m_errorMonitor->VerifyFound();
11084}
11085
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011086TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011087 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11088 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011089
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011090 ASSERT_NO_FATAL_FAILURE(InitState());
11091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011092
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011093 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011094 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11095 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011096
11097 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011098 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11099 ds_pool_ci.pNext = NULL;
11100 ds_pool_ci.maxSets = 1;
11101 ds_pool_ci.poolSizeCount = 1;
11102 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011103
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011104 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011105 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011106 ASSERT_VK_SUCCESS(err);
11107
Tony Barboureb254902015-07-15 12:50:33 -060011108 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011109 dsl_binding.binding = 0;
11110 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11111 dsl_binding.descriptorCount = 1;
11112 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11113 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011114
Tony Barboureb254902015-07-15 12:50:33 -060011115 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011116 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11117 ds_layout_ci.pNext = NULL;
11118 ds_layout_ci.bindingCount = 1;
11119 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011120
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011121 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011122 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011123 ASSERT_VK_SUCCESS(err);
11124
11125 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011126 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011127 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011128 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011129 alloc_info.descriptorPool = ds_pool;
11130 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011131 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011132 ASSERT_VK_SUCCESS(err);
11133
Tony Barboureb254902015-07-15 12:50:33 -060011134 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011135 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011136 pipe_ms_state_ci.pNext = NULL;
11137 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11138 pipe_ms_state_ci.sampleShadingEnable = 0;
11139 pipe_ms_state_ci.minSampleShading = 1.0;
11140 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011141
Tony Barboureb254902015-07-15 12:50:33 -060011142 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011143 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11144 pipeline_layout_ci.pNext = NULL;
11145 pipeline_layout_ci.setLayoutCount = 1;
11146 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011147
11148 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011150 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011152 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011153 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011154 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011155 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011156
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011157 VkPipelineObj pipe(m_device);
11158 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011159 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011160 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011161 m_errorMonitor->SetUnexpectedError(
11162 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11163 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011164 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011165
Tony Barbour552f6c02016-12-21 14:34:07 -070011166 m_commandBuffer->BeginCommandBuffer();
11167 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011168
Karl Schultz6addd812016-02-02 17:17:23 -070011169 // Main thing we care about for this test is that the VkImage obj we're
11170 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011171 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011172 VkClearAttachment color_attachment;
11173 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11174 color_attachment.clearValue.color.float32[0] = 1.0;
11175 color_attachment.clearValue.color.float32[1] = 1.0;
11176 color_attachment.clearValue.color.float32[2] = 1.0;
11177 color_attachment.clearValue.color.float32[3] = 1.0;
11178 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011179 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011180
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011181 // Call for full-sized FB Color attachment prior to issuing a Draw
11182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011183 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011184 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011185 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011186
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011187 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11188 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11190 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11191 m_errorMonitor->VerifyFound();
11192
11193 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11194 clear_rect.layerCount = 2;
11195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11196 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011197 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011198
Chia-I Wuf7458c52015-10-26 21:10:41 +080011199 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11200 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11201 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011202}
11203
Karl Schultz6addd812016-02-02 17:17:23 -070011204TEST_F(VkLayerTest, VtxBufferBadIndex) {
11205 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11208 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011209
Tobin Ehlis502480b2015-06-24 15:53:07 -060011210 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011211 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011213
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011214 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011215 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11216 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011217
11218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11220 ds_pool_ci.pNext = NULL;
11221 ds_pool_ci.maxSets = 1;
11222 ds_pool_ci.poolSizeCount = 1;
11223 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011224
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011225 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011226 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011227 ASSERT_VK_SUCCESS(err);
11228
Tony Barboureb254902015-07-15 12:50:33 -060011229 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011230 dsl_binding.binding = 0;
11231 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11232 dsl_binding.descriptorCount = 1;
11233 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11234 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011235
Tony Barboureb254902015-07-15 12:50:33 -060011236 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011237 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11238 ds_layout_ci.pNext = NULL;
11239 ds_layout_ci.bindingCount = 1;
11240 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011241
Tobin Ehlis502480b2015-06-24 15:53:07 -060011242 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011243 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011244 ASSERT_VK_SUCCESS(err);
11245
11246 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011247 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011248 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011249 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011250 alloc_info.descriptorPool = ds_pool;
11251 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011252 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011253 ASSERT_VK_SUCCESS(err);
11254
Tony Barboureb254902015-07-15 12:50:33 -060011255 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011256 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011257 pipe_ms_state_ci.pNext = NULL;
11258 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11259 pipe_ms_state_ci.sampleShadingEnable = 0;
11260 pipe_ms_state_ci.minSampleShading = 1.0;
11261 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011262
Tony Barboureb254902015-07-15 12:50:33 -060011263 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011264 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11265 pipeline_layout_ci.pNext = NULL;
11266 pipeline_layout_ci.setLayoutCount = 1;
11267 pipeline_layout_ci.pSetLayouts = &ds_layout;
11268 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011270 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011271 ASSERT_VK_SUCCESS(err);
11272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011273 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011274 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 -060011275 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011276 VkPipelineObj pipe(m_device);
11277 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011278 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011279 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011280 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011281 pipe.SetViewport(m_viewports);
11282 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011283 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011284
Tony Barbour552f6c02016-12-21 14:34:07 -070011285 m_commandBuffer->BeginCommandBuffer();
11286 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011287 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011288 // Don't care about actual data, just need to get to draw to flag error
11289 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011290 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011291 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011292 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011293
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011294 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011295
Chia-I Wuf7458c52015-10-26 21:10:41 +080011296 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11297 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11298 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011299}
Mark Muellerdfe37552016-07-07 14:47:42 -060011300
Mark Mueller2ee294f2016-08-04 12:59:48 -060011301TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011302 TEST_DESCRIPTION(
11303 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11304 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011305 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011306
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011307 const char *invalid_queueFamilyIndex_message =
11308 "Invalid queue create request in vkCreateDevice(). Invalid "
11309 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011311 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011312
Mark Mueller880fce52016-08-17 15:23:23 -060011313 // The following test fails with recent NVidia drivers.
11314 // By the time core_validation is reached, the NVidia
11315 // driver has sanitized the invalid condition and core_validation
11316 // is not introduced to the failure condition. This is not the case
11317 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011318 // uint32_t count = static_cast<uint32_t>(~0);
11319 // VkPhysicalDevice physical_device;
11320 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11321 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011324 float queue_priority = 0.0;
11325
11326 VkDeviceQueueCreateInfo queue_create_info = {};
11327 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11328 queue_create_info.queueCount = 1;
11329 queue_create_info.pQueuePriorities = &queue_priority;
11330 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11331
11332 VkPhysicalDeviceFeatures features = m_device->phy().features();
11333 VkDevice testDevice;
11334 VkDeviceCreateInfo device_create_info = {};
11335 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11336 device_create_info.queueCreateInfoCount = 1;
11337 device_create_info.pQueueCreateInfos = &queue_create_info;
11338 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011339 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011340 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11341 m_errorMonitor->VerifyFound();
11342
11343 queue_create_info.queueFamilyIndex = 1;
11344
11345 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11346 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11347 for (unsigned i = 0; i < feature_count; i++) {
11348 if (VK_FALSE == feature_array[i]) {
11349 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011351 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011352 m_errorMonitor->SetUnexpectedError(
11353 "You requested features that are unavailable on this device. You should first query feature availability by "
11354 "calling vkGetPhysicalDeviceFeatures().");
11355 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011356 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11357 m_errorMonitor->VerifyFound();
11358 break;
11359 }
11360 }
11361}
11362
Tobin Ehlis16edf082016-11-21 12:33:49 -070011363TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11364 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11365
11366 ASSERT_NO_FATAL_FAILURE(InitState());
11367
11368 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11369 std::vector<VkDeviceQueueCreateInfo> queue_info;
11370 queue_info.reserve(queue_props.size());
11371 std::vector<std::vector<float>> queue_priorities;
11372 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11373 VkDeviceQueueCreateInfo qi{};
11374 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11375 qi.queueFamilyIndex = i;
11376 qi.queueCount = queue_props[i].queueCount;
11377 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11378 qi.pQueuePriorities = queue_priorities[i].data();
11379 queue_info.push_back(qi);
11380 }
11381
11382 std::vector<const char *> device_extension_names;
11383
11384 VkDevice local_device;
11385 VkDeviceCreateInfo device_create_info = {};
11386 auto features = m_device->phy().features();
11387 // Intentionally disable pipeline stats
11388 features.pipelineStatisticsQuery = VK_FALSE;
11389 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11390 device_create_info.pNext = NULL;
11391 device_create_info.queueCreateInfoCount = queue_info.size();
11392 device_create_info.pQueueCreateInfos = queue_info.data();
11393 device_create_info.enabledLayerCount = 0;
11394 device_create_info.ppEnabledLayerNames = NULL;
11395 device_create_info.pEnabledFeatures = &features;
11396 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11397 ASSERT_VK_SUCCESS(err);
11398
11399 VkQueryPoolCreateInfo qpci{};
11400 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11401 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11402 qpci.queryCount = 1;
11403 VkQueryPool query_pool;
11404
11405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11406 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11407 m_errorMonitor->VerifyFound();
11408
11409 vkDestroyDevice(local_device, nullptr);
11410}
11411
Mark Mueller2ee294f2016-08-04 12:59:48 -060011412TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011413 TEST_DESCRIPTION(
11414 "Use an invalid queue index in a vkCmdWaitEvents call."
11415 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011416
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011417 const char *invalid_queue_index =
11418 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11419 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11420 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011421
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011422 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011425
11426 ASSERT_NO_FATAL_FAILURE(InitState());
11427
11428 VkEvent event;
11429 VkEventCreateInfo event_create_info{};
11430 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11431 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11432
Mark Mueller2ee294f2016-08-04 12:59:48 -060011433 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011434 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011435
Tony Barbour552f6c02016-12-21 14:34:07 -070011436 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011437
11438 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011439 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 -060011440 ASSERT_TRUE(image.initialized());
11441 VkImageMemoryBarrier img_barrier = {};
11442 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11443 img_barrier.pNext = NULL;
11444 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11445 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11446 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11447 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11448 img_barrier.image = image.handle();
11449 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011450
11451 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11452 // that layer validation catches the case when it is not.
11453 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011454 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11455 img_barrier.subresourceRange.baseArrayLayer = 0;
11456 img_barrier.subresourceRange.baseMipLevel = 0;
11457 img_barrier.subresourceRange.layerCount = 1;
11458 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011459 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11460 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011461 m_errorMonitor->VerifyFound();
11462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011464
11465 VkQueryPool query_pool;
11466 VkQueryPoolCreateInfo query_pool_create_info = {};
11467 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11468 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11469 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011470 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011472 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011473 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11474
11475 vkEndCommandBuffer(m_commandBuffer->handle());
11476 m_errorMonitor->VerifyFound();
11477
11478 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11479 vkDestroyEvent(m_device->device(), event, nullptr);
11480}
11481
Mark Muellerdfe37552016-07-07 14:47:42 -060011482TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011483 TEST_DESCRIPTION(
11484 "Submit a command buffer using deleted vertex buffer, "
11485 "delete a buffer twice, use an invalid offset for each "
11486 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011487
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011488 const char *deleted_buffer_in_command_buffer =
11489 "Cannot submit cmd buffer "
11490 "using deleted buffer ";
11491 const char *invalid_offset_message =
11492 "vkBindBufferMemory(): "
11493 "memoryOffset is 0x";
11494 const char *invalid_storage_buffer_offset_message =
11495 "vkBindBufferMemory(): "
11496 "storage memoryOffset "
11497 "is 0x";
11498 const char *invalid_texel_buffer_offset_message =
11499 "vkBindBufferMemory(): "
11500 "texel memoryOffset "
11501 "is 0x";
11502 const char *invalid_uniform_buffer_offset_message =
11503 "vkBindBufferMemory(): "
11504 "uniform memoryOffset "
11505 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011506
11507 ASSERT_NO_FATAL_FAILURE(InitState());
11508 ASSERT_NO_FATAL_FAILURE(InitViewport());
11509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11510
11511 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011512 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011513 pipe_ms_state_ci.pNext = NULL;
11514 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11515 pipe_ms_state_ci.sampleShadingEnable = 0;
11516 pipe_ms_state_ci.minSampleShading = 1.0;
11517 pipe_ms_state_ci.pSampleMask = nullptr;
11518
11519 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11520 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11521 VkPipelineLayout pipeline_layout;
11522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011523 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011524 ASSERT_VK_SUCCESS(err);
11525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011526 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11527 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011528 VkPipelineObj pipe(m_device);
11529 pipe.AddShader(&vs);
11530 pipe.AddShader(&fs);
11531 pipe.AddColorAttachment();
11532 pipe.SetMSAA(&pipe_ms_state_ci);
11533 pipe.SetViewport(m_viewports);
11534 pipe.SetScissor(m_scissors);
11535 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11536
Tony Barbour552f6c02016-12-21 14:34:07 -070011537 m_commandBuffer->BeginCommandBuffer();
11538 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011539 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011540
11541 {
11542 // Create and bind a vertex buffer in a reduced scope, which will cause
11543 // it to be deleted upon leaving this scope
11544 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011545 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011546 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11547 draw_verticies.AddVertexInputToPipe(pipe);
11548 }
11549
11550 Draw(1, 0, 0, 0);
11551
Tony Barbour552f6c02016-12-21 14:34:07 -070011552 m_commandBuffer->EndRenderPass();
11553 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011554
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011556 QueueCommandBuffer(false);
11557 m_errorMonitor->VerifyFound();
11558
11559 {
11560 // Create and bind a vertex buffer in a reduced scope, and delete it
11561 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011562 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011564 buffer_test.TestDoubleDestroy();
11565 }
11566 m_errorMonitor->VerifyFound();
11567
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011568 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011569 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011570 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011572 m_errorMonitor->SetUnexpectedError(
11573 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11574 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011575 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11576 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011577 m_errorMonitor->VerifyFound();
11578 }
11579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011580 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11581 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011582 // Create and bind a memory buffer with an invalid offset again,
11583 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011585 m_errorMonitor->SetUnexpectedError(
11586 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11587 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011588 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11589 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011590 m_errorMonitor->VerifyFound();
11591 }
11592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011593 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011594 // Create and bind a memory buffer with an invalid offset again, but
11595 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011597 m_errorMonitor->SetUnexpectedError(
11598 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11599 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011600 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11601 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011602 m_errorMonitor->VerifyFound();
11603 }
11604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011605 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011606 // Create and bind a memory buffer with an invalid offset again, but
11607 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011609 m_errorMonitor->SetUnexpectedError(
11610 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11611 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011612 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11613 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011614 m_errorMonitor->VerifyFound();
11615 }
11616
11617 {
11618 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011620 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11621 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011622 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11623 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011624 m_errorMonitor->VerifyFound();
11625 }
11626
11627 {
11628 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011630 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11631 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011632 }
11633 m_errorMonitor->VerifyFound();
11634
11635 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11636}
11637
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011638// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11639TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011640 TEST_DESCRIPTION(
11641 "Hit all possible validation checks associated with the "
11642 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11643 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011644 // 3 in ValidateCmdBufImageLayouts
11645 // * -1 Attempt to submit cmd buf w/ deleted image
11646 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11647 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011648
11649 ASSERT_NO_FATAL_FAILURE(InitState());
11650 // Create src & dst images to use for copy operations
11651 VkImage src_image;
11652 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011653 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011654
11655 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11656 const int32_t tex_width = 32;
11657 const int32_t tex_height = 32;
11658
11659 VkImageCreateInfo image_create_info = {};
11660 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11661 image_create_info.pNext = NULL;
11662 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11663 image_create_info.format = tex_format;
11664 image_create_info.extent.width = tex_width;
11665 image_create_info.extent.height = tex_height;
11666 image_create_info.extent.depth = 1;
11667 image_create_info.mipLevels = 1;
11668 image_create_info.arrayLayers = 4;
11669 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11670 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11671 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011672 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011673 image_create_info.flags = 0;
11674
11675 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11676 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011677 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011678 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11679 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011680 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11681 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11682 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11683 ASSERT_VK_SUCCESS(err);
11684
11685 // Allocate memory
11686 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011687 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011688 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011689 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11690 mem_alloc.pNext = NULL;
11691 mem_alloc.allocationSize = 0;
11692 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011693
11694 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011695 mem_alloc.allocationSize = img_mem_reqs.size;
11696 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011697 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011698 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011699 ASSERT_VK_SUCCESS(err);
11700
11701 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011702 mem_alloc.allocationSize = img_mem_reqs.size;
11703 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011704 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011705 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011706 ASSERT_VK_SUCCESS(err);
11707
11708 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011709 mem_alloc.allocationSize = img_mem_reqs.size;
11710 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011711 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011712 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011713 ASSERT_VK_SUCCESS(err);
11714
11715 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11716 ASSERT_VK_SUCCESS(err);
11717 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11718 ASSERT_VK_SUCCESS(err);
11719 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11720 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011721
Tony Barbour552f6c02016-12-21 14:34:07 -070011722 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011723 VkImageCopy copy_region;
11724 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11725 copy_region.srcSubresource.mipLevel = 0;
11726 copy_region.srcSubresource.baseArrayLayer = 0;
11727 copy_region.srcSubresource.layerCount = 1;
11728 copy_region.srcOffset.x = 0;
11729 copy_region.srcOffset.y = 0;
11730 copy_region.srcOffset.z = 0;
11731 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11732 copy_region.dstSubresource.mipLevel = 0;
11733 copy_region.dstSubresource.baseArrayLayer = 0;
11734 copy_region.dstSubresource.layerCount = 1;
11735 copy_region.dstOffset.x = 0;
11736 copy_region.dstOffset.y = 0;
11737 copy_region.dstOffset.z = 0;
11738 copy_region.extent.width = 1;
11739 copy_region.extent.height = 1;
11740 copy_region.extent.depth = 1;
11741
11742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11743 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011744 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011745 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 -060011746 m_errorMonitor->VerifyFound();
11747 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11749 "Cannot copy from an image whose source layout is "
11750 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11751 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011752 m_errorMonitor->SetUnexpectedError(
11753 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011754 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 -060011755 m_errorMonitor->VerifyFound();
11756 // Final src error is due to bad layout type
11757 m_errorMonitor->SetDesiredFailureMsg(
11758 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11759 "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 -070011760 m_errorMonitor->SetUnexpectedError(
11761 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11762 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011763 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 -060011764 m_errorMonitor->VerifyFound();
11765 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11767 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011768 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011769 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 -060011770 m_errorMonitor->VerifyFound();
11771 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11773 "Cannot copy from an image whose dest layout is "
11774 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11775 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011776 m_errorMonitor->SetUnexpectedError(
11777 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011778 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 -060011779 m_errorMonitor->VerifyFound();
11780 m_errorMonitor->SetDesiredFailureMsg(
11781 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11782 "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 -070011783 m_errorMonitor->SetUnexpectedError(
11784 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11785 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011786 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 -060011787 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011788
Cort3b021012016-12-07 12:00:57 -080011789 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11790 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11791 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11792 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11793 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11794 transfer_dst_image_barrier[0].srcAccessMask = 0;
11795 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11796 transfer_dst_image_barrier[0].image = dst_image;
11797 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11798 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11799 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11800 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11801 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11802 transfer_dst_image_barrier[0].image = depth_image;
11803 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11804 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11805 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11806
11807 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011808 VkClearColorValue color_clear_value = {};
11809 VkImageSubresourceRange clear_range;
11810 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11811 clear_range.baseMipLevel = 0;
11812 clear_range.baseArrayLayer = 0;
11813 clear_range.layerCount = 1;
11814 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011815
Cort3b021012016-12-07 12:00:57 -080011816 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11817 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011820 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011821 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011822 // Fail due to provided layout not matching actual current layout for color clear.
11823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011824 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011825 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011826
Cort530cf382016-12-08 09:59:47 -080011827 VkClearDepthStencilValue depth_clear_value = {};
11828 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011829
11830 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11831 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011834 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011835 m_errorMonitor->VerifyFound();
11836 // Fail due to provided layout not matching actual current layout for depth clear.
11837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011838 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011839 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011840
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011841 // Now cause error due to bad image layout transition in PipelineBarrier
11842 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011843 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011844 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011845 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011846 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011847 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11848 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011849 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11851 "You cannot transition the layout of aspect 1 from "
11852 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11853 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011854 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11855 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011856 m_errorMonitor->VerifyFound();
11857
11858 // Finally some layout errors at RenderPass create time
11859 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11860 VkAttachmentReference attach = {};
11861 // perf warning for GENERAL layout w/ non-DS input attachment
11862 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11863 VkSubpassDescription subpass = {};
11864 subpass.inputAttachmentCount = 1;
11865 subpass.pInputAttachments = &attach;
11866 VkRenderPassCreateInfo rpci = {};
11867 rpci.subpassCount = 1;
11868 rpci.pSubpasses = &subpass;
11869 rpci.attachmentCount = 1;
11870 VkAttachmentDescription attach_desc = {};
11871 attach_desc.format = VK_FORMAT_UNDEFINED;
11872 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011873 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011874 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11876 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011877 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11878 m_errorMonitor->VerifyFound();
11879 // error w/ non-general layout
11880 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11881
11882 m_errorMonitor->SetDesiredFailureMsg(
11883 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11884 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11885 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11886 m_errorMonitor->VerifyFound();
11887 subpass.inputAttachmentCount = 0;
11888 subpass.colorAttachmentCount = 1;
11889 subpass.pColorAttachments = &attach;
11890 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11891 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11893 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011894 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11895 m_errorMonitor->VerifyFound();
11896 // error w/ non-color opt or GENERAL layout for color attachment
11897 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11898 m_errorMonitor->SetDesiredFailureMsg(
11899 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11900 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11901 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11902 m_errorMonitor->VerifyFound();
11903 subpass.colorAttachmentCount = 0;
11904 subpass.pDepthStencilAttachment = &attach;
11905 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11906 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11908 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011909 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11910 m_errorMonitor->VerifyFound();
11911 // error w/ non-ds opt or GENERAL layout for color attachment
11912 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11914 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11915 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011916 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11917 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011918 // For this error we need a valid renderpass so create default one
11919 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11920 attach.attachment = 0;
11921 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11922 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11923 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11924 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11925 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11926 // Can't do a CLEAR load on READ_ONLY initialLayout
11927 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11928 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11929 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11931 " with invalid first layout "
11932 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11933 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011934 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11935 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011936
Cort3b021012016-12-07 12:00:57 -080011937 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11938 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11939 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011940 vkDestroyImage(m_device->device(), src_image, NULL);
11941 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011942 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011943}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011944
Tobin Ehlise0936662016-10-11 08:10:51 -060011945TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11946 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11947 VkResult err;
11948
11949 ASSERT_NO_FATAL_FAILURE(InitState());
11950
11951 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11952 VkImageTiling tiling;
11953 VkFormatProperties format_properties;
11954 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11955 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11956 tiling = VK_IMAGE_TILING_LINEAR;
11957 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11958 tiling = VK_IMAGE_TILING_OPTIMAL;
11959 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011960 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011961 return;
11962 }
11963
11964 VkDescriptorPoolSize ds_type = {};
11965 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11966 ds_type.descriptorCount = 1;
11967
11968 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11969 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11970 ds_pool_ci.maxSets = 1;
11971 ds_pool_ci.poolSizeCount = 1;
11972 ds_pool_ci.pPoolSizes = &ds_type;
11973 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11974
11975 VkDescriptorPool ds_pool;
11976 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11977 ASSERT_VK_SUCCESS(err);
11978
11979 VkDescriptorSetLayoutBinding dsl_binding = {};
11980 dsl_binding.binding = 0;
11981 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11982 dsl_binding.descriptorCount = 1;
11983 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11984 dsl_binding.pImmutableSamplers = NULL;
11985
11986 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11987 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11988 ds_layout_ci.pNext = NULL;
11989 ds_layout_ci.bindingCount = 1;
11990 ds_layout_ci.pBindings = &dsl_binding;
11991
11992 VkDescriptorSetLayout ds_layout;
11993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11994 ASSERT_VK_SUCCESS(err);
11995
11996 VkDescriptorSetAllocateInfo alloc_info = {};
11997 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11998 alloc_info.descriptorSetCount = 1;
11999 alloc_info.descriptorPool = ds_pool;
12000 alloc_info.pSetLayouts = &ds_layout;
12001 VkDescriptorSet descriptor_set;
12002 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12003 ASSERT_VK_SUCCESS(err);
12004
12005 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12006 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12007 pipeline_layout_ci.pNext = NULL;
12008 pipeline_layout_ci.setLayoutCount = 1;
12009 pipeline_layout_ci.pSetLayouts = &ds_layout;
12010 VkPipelineLayout pipeline_layout;
12011 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12012 ASSERT_VK_SUCCESS(err);
12013
12014 VkImageObj image(m_device);
12015 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
12016 ASSERT_TRUE(image.initialized());
12017 VkImageView view = image.targetView(tex_format);
12018
12019 VkDescriptorImageInfo image_info = {};
12020 image_info.imageView = view;
12021 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12022
12023 VkWriteDescriptorSet descriptor_write = {};
12024 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12025 descriptor_write.dstSet = descriptor_set;
12026 descriptor_write.dstBinding = 0;
12027 descriptor_write.descriptorCount = 1;
12028 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12029 descriptor_write.pImageInfo = &image_info;
12030
12031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12032 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12033 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12034 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12035 m_errorMonitor->VerifyFound();
12036
12037 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12038 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12039 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12040 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12041}
12042
Mark Mueller93b938f2016-08-18 10:27:40 -060012043TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012044 TEST_DESCRIPTION(
12045 "Use vkCmdExecuteCommands with invalid state "
12046 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012047
12048 ASSERT_NO_FATAL_FAILURE(InitState());
12049 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12050
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012051 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012052 const char *simultaneous_use_message2 =
12053 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12054 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012055
12056 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012057 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012058 command_buffer_allocate_info.commandPool = m_commandPool;
12059 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12060 command_buffer_allocate_info.commandBufferCount = 1;
12061
12062 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012063 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012064 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12065 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012066 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012067 command_buffer_inheritance_info.renderPass = m_renderPass;
12068 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012069
Mark Mueller93b938f2016-08-18 10:27:40 -060012070 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 command_buffer_begin_info.flags =
12072 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012073 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12074
12075 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12076 vkEndCommandBuffer(secondary_command_buffer);
12077
Mark Mueller93b938f2016-08-18 10:27:40 -060012078 VkSubmitInfo submit_info = {};
12079 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12080 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012081 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012082
Mark Mueller4042b652016-09-05 22:52:21 -060012083 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012084 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12086 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012087 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012088 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012089 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12090 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012091
Dave Houltonfbf52152017-01-06 12:55:29 -070012092 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012093 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012094 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012095
Mark Mueller4042b652016-09-05 22:52:21 -060012096 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012097 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12098 m_errorMonitor->SetUnexpectedError(
12099 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12100 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012101 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012102 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12105 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012106 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012107 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12108 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012109
12110 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012111
12112 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012113}
12114
Tony Barbour626994c2017-02-08 15:29:37 -070012115TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12116 TEST_DESCRIPTION(
12117 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12118 "errors");
12119 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12120 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12121 ASSERT_NO_FATAL_FAILURE(InitState());
12122
12123 VkCommandBuffer cmd_bufs[2];
12124 VkCommandBufferAllocateInfo alloc_info;
12125 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12126 alloc_info.pNext = NULL;
12127 alloc_info.commandBufferCount = 2;
12128 alloc_info.commandPool = m_commandPool;
12129 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12130 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12131
12132 VkCommandBufferBeginInfo cb_binfo;
12133 cb_binfo.pNext = NULL;
12134 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12135 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12136 cb_binfo.flags = 0;
12137 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12138 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12139 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12140 vkEndCommandBuffer(cmd_bufs[0]);
12141 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12142
12143 VkSubmitInfo submit_info = {};
12144 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12145 submit_info.commandBufferCount = 2;
12146 submit_info.pCommandBuffers = duplicates;
12147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12148 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12149 m_errorMonitor->VerifyFound();
12150 vkQueueWaitIdle(m_device->m_queue);
12151
12152 // Set one time use and now look for one time submit
12153 duplicates[0] = duplicates[1] = cmd_bufs[1];
12154 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12155 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12156 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12157 vkEndCommandBuffer(cmd_bufs[1]);
12158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12159 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12160 m_errorMonitor->VerifyFound();
12161 vkQueueWaitIdle(m_device->m_queue);
12162}
12163
Tobin Ehlisb093da82017-01-19 12:05:27 -070012164TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012165 TEST_DESCRIPTION(
12166 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12167 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012168
12169 ASSERT_NO_FATAL_FAILURE(InitState());
12170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12171
12172 std::vector<const char *> device_extension_names;
12173 auto features = m_device->phy().features();
12174 // Make sure gs & ts are disabled
12175 features.geometryShader = false;
12176 features.tessellationShader = false;
12177 // The sacrificial device object
12178 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12179
12180 VkCommandPoolCreateInfo pool_create_info{};
12181 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12182 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12183
12184 VkCommandPool command_pool;
12185 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12186
12187 VkCommandBufferAllocateInfo cmd = {};
12188 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12189 cmd.pNext = NULL;
12190 cmd.commandPool = command_pool;
12191 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12192 cmd.commandBufferCount = 1;
12193
12194 VkCommandBuffer cmd_buffer;
12195 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12196 ASSERT_VK_SUCCESS(err);
12197
12198 VkEvent event;
12199 VkEventCreateInfo evci = {};
12200 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12201 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12202 ASSERT_VK_SUCCESS(result);
12203
12204 VkCommandBufferBeginInfo cbbi = {};
12205 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12206 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12208 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12209 m_errorMonitor->VerifyFound();
12210
12211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12212 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12213 m_errorMonitor->VerifyFound();
12214
12215 vkDestroyEvent(test_device.handle(), event, NULL);
12216 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12217}
12218
Mark Mueller917f6bc2016-08-30 10:57:19 -060012219TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012220 TEST_DESCRIPTION(
12221 "Use vkCmdExecuteCommands with invalid state "
12222 "in primary and secondary command buffers. "
12223 "Delete objects that are inuse. Call VkQueueSubmit "
12224 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012225
12226 ASSERT_NO_FATAL_FAILURE(InitState());
12227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12228
Tony Barbour552f6c02016-12-21 14:34:07 -070012229 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012230
12231 VkEvent event;
12232 VkEventCreateInfo event_create_info = {};
12233 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12234 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012235 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012236
Tony Barbour552f6c02016-12-21 14:34:07 -070012237 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012238 vkDestroyEvent(m_device->device(), event, nullptr);
12239
12240 VkSubmitInfo submit_info = {};
12241 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12242 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012243 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012245 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12246 m_errorMonitor->VerifyFound();
12247
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012248 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012249 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12250
12251 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12252
Mark Mueller917f6bc2016-08-30 10:57:19 -060012253 VkSemaphoreCreateInfo semaphore_create_info = {};
12254 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12255 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012256 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012257 VkFenceCreateInfo fence_create_info = {};
12258 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12259 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012260 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012261
12262 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012263 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012264 descriptor_pool_type_count.descriptorCount = 1;
12265
12266 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12267 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12268 descriptor_pool_create_info.maxSets = 1;
12269 descriptor_pool_create_info.poolSizeCount = 1;
12270 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012271 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012272
12273 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012274 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012275
12276 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012277 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012278 descriptorset_layout_binding.descriptorCount = 1;
12279 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12280
12281 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012282 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012283 descriptorset_layout_create_info.bindingCount = 1;
12284 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12285
12286 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012287 ASSERT_VK_SUCCESS(
12288 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012289
12290 VkDescriptorSet descriptorset;
12291 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012292 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012293 descriptorset_allocate_info.descriptorSetCount = 1;
12294 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12295 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012296 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012297
Mark Mueller4042b652016-09-05 22:52:21 -060012298 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12299
12300 VkDescriptorBufferInfo buffer_info = {};
12301 buffer_info.buffer = buffer_test.GetBuffer();
12302 buffer_info.offset = 0;
12303 buffer_info.range = 1024;
12304
12305 VkWriteDescriptorSet write_descriptor_set = {};
12306 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12307 write_descriptor_set.dstSet = descriptorset;
12308 write_descriptor_set.descriptorCount = 1;
12309 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12310 write_descriptor_set.pBufferInfo = &buffer_info;
12311
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012312 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012313
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012314 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12315 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012316
12317 VkPipelineObj pipe(m_device);
12318 pipe.AddColorAttachment();
12319 pipe.AddShader(&vs);
12320 pipe.AddShader(&fs);
12321
12322 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012323 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012324 pipeline_layout_create_info.setLayoutCount = 1;
12325 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12326
12327 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012328 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012329
12330 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12331
Tony Barbour552f6c02016-12-21 14:34:07 -070012332 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012333 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012335 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12336 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12337 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012338
Tony Barbour552f6c02016-12-21 14:34:07 -070012339 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012340
Mark Mueller917f6bc2016-08-30 10:57:19 -060012341 submit_info.signalSemaphoreCount = 1;
12342 submit_info.pSignalSemaphores = &semaphore;
12343 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012344 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012345
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012347 vkDestroyEvent(m_device->device(), event, nullptr);
12348 m_errorMonitor->VerifyFound();
12349
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012351 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12352 m_errorMonitor->VerifyFound();
12353
Jeremy Hayes08369882017-02-02 10:31:06 -070012354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012355 vkDestroyFence(m_device->device(), fence, nullptr);
12356 m_errorMonitor->VerifyFound();
12357
Tobin Ehlis122207b2016-09-01 08:50:06 -070012358 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012359 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12360 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012361 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012362 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12363 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012364 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012365 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12366 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012367 vkDestroyEvent(m_device->device(), event, nullptr);
12368 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012369 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012370 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12371}
12372
Tobin Ehlis2adda372016-09-01 08:51:06 -070012373TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12374 TEST_DESCRIPTION("Delete in-use query pool.");
12375
12376 ASSERT_NO_FATAL_FAILURE(InitState());
12377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12378
12379 VkQueryPool query_pool;
12380 VkQueryPoolCreateInfo query_pool_ci{};
12381 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12382 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12383 query_pool_ci.queryCount = 1;
12384 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012385 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012386 // Reset query pool to create binding with cmd buffer
12387 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12388
Tony Barbour552f6c02016-12-21 14:34:07 -070012389 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012390
12391 VkSubmitInfo submit_info = {};
12392 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12393 submit_info.commandBufferCount = 1;
12394 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12395 // Submit cmd buffer and then destroy query pool while in-flight
12396 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12397
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012399 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12400 m_errorMonitor->VerifyFound();
12401
12402 vkQueueWaitIdle(m_device->m_queue);
12403 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012404 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12405 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012406 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12407}
12408
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012409TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12410 TEST_DESCRIPTION("Delete in-use pipeline.");
12411
12412 ASSERT_NO_FATAL_FAILURE(InitState());
12413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12414
12415 // Empty pipeline layout used for binding PSO
12416 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12417 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12418 pipeline_layout_ci.setLayoutCount = 0;
12419 pipeline_layout_ci.pSetLayouts = NULL;
12420
12421 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012422 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012423 ASSERT_VK_SUCCESS(err);
12424
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012426 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012427 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12428 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012429 // Store pipeline handle so we can actually delete it before test finishes
12430 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012431 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012432 VkPipelineObj pipe(m_device);
12433 pipe.AddShader(&vs);
12434 pipe.AddShader(&fs);
12435 pipe.AddColorAttachment();
12436 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12437 delete_this_pipeline = pipe.handle();
12438
Tony Barbour552f6c02016-12-21 14:34:07 -070012439 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012440 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012441 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012442
Tony Barbour552f6c02016-12-21 14:34:07 -070012443 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012444
12445 VkSubmitInfo submit_info = {};
12446 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12447 submit_info.commandBufferCount = 1;
12448 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12449 // Submit cmd buffer and then pipeline destroyed while in-flight
12450 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012451 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012452 m_errorMonitor->VerifyFound();
12453 // Make sure queue finished and then actually delete pipeline
12454 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012455 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12456 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012457 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12458 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12459}
12460
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012461TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12462 TEST_DESCRIPTION("Delete in-use imageView.");
12463
12464 ASSERT_NO_FATAL_FAILURE(InitState());
12465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12466
12467 VkDescriptorPoolSize ds_type_count;
12468 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12469 ds_type_count.descriptorCount = 1;
12470
12471 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12472 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12473 ds_pool_ci.maxSets = 1;
12474 ds_pool_ci.poolSizeCount = 1;
12475 ds_pool_ci.pPoolSizes = &ds_type_count;
12476
12477 VkDescriptorPool ds_pool;
12478 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12479 ASSERT_VK_SUCCESS(err);
12480
12481 VkSamplerCreateInfo sampler_ci = {};
12482 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12483 sampler_ci.pNext = NULL;
12484 sampler_ci.magFilter = VK_FILTER_NEAREST;
12485 sampler_ci.minFilter = VK_FILTER_NEAREST;
12486 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12487 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12488 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12489 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12490 sampler_ci.mipLodBias = 1.0;
12491 sampler_ci.anisotropyEnable = VK_FALSE;
12492 sampler_ci.maxAnisotropy = 1;
12493 sampler_ci.compareEnable = VK_FALSE;
12494 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12495 sampler_ci.minLod = 1.0;
12496 sampler_ci.maxLod = 1.0;
12497 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12498 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12499 VkSampler sampler;
12500
12501 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12502 ASSERT_VK_SUCCESS(err);
12503
12504 VkDescriptorSetLayoutBinding layout_binding;
12505 layout_binding.binding = 0;
12506 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12507 layout_binding.descriptorCount = 1;
12508 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12509 layout_binding.pImmutableSamplers = NULL;
12510
12511 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12512 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12513 ds_layout_ci.bindingCount = 1;
12514 ds_layout_ci.pBindings = &layout_binding;
12515 VkDescriptorSetLayout ds_layout;
12516 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12517 ASSERT_VK_SUCCESS(err);
12518
12519 VkDescriptorSetAllocateInfo alloc_info = {};
12520 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12521 alloc_info.descriptorSetCount = 1;
12522 alloc_info.descriptorPool = ds_pool;
12523 alloc_info.pSetLayouts = &ds_layout;
12524 VkDescriptorSet descriptor_set;
12525 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12526 ASSERT_VK_SUCCESS(err);
12527
12528 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12529 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12530 pipeline_layout_ci.pNext = NULL;
12531 pipeline_layout_ci.setLayoutCount = 1;
12532 pipeline_layout_ci.pSetLayouts = &ds_layout;
12533
12534 VkPipelineLayout pipeline_layout;
12535 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12536 ASSERT_VK_SUCCESS(err);
12537
12538 VkImageObj image(m_device);
12539 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12540 ASSERT_TRUE(image.initialized());
12541
12542 VkImageView view;
12543 VkImageViewCreateInfo ivci = {};
12544 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12545 ivci.image = image.handle();
12546 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12547 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12548 ivci.subresourceRange.layerCount = 1;
12549 ivci.subresourceRange.baseMipLevel = 0;
12550 ivci.subresourceRange.levelCount = 1;
12551 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12552
12553 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12554 ASSERT_VK_SUCCESS(err);
12555
12556 VkDescriptorImageInfo image_info{};
12557 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12558 image_info.imageView = view;
12559 image_info.sampler = sampler;
12560
12561 VkWriteDescriptorSet descriptor_write = {};
12562 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12563 descriptor_write.dstSet = descriptor_set;
12564 descriptor_write.dstBinding = 0;
12565 descriptor_write.descriptorCount = 1;
12566 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12567 descriptor_write.pImageInfo = &image_info;
12568
12569 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12570
12571 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012572 char const *vsSource =
12573 "#version 450\n"
12574 "\n"
12575 "out gl_PerVertex { \n"
12576 " vec4 gl_Position;\n"
12577 "};\n"
12578 "void main(){\n"
12579 " gl_Position = vec4(1);\n"
12580 "}\n";
12581 char const *fsSource =
12582 "#version 450\n"
12583 "\n"
12584 "layout(set=0, binding=0) uniform sampler2D s;\n"
12585 "layout(location=0) out vec4 x;\n"
12586 "void main(){\n"
12587 " x = texture(s, vec2(1));\n"
12588 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012589 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12590 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12591 VkPipelineObj pipe(m_device);
12592 pipe.AddShader(&vs);
12593 pipe.AddShader(&fs);
12594 pipe.AddColorAttachment();
12595 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12596
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012598
Tony Barbour552f6c02016-12-21 14:34:07 -070012599 m_commandBuffer->BeginCommandBuffer();
12600 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012601 // Bind pipeline to cmd buffer
12602 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12603 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12604 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012605
12606 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12607 VkRect2D scissor = {{0, 0}, {16, 16}};
12608 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12609 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12610
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012611 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012612 m_commandBuffer->EndRenderPass();
12613 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012614 // Submit cmd buffer then destroy sampler
12615 VkSubmitInfo submit_info = {};
12616 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12617 submit_info.commandBufferCount = 1;
12618 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12619 // Submit cmd buffer and then destroy imageView while in-flight
12620 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12621
12622 vkDestroyImageView(m_device->device(), view, nullptr);
12623 m_errorMonitor->VerifyFound();
12624 vkQueueWaitIdle(m_device->m_queue);
12625 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012626 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12627 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012628 vkDestroyImageView(m_device->device(), view, NULL);
12629 vkDestroySampler(m_device->device(), sampler, nullptr);
12630 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12631 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12632 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12633}
12634
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012635TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12636 TEST_DESCRIPTION("Delete in-use bufferView.");
12637
12638 ASSERT_NO_FATAL_FAILURE(InitState());
12639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12640
12641 VkDescriptorPoolSize ds_type_count;
12642 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12643 ds_type_count.descriptorCount = 1;
12644
12645 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12646 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12647 ds_pool_ci.maxSets = 1;
12648 ds_pool_ci.poolSizeCount = 1;
12649 ds_pool_ci.pPoolSizes = &ds_type_count;
12650
12651 VkDescriptorPool ds_pool;
12652 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12653 ASSERT_VK_SUCCESS(err);
12654
12655 VkDescriptorSetLayoutBinding layout_binding;
12656 layout_binding.binding = 0;
12657 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12658 layout_binding.descriptorCount = 1;
12659 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12660 layout_binding.pImmutableSamplers = NULL;
12661
12662 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12663 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12664 ds_layout_ci.bindingCount = 1;
12665 ds_layout_ci.pBindings = &layout_binding;
12666 VkDescriptorSetLayout ds_layout;
12667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12668 ASSERT_VK_SUCCESS(err);
12669
12670 VkDescriptorSetAllocateInfo alloc_info = {};
12671 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12672 alloc_info.descriptorSetCount = 1;
12673 alloc_info.descriptorPool = ds_pool;
12674 alloc_info.pSetLayouts = &ds_layout;
12675 VkDescriptorSet descriptor_set;
12676 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12677 ASSERT_VK_SUCCESS(err);
12678
12679 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12680 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12681 pipeline_layout_ci.pNext = NULL;
12682 pipeline_layout_ci.setLayoutCount = 1;
12683 pipeline_layout_ci.pSetLayouts = &ds_layout;
12684
12685 VkPipelineLayout pipeline_layout;
12686 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12687 ASSERT_VK_SUCCESS(err);
12688
12689 VkBuffer buffer;
12690 uint32_t queue_family_index = 0;
12691 VkBufferCreateInfo buffer_create_info = {};
12692 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12693 buffer_create_info.size = 1024;
12694 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12695 buffer_create_info.queueFamilyIndexCount = 1;
12696 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12697
12698 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12699 ASSERT_VK_SUCCESS(err);
12700
12701 VkMemoryRequirements memory_reqs;
12702 VkDeviceMemory buffer_memory;
12703
12704 VkMemoryAllocateInfo memory_info = {};
12705 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12706 memory_info.allocationSize = 0;
12707 memory_info.memoryTypeIndex = 0;
12708
12709 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12710 memory_info.allocationSize = memory_reqs.size;
12711 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12712 ASSERT_TRUE(pass);
12713
12714 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12715 ASSERT_VK_SUCCESS(err);
12716 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12717 ASSERT_VK_SUCCESS(err);
12718
12719 VkBufferView view;
12720 VkBufferViewCreateInfo bvci = {};
12721 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12722 bvci.buffer = buffer;
12723 bvci.format = VK_FORMAT_R8_UNORM;
12724 bvci.range = VK_WHOLE_SIZE;
12725
12726 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12727 ASSERT_VK_SUCCESS(err);
12728
12729 VkWriteDescriptorSet descriptor_write = {};
12730 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12731 descriptor_write.dstSet = descriptor_set;
12732 descriptor_write.dstBinding = 0;
12733 descriptor_write.descriptorCount = 1;
12734 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12735 descriptor_write.pTexelBufferView = &view;
12736
12737 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12738
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012739 char const *vsSource =
12740 "#version 450\n"
12741 "\n"
12742 "out gl_PerVertex { \n"
12743 " vec4 gl_Position;\n"
12744 "};\n"
12745 "void main(){\n"
12746 " gl_Position = vec4(1);\n"
12747 "}\n";
12748 char const *fsSource =
12749 "#version 450\n"
12750 "\n"
12751 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12752 "layout(location=0) out vec4 x;\n"
12753 "void main(){\n"
12754 " x = imageLoad(s, 0);\n"
12755 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012756 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12757 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12758 VkPipelineObj pipe(m_device);
12759 pipe.AddShader(&vs);
12760 pipe.AddShader(&fs);
12761 pipe.AddColorAttachment();
12762 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12763
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012765
Tony Barbour552f6c02016-12-21 14:34:07 -070012766 m_commandBuffer->BeginCommandBuffer();
12767 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012768 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12769 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12770 VkRect2D scissor = {{0, 0}, {16, 16}};
12771 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12772 // Bind pipeline to cmd buffer
12773 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12774 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12775 &descriptor_set, 0, nullptr);
12776 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012777 m_commandBuffer->EndRenderPass();
12778 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012779
12780 VkSubmitInfo submit_info = {};
12781 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12782 submit_info.commandBufferCount = 1;
12783 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12784 // Submit cmd buffer and then destroy bufferView while in-flight
12785 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12786
12787 vkDestroyBufferView(m_device->device(), view, nullptr);
12788 m_errorMonitor->VerifyFound();
12789 vkQueueWaitIdle(m_device->m_queue);
12790 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012791 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12792 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012793 vkDestroyBufferView(m_device->device(), view, NULL);
12794 vkDestroyBuffer(m_device->device(), buffer, NULL);
12795 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12796 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12797 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12798 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12799}
12800
Tobin Ehlis209532e2016-09-07 13:52:18 -060012801TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12802 TEST_DESCRIPTION("Delete in-use sampler.");
12803
12804 ASSERT_NO_FATAL_FAILURE(InitState());
12805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12806
12807 VkDescriptorPoolSize ds_type_count;
12808 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12809 ds_type_count.descriptorCount = 1;
12810
12811 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12812 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12813 ds_pool_ci.maxSets = 1;
12814 ds_pool_ci.poolSizeCount = 1;
12815 ds_pool_ci.pPoolSizes = &ds_type_count;
12816
12817 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012818 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012819 ASSERT_VK_SUCCESS(err);
12820
12821 VkSamplerCreateInfo sampler_ci = {};
12822 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12823 sampler_ci.pNext = NULL;
12824 sampler_ci.magFilter = VK_FILTER_NEAREST;
12825 sampler_ci.minFilter = VK_FILTER_NEAREST;
12826 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12827 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12828 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12829 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12830 sampler_ci.mipLodBias = 1.0;
12831 sampler_ci.anisotropyEnable = VK_FALSE;
12832 sampler_ci.maxAnisotropy = 1;
12833 sampler_ci.compareEnable = VK_FALSE;
12834 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12835 sampler_ci.minLod = 1.0;
12836 sampler_ci.maxLod = 1.0;
12837 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12838 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12839 VkSampler sampler;
12840
12841 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12842 ASSERT_VK_SUCCESS(err);
12843
12844 VkDescriptorSetLayoutBinding layout_binding;
12845 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012846 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012847 layout_binding.descriptorCount = 1;
12848 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12849 layout_binding.pImmutableSamplers = NULL;
12850
12851 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12852 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12853 ds_layout_ci.bindingCount = 1;
12854 ds_layout_ci.pBindings = &layout_binding;
12855 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012856 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012857 ASSERT_VK_SUCCESS(err);
12858
12859 VkDescriptorSetAllocateInfo alloc_info = {};
12860 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12861 alloc_info.descriptorSetCount = 1;
12862 alloc_info.descriptorPool = ds_pool;
12863 alloc_info.pSetLayouts = &ds_layout;
12864 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012865 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012866 ASSERT_VK_SUCCESS(err);
12867
12868 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12869 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12870 pipeline_layout_ci.pNext = NULL;
12871 pipeline_layout_ci.setLayoutCount = 1;
12872 pipeline_layout_ci.pSetLayouts = &ds_layout;
12873
12874 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012875 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012876 ASSERT_VK_SUCCESS(err);
12877
12878 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012879 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 -060012880 ASSERT_TRUE(image.initialized());
12881
12882 VkImageView view;
12883 VkImageViewCreateInfo ivci = {};
12884 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12885 ivci.image = image.handle();
12886 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12887 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12888 ivci.subresourceRange.layerCount = 1;
12889 ivci.subresourceRange.baseMipLevel = 0;
12890 ivci.subresourceRange.levelCount = 1;
12891 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12892
12893 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12894 ASSERT_VK_SUCCESS(err);
12895
12896 VkDescriptorImageInfo image_info{};
12897 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12898 image_info.imageView = view;
12899 image_info.sampler = sampler;
12900
12901 VkWriteDescriptorSet descriptor_write = {};
12902 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12903 descriptor_write.dstSet = descriptor_set;
12904 descriptor_write.dstBinding = 0;
12905 descriptor_write.descriptorCount = 1;
12906 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12907 descriptor_write.pImageInfo = &image_info;
12908
12909 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12910
12911 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012912 char const *vsSource =
12913 "#version 450\n"
12914 "\n"
12915 "out gl_PerVertex { \n"
12916 " vec4 gl_Position;\n"
12917 "};\n"
12918 "void main(){\n"
12919 " gl_Position = vec4(1);\n"
12920 "}\n";
12921 char const *fsSource =
12922 "#version 450\n"
12923 "\n"
12924 "layout(set=0, binding=0) uniform sampler2D s;\n"
12925 "layout(location=0) out vec4 x;\n"
12926 "void main(){\n"
12927 " x = texture(s, vec2(1));\n"
12928 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12931 VkPipelineObj pipe(m_device);
12932 pipe.AddShader(&vs);
12933 pipe.AddShader(&fs);
12934 pipe.AddColorAttachment();
12935 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12936
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012938
Tony Barbour552f6c02016-12-21 14:34:07 -070012939 m_commandBuffer->BeginCommandBuffer();
12940 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012941 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012942 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12943 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12944 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012945
12946 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12947 VkRect2D scissor = {{0, 0}, {16, 16}};
12948 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12949 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12950
Tobin Ehlis209532e2016-09-07 13:52:18 -060012951 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012952 m_commandBuffer->EndRenderPass();
12953 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012954 // Submit cmd buffer then destroy sampler
12955 VkSubmitInfo submit_info = {};
12956 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12957 submit_info.commandBufferCount = 1;
12958 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12959 // Submit cmd buffer and then destroy sampler while in-flight
12960 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12961
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012962 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012963 m_errorMonitor->VerifyFound();
12964 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012965
Tobin Ehlis209532e2016-09-07 13:52:18 -060012966 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012967 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12968 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012969 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012970 vkDestroyImageView(m_device->device(), view, NULL);
12971 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12973 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12974}
12975
Mark Mueller1cd9f412016-08-25 13:23:52 -060012976TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012977 TEST_DESCRIPTION(
12978 "Call VkQueueSubmit with a semaphore that is already "
12979 "signaled but not waited on by the queue. Wait on a "
12980 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012981
12982 ASSERT_NO_FATAL_FAILURE(InitState());
12983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012985 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 -070012986 const char *invalid_fence_wait_message =
12987 " which has not been submitted on a Queue or during "
12988 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012989
Tony Barbour552f6c02016-12-21 14:34:07 -070012990 m_commandBuffer->BeginCommandBuffer();
12991 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012992
12993 VkSemaphoreCreateInfo semaphore_create_info = {};
12994 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12995 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012996 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012997 VkSubmitInfo submit_info = {};
12998 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12999 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013000 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013001 submit_info.signalSemaphoreCount = 1;
13002 submit_info.pSignalSemaphores = &semaphore;
13003 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070013004 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060013005 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070013006 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070013007 m_commandBuffer->BeginCommandBuffer();
13008 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013010 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13011 m_errorMonitor->VerifyFound();
13012
Mark Mueller1cd9f412016-08-25 13:23:52 -060013013 VkFenceCreateInfo fence_create_info = {};
13014 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13015 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013016 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013019 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13020 m_errorMonitor->VerifyFound();
13021
Mark Mueller4042b652016-09-05 22:52:21 -060013022 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013023 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013024 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13025}
13026
Tobin Ehlis4af23302016-07-19 10:50:30 -060013027TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013028 TEST_DESCRIPTION(
13029 "Bind a secondary command buffer with with a framebuffer "
13030 "that does not match the framebuffer for the active "
13031 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013032 ASSERT_NO_FATAL_FAILURE(InitState());
13033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13034
13035 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013036 VkAttachmentDescription attachment = {0,
13037 VK_FORMAT_B8G8R8A8_UNORM,
13038 VK_SAMPLE_COUNT_1_BIT,
13039 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13040 VK_ATTACHMENT_STORE_OP_STORE,
13041 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13042 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13043 VK_IMAGE_LAYOUT_UNDEFINED,
13044 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013046 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013050 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013051
13052 VkRenderPass rp;
13053 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13054 ASSERT_VK_SUCCESS(err);
13055
13056 // A compatible framebuffer.
13057 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013058 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 -060013059 ASSERT_TRUE(image.initialized());
13060
13061 VkImageViewCreateInfo ivci = {
13062 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13063 nullptr,
13064 0,
13065 image.handle(),
13066 VK_IMAGE_VIEW_TYPE_2D,
13067 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013068 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13069 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013070 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13071 };
13072 VkImageView view;
13073 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13074 ASSERT_VK_SUCCESS(err);
13075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013076 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013077 VkFramebuffer fb;
13078 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13079 ASSERT_VK_SUCCESS(err);
13080
13081 VkCommandBufferAllocateInfo cbai = {};
13082 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13083 cbai.commandPool = m_commandPool;
13084 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13085 cbai.commandBufferCount = 1;
13086
13087 VkCommandBuffer sec_cb;
13088 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13089 ASSERT_VK_SUCCESS(err);
13090 VkCommandBufferBeginInfo cbbi = {};
13091 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013092 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013093 cbii.renderPass = renderPass();
13094 cbii.framebuffer = fb;
13095 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13096 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013097 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 -060013098 cbbi.pInheritanceInfo = &cbii;
13099 vkBeginCommandBuffer(sec_cb, &cbbi);
13100 vkEndCommandBuffer(sec_cb);
13101
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013102 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013103 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13104 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013107 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013108 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13109 m_errorMonitor->VerifyFound();
13110 // Cleanup
13111 vkDestroyImageView(m_device->device(), view, NULL);
13112 vkDestroyRenderPass(m_device->device(), rp, NULL);
13113 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13114}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013115
13116TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013117 TEST_DESCRIPTION(
13118 "If logicOp is available on the device, set it to an "
13119 "invalid value. If logicOp is not available, attempt to "
13120 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013121 ASSERT_NO_FATAL_FAILURE(InitState());
13122 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13123
13124 auto features = m_device->phy().features();
13125 // Set the expected error depending on whether or not logicOp available
13126 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13128 "If logic operations feature not "
13129 "enabled, logicOpEnable must be "
13130 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013131 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013133 }
13134 // Create a pipeline using logicOp
13135 VkResult err;
13136
13137 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13138 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13139
13140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013141 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013142 ASSERT_VK_SUCCESS(err);
13143
13144 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13145 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13146 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013147 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013148 vp_state_ci.pViewports = &vp;
13149 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013150 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013151 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013152
13153 VkPipelineShaderStageCreateInfo shaderStages[2];
13154 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013156 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13157 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013158 shaderStages[0] = vs.GetStageCreateInfo();
13159 shaderStages[1] = fs.GetStageCreateInfo();
13160
13161 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13162 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13163
13164 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13165 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13166 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13167
13168 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13169 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013170 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013171
13172 VkPipelineColorBlendAttachmentState att = {};
13173 att.blendEnable = VK_FALSE;
13174 att.colorWriteMask = 0xf;
13175
13176 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13177 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13178 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13179 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013180 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013181 cb_ci.attachmentCount = 1;
13182 cb_ci.pAttachments = &att;
13183
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013184 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13185 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13186 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13187
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013188 VkGraphicsPipelineCreateInfo gp_ci = {};
13189 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13190 gp_ci.stageCount = 2;
13191 gp_ci.pStages = shaderStages;
13192 gp_ci.pVertexInputState = &vi_ci;
13193 gp_ci.pInputAssemblyState = &ia_ci;
13194 gp_ci.pViewportState = &vp_state_ci;
13195 gp_ci.pRasterizationState = &rs_ci;
13196 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013197 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013198 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13199 gp_ci.layout = pipeline_layout;
13200 gp_ci.renderPass = renderPass();
13201
13202 VkPipelineCacheCreateInfo pc_ci = {};
13203 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13204
13205 VkPipeline pipeline;
13206 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013207 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013208 ASSERT_VK_SUCCESS(err);
13209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013210 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013211 m_errorMonitor->VerifyFound();
13212 if (VK_SUCCESS == err) {
13213 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13214 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013215 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13216 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13217}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013218
Mike Stroyanaccf7692015-05-12 16:00:45 -060013219#if GTEST_IS_THREADSAFE
13220struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013221 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013222 VkEvent event;
13223 bool bailout;
13224};
13225
Karl Schultz6addd812016-02-02 17:17:23 -070013226extern "C" void *AddToCommandBuffer(void *arg) {
13227 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013228
Mike Stroyana6d14942016-07-13 15:10:05 -060013229 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013230 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013231 if (data->bailout) {
13232 break;
13233 }
13234 }
13235 return NULL;
13236}
13237
Karl Schultz6addd812016-02-02 17:17:23 -070013238TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013239 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013242
Mike Stroyanaccf7692015-05-12 16:00:45 -060013243 ASSERT_NO_FATAL_FAILURE(InitState());
13244 ASSERT_NO_FATAL_FAILURE(InitViewport());
13245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13246
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013247 // Calls AllocateCommandBuffers
13248 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013249
13250 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013251 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013252
13253 VkEventCreateInfo event_info;
13254 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013255 VkResult err;
13256
13257 memset(&event_info, 0, sizeof(event_info));
13258 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13259
Chia-I Wuf7458c52015-10-26 21:10:41 +080013260 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013261 ASSERT_VK_SUCCESS(err);
13262
Mike Stroyanaccf7692015-05-12 16:00:45 -060013263 err = vkResetEvent(device(), event);
13264 ASSERT_VK_SUCCESS(err);
13265
13266 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013267 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013268 data.event = event;
13269 data.bailout = false;
13270 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013271
13272 // First do some correct operations using multiple threads.
13273 // Add many entries to command buffer from another thread.
13274 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13275 // Make non-conflicting calls from this thread at the same time.
13276 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013277 uint32_t count;
13278 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013279 }
13280 test_platform_thread_join(thread, NULL);
13281
13282 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013283 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013284 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013285 // Add many entries to command buffer from this thread at the same time.
13286 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013287
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013288 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013289 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013290
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013291 m_errorMonitor->SetBailout(NULL);
13292
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013293 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013294
Chia-I Wuf7458c52015-10-26 21:10:41 +080013295 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013296}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013297#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013298
Karl Schultz6addd812016-02-02 17:17:23 -070013299TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013300 TEST_DESCRIPTION(
13301 "Test that an error is produced for a spirv module "
13302 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013305
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013306 ASSERT_NO_FATAL_FAILURE(InitState());
13307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13308
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013309 VkShaderModule module;
13310 VkShaderModuleCreateInfo moduleCreateInfo;
13311 struct icd_spv_header spv;
13312
13313 spv.magic = ICD_SPV_MAGIC;
13314 spv.version = ICD_SPV_VERSION;
13315 spv.gen_magic = 0;
13316
13317 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13318 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013319 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013320 moduleCreateInfo.codeSize = 4;
13321 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013322 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013323
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013324 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013325}
13326
Karl Schultz6addd812016-02-02 17:17:23 -070013327TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013328 TEST_DESCRIPTION(
13329 "Test that an error is produced for a spirv module "
13330 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013333
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013334 ASSERT_NO_FATAL_FAILURE(InitState());
13335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13336
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013337 VkShaderModule module;
13338 VkShaderModuleCreateInfo moduleCreateInfo;
13339 struct icd_spv_header spv;
13340
13341 spv.magic = ~ICD_SPV_MAGIC;
13342 spv.version = ICD_SPV_VERSION;
13343 spv.gen_magic = 0;
13344
13345 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13346 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013347 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013348 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13349 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013350 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013351
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013352 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013353}
13354
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013355#if 0
13356// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013357TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013359 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013360
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013361 ASSERT_NO_FATAL_FAILURE(InitState());
13362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13363
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013364 VkShaderModule module;
13365 VkShaderModuleCreateInfo moduleCreateInfo;
13366 struct icd_spv_header spv;
13367
13368 spv.magic = ICD_SPV_MAGIC;
13369 spv.version = ~ICD_SPV_VERSION;
13370 spv.gen_magic = 0;
13371
13372 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13373 moduleCreateInfo.pNext = NULL;
13374
Karl Schultz6addd812016-02-02 17:17:23 -070013375 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013376 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13377 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013378 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013379
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013380 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013381}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013382#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013383
Karl Schultz6addd812016-02-02 17:17:23 -070013384TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013385 TEST_DESCRIPTION(
13386 "Test that a warning is produced for a vertex output that "
13387 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013389
Chris Forbes9f7ff632015-05-25 11:13:08 +120013390 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013392
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013393 char const *vsSource =
13394 "#version 450\n"
13395 "\n"
13396 "layout(location=0) out float x;\n"
13397 "out gl_PerVertex {\n"
13398 " vec4 gl_Position;\n"
13399 "};\n"
13400 "void main(){\n"
13401 " gl_Position = vec4(1);\n"
13402 " x = 0;\n"
13403 "}\n";
13404 char const *fsSource =
13405 "#version 450\n"
13406 "\n"
13407 "layout(location=0) out vec4 color;\n"
13408 "void main(){\n"
13409 " color = vec4(1);\n"
13410 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013411
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013414
13415 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013416 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013417 pipe.AddShader(&vs);
13418 pipe.AddShader(&fs);
13419
Chris Forbes9f7ff632015-05-25 11:13:08 +120013420 VkDescriptorSetObj descriptorSet(m_device);
13421 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013422 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013423
Tony Barbour5781e8f2015-08-04 16:23:11 -060013424 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013425
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013426 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013427}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013428
Mark Mueller098c9cb2016-09-08 09:01:57 -060013429TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13430 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13431
13432 ASSERT_NO_FATAL_FAILURE(InitState());
13433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13434
13435 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013436 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013437
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013438 char const *vsSource =
13439 "#version 450\n"
13440 "\n"
13441 "out gl_PerVertex {\n"
13442 " vec4 gl_Position;\n"
13443 "};\n"
13444 "void main(){\n"
13445 " gl_Position = vec4(1);\n"
13446 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013447
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013448 char const *fsSource =
13449 "#version 450\n"
13450 "\n"
13451 "layout (constant_id = 0) const float r = 0.0f;\n"
13452 "layout(location = 0) out vec4 uFragColor;\n"
13453 "void main(){\n"
13454 " uFragColor = vec4(r,1,0,1);\n"
13455 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013456
13457 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13458 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13459
13460 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13461 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13462
13463 VkPipelineLayout pipeline_layout;
13464 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13465
13466 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13467 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13468 vp_state_create_info.viewportCount = 1;
13469 VkViewport viewport = {};
13470 vp_state_create_info.pViewports = &viewport;
13471 vp_state_create_info.scissorCount = 1;
13472 VkRect2D scissors = {};
13473 vp_state_create_info.pScissors = &scissors;
13474
13475 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13476
13477 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13478 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13479 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13480 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13481
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013482 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013483
13484 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13485 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13486
13487 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13488 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13489 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13490
13491 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13492 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13493 rasterization_state_create_info.pNext = nullptr;
13494 rasterization_state_create_info.lineWidth = 1.0f;
13495 rasterization_state_create_info.rasterizerDiscardEnable = true;
13496
13497 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13498 color_blend_attachment_state.blendEnable = VK_FALSE;
13499 color_blend_attachment_state.colorWriteMask = 0xf;
13500
13501 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13502 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13503 color_blend_state_create_info.attachmentCount = 1;
13504 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13505
13506 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13507 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13508 graphicspipe_create_info.stageCount = 2;
13509 graphicspipe_create_info.pStages = shader_stage_create_info;
13510 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13511 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13512 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13513 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13514 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13515 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13516 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13517 graphicspipe_create_info.layout = pipeline_layout;
13518 graphicspipe_create_info.renderPass = renderPass();
13519
13520 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13521 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13522
13523 VkPipelineCache pipelineCache;
13524 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13525
13526 // This structure maps constant ids to data locations.
13527 const VkSpecializationMapEntry entry =
13528 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013529 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013530
13531 uint32_t data = 1;
13532
13533 // Set up the info describing spec map and data
13534 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013535 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013536 };
13537 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13538
13539 VkPipeline pipeline;
13540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13541 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13542 m_errorMonitor->VerifyFound();
13543
13544 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13545 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13546}
13547
13548TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13549 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13550
13551 ASSERT_NO_FATAL_FAILURE(InitState());
13552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13553
13554 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13555
13556 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13557 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13558 descriptor_pool_type_count[0].descriptorCount = 1;
13559 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13560 descriptor_pool_type_count[1].descriptorCount = 1;
13561
13562 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13563 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13564 descriptor_pool_create_info.maxSets = 1;
13565 descriptor_pool_create_info.poolSizeCount = 2;
13566 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13567 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13568
13569 VkDescriptorPool descriptorset_pool;
13570 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13571
13572 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13573 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13574 descriptorset_layout_binding.descriptorCount = 1;
13575 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13576
13577 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13578 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13579 descriptorset_layout_create_info.bindingCount = 1;
13580 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13581
13582 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013583 ASSERT_VK_SUCCESS(
13584 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013585
13586 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13587 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13588 descriptorset_allocate_info.descriptorSetCount = 1;
13589 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13590 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13591 VkDescriptorSet descriptorset;
13592 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13593
13594 // Challenge core_validation with a non uniform buffer type.
13595 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13596
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013597 char const *vsSource =
13598 "#version 450\n"
13599 "\n"
13600 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13601 " mat4 mvp;\n"
13602 "} ubuf;\n"
13603 "out gl_PerVertex {\n"
13604 " vec4 gl_Position;\n"
13605 "};\n"
13606 "void main(){\n"
13607 " gl_Position = ubuf.mvp * vec4(1);\n"
13608 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013609
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013610 char const *fsSource =
13611 "#version 450\n"
13612 "\n"
13613 "layout(location = 0) out vec4 uFragColor;\n"
13614 "void main(){\n"
13615 " uFragColor = vec4(0,1,0,1);\n"
13616 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013617
13618 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13619 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13620
13621 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13622 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13623 pipeline_layout_create_info.setLayoutCount = 1;
13624 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13625
13626 VkPipelineLayout pipeline_layout;
13627 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13628
13629 VkPipelineObj pipe(m_device);
13630 pipe.AddColorAttachment();
13631 pipe.AddShader(&vs);
13632 pipe.AddShader(&fs);
13633
13634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13635 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13636 m_errorMonitor->VerifyFound();
13637
13638 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13639 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13640 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13641}
13642
13643TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13644 TEST_DESCRIPTION(
13645 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13646
13647 ASSERT_NO_FATAL_FAILURE(InitState());
13648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13649
13650 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13651
13652 VkDescriptorPoolSize descriptor_pool_type_count = {};
13653 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13654 descriptor_pool_type_count.descriptorCount = 1;
13655
13656 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13657 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13658 descriptor_pool_create_info.maxSets = 1;
13659 descriptor_pool_create_info.poolSizeCount = 1;
13660 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13661 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13662
13663 VkDescriptorPool descriptorset_pool;
13664 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13665
13666 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13667 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13668 descriptorset_layout_binding.descriptorCount = 1;
13669 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13670 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13671
13672 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13673 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13674 descriptorset_layout_create_info.bindingCount = 1;
13675 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13676
13677 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013678 ASSERT_VK_SUCCESS(
13679 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013680
13681 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13682 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13683 descriptorset_allocate_info.descriptorSetCount = 1;
13684 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13685 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13686 VkDescriptorSet descriptorset;
13687 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13688
13689 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13690
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013691 char const *vsSource =
13692 "#version 450\n"
13693 "\n"
13694 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13695 " mat4 mvp;\n"
13696 "} ubuf;\n"
13697 "out gl_PerVertex {\n"
13698 " vec4 gl_Position;\n"
13699 "};\n"
13700 "void main(){\n"
13701 " gl_Position = ubuf.mvp * vec4(1);\n"
13702 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013703
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013704 char const *fsSource =
13705 "#version 450\n"
13706 "\n"
13707 "layout(location = 0) out vec4 uFragColor;\n"
13708 "void main(){\n"
13709 " uFragColor = vec4(0,1,0,1);\n"
13710 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013711
13712 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13713 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13714
13715 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13716 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13717 pipeline_layout_create_info.setLayoutCount = 1;
13718 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13719
13720 VkPipelineLayout pipeline_layout;
13721 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13722
13723 VkPipelineObj pipe(m_device);
13724 pipe.AddColorAttachment();
13725 pipe.AddShader(&vs);
13726 pipe.AddShader(&fs);
13727
13728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13729 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13730 m_errorMonitor->VerifyFound();
13731
13732 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13733 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13734 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13735}
13736
13737TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013738 TEST_DESCRIPTION(
13739 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13740 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013741
13742 ASSERT_NO_FATAL_FAILURE(InitState());
13743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13744
13745 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013746 "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 -060013747
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013748 char const *vsSource =
13749 "#version 450\n"
13750 "\n"
13751 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13752 "out gl_PerVertex {\n"
13753 " vec4 gl_Position;\n"
13754 "};\n"
13755 "void main(){\n"
13756 " gl_Position = vec4(consts.x);\n"
13757 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013758
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013759 char const *fsSource =
13760 "#version 450\n"
13761 "\n"
13762 "layout(location = 0) out vec4 uFragColor;\n"
13763 "void main(){\n"
13764 " uFragColor = vec4(0,1,0,1);\n"
13765 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013766
13767 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13769
13770 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13771 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13772
13773 // Set up a push constant range
13774 VkPushConstantRange push_constant_ranges = {};
13775 // Set to the wrong stage to challenge core_validation
13776 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13777 push_constant_ranges.size = 4;
13778
13779 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13780 pipeline_layout_create_info.pushConstantRangeCount = 1;
13781
13782 VkPipelineLayout pipeline_layout;
13783 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13784
13785 VkPipelineObj pipe(m_device);
13786 pipe.AddColorAttachment();
13787 pipe.AddShader(&vs);
13788 pipe.AddShader(&fs);
13789
13790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13791 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13792 m_errorMonitor->VerifyFound();
13793
13794 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13795}
13796
13797TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13798 TEST_DESCRIPTION(
13799 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13800
13801 ASSERT_NO_FATAL_FAILURE(InitState());
13802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13803
13804 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013805 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013806
13807 // Some awkward steps are required to test with custom device features.
13808 std::vector<const char *> device_extension_names;
13809 auto features = m_device->phy().features();
13810 // Disable support for 64 bit floats
13811 features.shaderFloat64 = false;
13812 // The sacrificial device object
13813 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13814
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013815 char const *vsSource =
13816 "#version 450\n"
13817 "\n"
13818 "out gl_PerVertex {\n"
13819 " vec4 gl_Position;\n"
13820 "};\n"
13821 "void main(){\n"
13822 " gl_Position = vec4(1);\n"
13823 "}\n";
13824 char const *fsSource =
13825 "#version 450\n"
13826 "\n"
13827 "layout(location=0) out vec4 color;\n"
13828 "void main(){\n"
13829 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13830 " color = vec4(green);\n"
13831 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013832
13833 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13834 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13835
13836 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013837
13838 VkPipelineObj pipe(&test_device);
13839 pipe.AddColorAttachment();
13840 pipe.AddShader(&vs);
13841 pipe.AddShader(&fs);
13842
13843 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13844 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13845 VkPipelineLayout pipeline_layout;
13846 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13847
13848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13849 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13850 m_errorMonitor->VerifyFound();
13851
13852 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13853}
13854
13855TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13856 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13857
13858 ASSERT_NO_FATAL_FAILURE(InitState());
13859 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13860
13861 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13862
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013863 char const *vsSource =
13864 "#version 450\n"
13865 "\n"
13866 "out gl_PerVertex {\n"
13867 " vec4 gl_Position;\n"
13868 "};\n"
13869 "layout(xfb_buffer = 1) out;"
13870 "void main(){\n"
13871 " gl_Position = vec4(1);\n"
13872 "}\n";
13873 char const *fsSource =
13874 "#version 450\n"
13875 "\n"
13876 "layout(location=0) out vec4 color;\n"
13877 "void main(){\n"
13878 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13879 " color = vec4(green);\n"
13880 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013881
13882 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13883 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13884
13885 VkPipelineObj pipe(m_device);
13886 pipe.AddColorAttachment();
13887 pipe.AddShader(&vs);
13888 pipe.AddShader(&fs);
13889
13890 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13891 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13892 VkPipelineLayout pipeline_layout;
13893 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13894
13895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13896 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13897 m_errorMonitor->VerifyFound();
13898
13899 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13900}
13901
Karl Schultz6addd812016-02-02 17:17:23 -070013902TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013903 TEST_DESCRIPTION(
13904 "Test that an error is produced for a fragment shader input "
13905 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013908
Chris Forbes59cb88d2015-05-25 11:13:13 +120013909 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013911
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013912 char const *vsSource =
13913 "#version 450\n"
13914 "\n"
13915 "out gl_PerVertex {\n"
13916 " vec4 gl_Position;\n"
13917 "};\n"
13918 "void main(){\n"
13919 " gl_Position = vec4(1);\n"
13920 "}\n";
13921 char const *fsSource =
13922 "#version 450\n"
13923 "\n"
13924 "layout(location=0) in float x;\n"
13925 "layout(location=0) out vec4 color;\n"
13926 "void main(){\n"
13927 " color = vec4(x);\n"
13928 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013929
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013930 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13931 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013932
13933 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013934 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013935 pipe.AddShader(&vs);
13936 pipe.AddShader(&fs);
13937
Chris Forbes59cb88d2015-05-25 11:13:13 +120013938 VkDescriptorSetObj descriptorSet(m_device);
13939 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013940 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013941
Tony Barbour5781e8f2015-08-04 16:23:11 -060013942 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013944 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013945}
13946
Karl Schultz6addd812016-02-02 17:17:23 -070013947TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013948 TEST_DESCRIPTION(
13949 "Test that an error is produced for a fragment shader input "
13950 "within an interace block, which is not present in the outputs "
13951 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013953
13954 ASSERT_NO_FATAL_FAILURE(InitState());
13955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13956
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013957 char const *vsSource =
13958 "#version 450\n"
13959 "\n"
13960 "out gl_PerVertex {\n"
13961 " vec4 gl_Position;\n"
13962 "};\n"
13963 "void main(){\n"
13964 " gl_Position = vec4(1);\n"
13965 "}\n";
13966 char const *fsSource =
13967 "#version 450\n"
13968 "\n"
13969 "in block { layout(location=0) float x; } ins;\n"
13970 "layout(location=0) out vec4 color;\n"
13971 "void main(){\n"
13972 " color = vec4(ins.x);\n"
13973 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013974
13975 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13976 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13977
13978 VkPipelineObj pipe(m_device);
13979 pipe.AddColorAttachment();
13980 pipe.AddShader(&vs);
13981 pipe.AddShader(&fs);
13982
13983 VkDescriptorSetObj descriptorSet(m_device);
13984 descriptorSet.AppendDummy();
13985 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13986
13987 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13988
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013989 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013990}
13991
Karl Schultz6addd812016-02-02 17:17:23 -070013992TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013993 TEST_DESCRIPTION(
13994 "Test that an error is produced for mismatched array sizes "
13995 "across the vertex->fragment shader interface");
13996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13997 "Type mismatch on location 0.0: 'ptr to "
13998 "output arr[2] of float32' vs 'ptr to "
13999 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014000
14001 ASSERT_NO_FATAL_FAILURE(InitState());
14002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14003
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014004 char const *vsSource =
14005 "#version 450\n"
14006 "\n"
14007 "layout(location=0) out float x[2];\n"
14008 "out gl_PerVertex {\n"
14009 " vec4 gl_Position;\n"
14010 "};\n"
14011 "void main(){\n"
14012 " x[0] = 0; x[1] = 0;\n"
14013 " gl_Position = vec4(1);\n"
14014 "}\n";
14015 char const *fsSource =
14016 "#version 450\n"
14017 "\n"
14018 "layout(location=0) in float x[1];\n"
14019 "layout(location=0) out vec4 color;\n"
14020 "void main(){\n"
14021 " color = vec4(x[0]);\n"
14022 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014023
14024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14026
14027 VkPipelineObj pipe(m_device);
14028 pipe.AddColorAttachment();
14029 pipe.AddShader(&vs);
14030 pipe.AddShader(&fs);
14031
14032 VkDescriptorSetObj descriptorSet(m_device);
14033 descriptorSet.AppendDummy();
14034 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14035
14036 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14037
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014038 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014039}
14040
Karl Schultz6addd812016-02-02 17:17:23 -070014041TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014042 TEST_DESCRIPTION(
14043 "Test that an error is produced for mismatched types across "
14044 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014046
Chris Forbesb56af562015-05-25 11:13:17 +120014047 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014049
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014050 char const *vsSource =
14051 "#version 450\n"
14052 "\n"
14053 "layout(location=0) out int x;\n"
14054 "out gl_PerVertex {\n"
14055 " vec4 gl_Position;\n"
14056 "};\n"
14057 "void main(){\n"
14058 " x = 0;\n"
14059 " gl_Position = vec4(1);\n"
14060 "}\n";
14061 char const *fsSource =
14062 "#version 450\n"
14063 "\n"
14064 "layout(location=0) in float x;\n" /* VS writes int */
14065 "layout(location=0) out vec4 color;\n"
14066 "void main(){\n"
14067 " color = vec4(x);\n"
14068 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014069
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014070 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14071 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014072
14073 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014074 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014075 pipe.AddShader(&vs);
14076 pipe.AddShader(&fs);
14077
Chris Forbesb56af562015-05-25 11:13:17 +120014078 VkDescriptorSetObj descriptorSet(m_device);
14079 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014080 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014081
Tony Barbour5781e8f2015-08-04 16:23:11 -060014082 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014083
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014084 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014085}
14086
Karl Schultz6addd812016-02-02 17:17:23 -070014087TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014088 TEST_DESCRIPTION(
14089 "Test that an error is produced for mismatched types across "
14090 "the vertex->fragment shader interface, when the variable is contained within "
14091 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014093
14094 ASSERT_NO_FATAL_FAILURE(InitState());
14095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14096
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014097 char const *vsSource =
14098 "#version 450\n"
14099 "\n"
14100 "out block { layout(location=0) int x; } outs;\n"
14101 "out gl_PerVertex {\n"
14102 " vec4 gl_Position;\n"
14103 "};\n"
14104 "void main(){\n"
14105 " outs.x = 0;\n"
14106 " gl_Position = vec4(1);\n"
14107 "}\n";
14108 char const *fsSource =
14109 "#version 450\n"
14110 "\n"
14111 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14112 "layout(location=0) out vec4 color;\n"
14113 "void main(){\n"
14114 " color = vec4(ins.x);\n"
14115 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014116
14117 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14118 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14119
14120 VkPipelineObj pipe(m_device);
14121 pipe.AddColorAttachment();
14122 pipe.AddShader(&vs);
14123 pipe.AddShader(&fs);
14124
14125 VkDescriptorSetObj descriptorSet(m_device);
14126 descriptorSet.AppendDummy();
14127 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14128
14129 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14130
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014131 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014132}
14133
14134TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014135 TEST_DESCRIPTION(
14136 "Test that an error is produced for location mismatches across "
14137 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14138 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014139 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 +130014140
14141 ASSERT_NO_FATAL_FAILURE(InitState());
14142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14143
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014144 char const *vsSource =
14145 "#version 450\n"
14146 "\n"
14147 "out block { layout(location=1) float x; } outs;\n"
14148 "out gl_PerVertex {\n"
14149 " vec4 gl_Position;\n"
14150 "};\n"
14151 "void main(){\n"
14152 " outs.x = 0;\n"
14153 " gl_Position = vec4(1);\n"
14154 "}\n";
14155 char const *fsSource =
14156 "#version 450\n"
14157 "\n"
14158 "in block { layout(location=0) float x; } ins;\n"
14159 "layout(location=0) out vec4 color;\n"
14160 "void main(){\n"
14161 " color = vec4(ins.x);\n"
14162 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014163
14164 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14165 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14166
14167 VkPipelineObj pipe(m_device);
14168 pipe.AddColorAttachment();
14169 pipe.AddShader(&vs);
14170 pipe.AddShader(&fs);
14171
14172 VkDescriptorSetObj descriptorSet(m_device);
14173 descriptorSet.AppendDummy();
14174 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14175
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014176 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014177 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14178
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014179 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014180}
14181
14182TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014183 TEST_DESCRIPTION(
14184 "Test that an error is produced for component mismatches across the "
14185 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14186 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014187 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 +130014188
14189 ASSERT_NO_FATAL_FAILURE(InitState());
14190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14191
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014192 char const *vsSource =
14193 "#version 450\n"
14194 "\n"
14195 "out block { layout(location=0, component=0) float x; } outs;\n"
14196 "out gl_PerVertex {\n"
14197 " vec4 gl_Position;\n"
14198 "};\n"
14199 "void main(){\n"
14200 " outs.x = 0;\n"
14201 " gl_Position = vec4(1);\n"
14202 "}\n";
14203 char const *fsSource =
14204 "#version 450\n"
14205 "\n"
14206 "in block { layout(location=0, component=1) float x; } ins;\n"
14207 "layout(location=0) out vec4 color;\n"
14208 "void main(){\n"
14209 " color = vec4(ins.x);\n"
14210 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014211
14212 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14213 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14214
14215 VkPipelineObj pipe(m_device);
14216 pipe.AddColorAttachment();
14217 pipe.AddShader(&vs);
14218 pipe.AddShader(&fs);
14219
14220 VkDescriptorSetObj descriptorSet(m_device);
14221 descriptorSet.AppendDummy();
14222 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14223
14224 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14225
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014226 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014227}
14228
Chris Forbes1f3b0152016-11-30 12:48:40 +130014229TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14230 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14231
14232 ASSERT_NO_FATAL_FAILURE(InitState());
14233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14234
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014235 char const *vsSource =
14236 "#version 450\n"
14237 "layout(location=0) out mediump float x;\n"
14238 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14239 char const *fsSource =
14240 "#version 450\n"
14241 "layout(location=0) in highp float x;\n"
14242 "layout(location=0) out vec4 color;\n"
14243 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014244
14245 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14246 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14247
14248 VkPipelineObj pipe(m_device);
14249 pipe.AddColorAttachment();
14250 pipe.AddShader(&vs);
14251 pipe.AddShader(&fs);
14252
14253 VkDescriptorSetObj descriptorSet(m_device);
14254 descriptorSet.AppendDummy();
14255 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14256
14257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14258
14259 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14260
14261 m_errorMonitor->VerifyFound();
14262}
14263
Chris Forbes870a39e2016-11-30 12:55:56 +130014264TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14265 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14266
14267 ASSERT_NO_FATAL_FAILURE(InitState());
14268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14269
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014270 char const *vsSource =
14271 "#version 450\n"
14272 "out block { layout(location=0) mediump float x; };\n"
14273 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14274 char const *fsSource =
14275 "#version 450\n"
14276 "in block { layout(location=0) highp float x; };\n"
14277 "layout(location=0) out vec4 color;\n"
14278 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014279
14280 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14281 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14282
14283 VkPipelineObj pipe(m_device);
14284 pipe.AddColorAttachment();
14285 pipe.AddShader(&vs);
14286 pipe.AddShader(&fs);
14287
14288 VkDescriptorSetObj descriptorSet(m_device);
14289 descriptorSet.AppendDummy();
14290 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14291
14292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14293
14294 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14295
14296 m_errorMonitor->VerifyFound();
14297}
14298
Karl Schultz6addd812016-02-02 17:17:23 -070014299TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014300 TEST_DESCRIPTION(
14301 "Test that a warning is produced for a vertex attribute which is "
14302 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014304
Chris Forbesde136e02015-05-25 11:13:28 +120014305 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014307
14308 VkVertexInputBindingDescription input_binding;
14309 memset(&input_binding, 0, sizeof(input_binding));
14310
14311 VkVertexInputAttributeDescription input_attrib;
14312 memset(&input_attrib, 0, sizeof(input_attrib));
14313 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14314
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014315 char const *vsSource =
14316 "#version 450\n"
14317 "\n"
14318 "out gl_PerVertex {\n"
14319 " vec4 gl_Position;\n"
14320 "};\n"
14321 "void main(){\n"
14322 " gl_Position = vec4(1);\n"
14323 "}\n";
14324 char const *fsSource =
14325 "#version 450\n"
14326 "\n"
14327 "layout(location=0) out vec4 color;\n"
14328 "void main(){\n"
14329 " color = vec4(1);\n"
14330 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014331
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014332 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14333 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014334
14335 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014336 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014337 pipe.AddShader(&vs);
14338 pipe.AddShader(&fs);
14339
14340 pipe.AddVertexInputBindings(&input_binding, 1);
14341 pipe.AddVertexInputAttribs(&input_attrib, 1);
14342
Chris Forbesde136e02015-05-25 11:13:28 +120014343 VkDescriptorSetObj descriptorSet(m_device);
14344 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014345 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014346
Tony Barbour5781e8f2015-08-04 16:23:11 -060014347 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014348
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014349 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014350}
14351
Karl Schultz6addd812016-02-02 17:17:23 -070014352TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014353 TEST_DESCRIPTION(
14354 "Test that a warning is produced for a location mismatch on "
14355 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014357
14358 ASSERT_NO_FATAL_FAILURE(InitState());
14359 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14360
14361 VkVertexInputBindingDescription input_binding;
14362 memset(&input_binding, 0, sizeof(input_binding));
14363
14364 VkVertexInputAttributeDescription input_attrib;
14365 memset(&input_attrib, 0, sizeof(input_attrib));
14366 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14367
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014368 char const *vsSource =
14369 "#version 450\n"
14370 "\n"
14371 "layout(location=1) in float x;\n"
14372 "out gl_PerVertex {\n"
14373 " vec4 gl_Position;\n"
14374 "};\n"
14375 "void main(){\n"
14376 " gl_Position = vec4(x);\n"
14377 "}\n";
14378 char const *fsSource =
14379 "#version 450\n"
14380 "\n"
14381 "layout(location=0) out vec4 color;\n"
14382 "void main(){\n"
14383 " color = vec4(1);\n"
14384 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014385
14386 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14387 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14388
14389 VkPipelineObj pipe(m_device);
14390 pipe.AddColorAttachment();
14391 pipe.AddShader(&vs);
14392 pipe.AddShader(&fs);
14393
14394 pipe.AddVertexInputBindings(&input_binding, 1);
14395 pipe.AddVertexInputAttribs(&input_attrib, 1);
14396
14397 VkDescriptorSetObj descriptorSet(m_device);
14398 descriptorSet.AppendDummy();
14399 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14400
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014401 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014402 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14403
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014404 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014405}
14406
Karl Schultz6addd812016-02-02 17:17:23 -070014407TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014408 TEST_DESCRIPTION(
14409 "Test that an error is produced for a vertex shader input which is not "
14410 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14412 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014413
Chris Forbes62e8e502015-05-25 11:13:29 +120014414 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014416
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014417 char const *vsSource =
14418 "#version 450\n"
14419 "\n"
14420 "layout(location=0) in vec4 x;\n" /* not provided */
14421 "out gl_PerVertex {\n"
14422 " vec4 gl_Position;\n"
14423 "};\n"
14424 "void main(){\n"
14425 " gl_Position = x;\n"
14426 "}\n";
14427 char const *fsSource =
14428 "#version 450\n"
14429 "\n"
14430 "layout(location=0) out vec4 color;\n"
14431 "void main(){\n"
14432 " color = vec4(1);\n"
14433 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014434
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014435 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14436 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014437
14438 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014439 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014440 pipe.AddShader(&vs);
14441 pipe.AddShader(&fs);
14442
Chris Forbes62e8e502015-05-25 11:13:29 +120014443 VkDescriptorSetObj descriptorSet(m_device);
14444 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014445 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014446
Tony Barbour5781e8f2015-08-04 16:23:11 -060014447 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014448
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014449 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014450}
14451
Karl Schultz6addd812016-02-02 17:17:23 -070014452TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014453 TEST_DESCRIPTION(
14454 "Test that an error is produced for a mismatch between the "
14455 "fundamental type (float/int/uint) of an attribute and the "
14456 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014457 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 -060014458
Chris Forbesc97d98e2015-05-25 11:13:31 +120014459 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014461
14462 VkVertexInputBindingDescription input_binding;
14463 memset(&input_binding, 0, sizeof(input_binding));
14464
14465 VkVertexInputAttributeDescription input_attrib;
14466 memset(&input_attrib, 0, sizeof(input_attrib));
14467 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14468
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014469 char const *vsSource =
14470 "#version 450\n"
14471 "\n"
14472 "layout(location=0) in int x;\n" /* attrib provided float */
14473 "out gl_PerVertex {\n"
14474 " vec4 gl_Position;\n"
14475 "};\n"
14476 "void main(){\n"
14477 " gl_Position = vec4(x);\n"
14478 "}\n";
14479 char const *fsSource =
14480 "#version 450\n"
14481 "\n"
14482 "layout(location=0) out vec4 color;\n"
14483 "void main(){\n"
14484 " color = vec4(1);\n"
14485 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014486
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014487 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14488 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014489
14490 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014491 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014492 pipe.AddShader(&vs);
14493 pipe.AddShader(&fs);
14494
14495 pipe.AddVertexInputBindings(&input_binding, 1);
14496 pipe.AddVertexInputAttribs(&input_attrib, 1);
14497
Chris Forbesc97d98e2015-05-25 11:13:31 +120014498 VkDescriptorSetObj descriptorSet(m_device);
14499 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014500 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014501
Tony Barbour5781e8f2015-08-04 16:23:11 -060014502 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014503
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014504 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014505}
14506
Chris Forbesc68b43c2016-04-06 11:18:47 +120014507TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014508 TEST_DESCRIPTION(
14509 "Test that an error is produced for a pipeline containing multiple "
14510 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14512 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014513
14514 ASSERT_NO_FATAL_FAILURE(InitState());
14515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14516
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014517 char const *vsSource =
14518 "#version 450\n"
14519 "\n"
14520 "out gl_PerVertex {\n"
14521 " vec4 gl_Position;\n"
14522 "};\n"
14523 "void main(){\n"
14524 " gl_Position = vec4(1);\n"
14525 "}\n";
14526 char const *fsSource =
14527 "#version 450\n"
14528 "\n"
14529 "layout(location=0) out vec4 color;\n"
14530 "void main(){\n"
14531 " color = vec4(1);\n"
14532 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014533
14534 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14535 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14536
14537 VkPipelineObj pipe(m_device);
14538 pipe.AddColorAttachment();
14539 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014540 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014541 pipe.AddShader(&fs);
14542
14543 VkDescriptorSetObj descriptorSet(m_device);
14544 descriptorSet.AppendDummy();
14545 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14546
14547 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14548
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014549 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014550}
14551
Chris Forbes82ff92a2016-09-09 10:50:24 +120014552TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014554
14555 ASSERT_NO_FATAL_FAILURE(InitState());
14556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14557
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014558 char const *vsSource =
14559 "#version 450\n"
14560 "out gl_PerVertex {\n"
14561 " vec4 gl_Position;\n"
14562 "};\n"
14563 "void main(){\n"
14564 " gl_Position = vec4(0);\n"
14565 "}\n";
14566 char const *fsSource =
14567 "#version 450\n"
14568 "\n"
14569 "layout(location=0) out vec4 color;\n"
14570 "void main(){\n"
14571 " color = vec4(1);\n"
14572 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014573
14574 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14575 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14576
14577 VkPipelineObj pipe(m_device);
14578 pipe.AddColorAttachment();
14579 pipe.AddShader(&vs);
14580 pipe.AddShader(&fs);
14581
14582 VkDescriptorSetObj descriptorSet(m_device);
14583 descriptorSet.AppendDummy();
14584 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14585
14586 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14587
14588 m_errorMonitor->VerifyFound();
14589}
14590
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014591TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14593 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14594 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014595
14596 ASSERT_NO_FATAL_FAILURE(InitState());
14597 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14598
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014599 char const *vsSource =
14600 "#version 450\n"
14601 "void main(){ gl_Position = vec4(0); }\n";
14602 char const *fsSource =
14603 "#version 450\n"
14604 "\n"
14605 "layout(location=0) out vec4 color;\n"
14606 "void main(){\n"
14607 " color = vec4(1);\n"
14608 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014609
14610 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14611 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14612
14613 VkPipelineObj pipe(m_device);
14614 pipe.AddColorAttachment();
14615 pipe.AddShader(&vs);
14616 pipe.AddShader(&fs);
14617
14618 VkDescriptorSetObj descriptorSet(m_device);
14619 descriptorSet.AppendDummy();
14620 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14621
14622 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014623 {
14624 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14625 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14626 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014627 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014628 {
14629 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14630 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14631 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014632 },
14633 };
14634 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014635 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014636 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014637 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14638 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014639 VkRenderPass rp;
14640 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14641 ASSERT_VK_SUCCESS(err);
14642
14643 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14644
14645 m_errorMonitor->VerifyFound();
14646
14647 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14648}
14649
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014650TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014651 TEST_DESCRIPTION(
14652 "Test that an error is produced for a variable output from "
14653 "the TCS without the patch decoration, but consumed in the TES "
14654 "with the decoration.");
14655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14656 "is per-vertex in tessellation control shader stage "
14657 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014658
14659 ASSERT_NO_FATAL_FAILURE(InitState());
14660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14661
Chris Forbesc1e852d2016-04-04 19:26:42 +120014662 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014663 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014664 return;
14665 }
14666
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014667 char const *vsSource =
14668 "#version 450\n"
14669 "void main(){}\n";
14670 char const *tcsSource =
14671 "#version 450\n"
14672 "layout(location=0) out int x[];\n"
14673 "layout(vertices=3) out;\n"
14674 "void main(){\n"
14675 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14676 " gl_TessLevelInner[0] = 1;\n"
14677 " x[gl_InvocationID] = gl_InvocationID;\n"
14678 "}\n";
14679 char const *tesSource =
14680 "#version 450\n"
14681 "layout(triangles, equal_spacing, cw) in;\n"
14682 "layout(location=0) patch in int x;\n"
14683 "out gl_PerVertex { vec4 gl_Position; };\n"
14684 "void main(){\n"
14685 " gl_Position.xyz = gl_TessCoord;\n"
14686 " gl_Position.w = x;\n"
14687 "}\n";
14688 char const *fsSource =
14689 "#version 450\n"
14690 "layout(location=0) out vec4 color;\n"
14691 "void main(){\n"
14692 " color = vec4(1);\n"
14693 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014694
14695 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14696 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14697 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14698 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014700 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14701 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014703 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014704
14705 VkPipelineObj pipe(m_device);
14706 pipe.SetInputAssembly(&iasci);
14707 pipe.SetTessellation(&tsci);
14708 pipe.AddColorAttachment();
14709 pipe.AddShader(&vs);
14710 pipe.AddShader(&tcs);
14711 pipe.AddShader(&tes);
14712 pipe.AddShader(&fs);
14713
14714 VkDescriptorSetObj descriptorSet(m_device);
14715 descriptorSet.AppendDummy();
14716 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14717
14718 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14719
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014720 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014721}
14722
Karl Schultz6addd812016-02-02 17:17:23 -070014723TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014724 TEST_DESCRIPTION(
14725 "Test that an error is produced for a vertex attribute setup where multiple "
14726 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14728 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014729
Chris Forbes280ba2c2015-06-12 11:16:41 +120014730 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014732
14733 /* Two binding descriptions for binding 0 */
14734 VkVertexInputBindingDescription input_bindings[2];
14735 memset(input_bindings, 0, sizeof(input_bindings));
14736
14737 VkVertexInputAttributeDescription input_attrib;
14738 memset(&input_attrib, 0, sizeof(input_attrib));
14739 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14740
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014741 char const *vsSource =
14742 "#version 450\n"
14743 "\n"
14744 "layout(location=0) in float x;\n" /* attrib provided float */
14745 "out gl_PerVertex {\n"
14746 " vec4 gl_Position;\n"
14747 "};\n"
14748 "void main(){\n"
14749 " gl_Position = vec4(x);\n"
14750 "}\n";
14751 char const *fsSource =
14752 "#version 450\n"
14753 "\n"
14754 "layout(location=0) out vec4 color;\n"
14755 "void main(){\n"
14756 " color = vec4(1);\n"
14757 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014758
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014761
14762 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014763 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014764 pipe.AddShader(&vs);
14765 pipe.AddShader(&fs);
14766
14767 pipe.AddVertexInputBindings(input_bindings, 2);
14768 pipe.AddVertexInputAttribs(&input_attrib, 1);
14769
Chris Forbes280ba2c2015-06-12 11:16:41 +120014770 VkDescriptorSetObj descriptorSet(m_device);
14771 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014772 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014773
Tony Barbour5781e8f2015-08-04 16:23:11 -060014774 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014775
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014776 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014777}
Chris Forbes8f68b562015-05-25 11:13:32 +120014778
Karl Schultz6addd812016-02-02 17:17:23 -070014779TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014780 TEST_DESCRIPTION(
14781 "Test that an error is produced for a fragment shader which does not "
14782 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014784
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014785 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014786
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014787 char const *vsSource =
14788 "#version 450\n"
14789 "\n"
14790 "out gl_PerVertex {\n"
14791 " vec4 gl_Position;\n"
14792 "};\n"
14793 "void main(){\n"
14794 " gl_Position = vec4(1);\n"
14795 "}\n";
14796 char const *fsSource =
14797 "#version 450\n"
14798 "\n"
14799 "void main(){\n"
14800 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014801
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014802 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14803 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014804
14805 VkPipelineObj pipe(m_device);
14806 pipe.AddShader(&vs);
14807 pipe.AddShader(&fs);
14808
Chia-I Wu08accc62015-07-07 11:50:03 +080014809 /* set up CB 0, not written */
14810 pipe.AddColorAttachment();
14811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014812
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014813 VkDescriptorSetObj descriptorSet(m_device);
14814 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014815 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014816
Tony Barbour5781e8f2015-08-04 16:23:11 -060014817 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014818
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014819 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014820}
14821
Karl Schultz6addd812016-02-02 17:17:23 -070014822TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014823 TEST_DESCRIPTION(
14824 "Test that a warning is produced for a fragment shader which provides a spurious "
14825 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014827 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014828
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014829 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014830
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014831 char const *vsSource =
14832 "#version 450\n"
14833 "\n"
14834 "out gl_PerVertex {\n"
14835 " vec4 gl_Position;\n"
14836 "};\n"
14837 "void main(){\n"
14838 " gl_Position = vec4(1);\n"
14839 "}\n";
14840 char const *fsSource =
14841 "#version 450\n"
14842 "\n"
14843 "layout(location=0) out vec4 x;\n"
14844 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14845 "void main(){\n"
14846 " x = vec4(1);\n"
14847 " y = vec4(1);\n"
14848 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014849
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014850 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14851 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014852
14853 VkPipelineObj pipe(m_device);
14854 pipe.AddShader(&vs);
14855 pipe.AddShader(&fs);
14856
Chia-I Wu08accc62015-07-07 11:50:03 +080014857 /* set up CB 0, not written */
14858 pipe.AddColorAttachment();
14859 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014860 /* FS writes CB 1, but we don't configure it */
14861
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014862 VkDescriptorSetObj descriptorSet(m_device);
14863 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014864 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014865
Tony Barbour5781e8f2015-08-04 16:23:11 -060014866 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014867
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014868 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014869}
14870
Karl Schultz6addd812016-02-02 17:17:23 -070014871TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014872 TEST_DESCRIPTION(
14873 "Test that an error is produced for a mismatch between the fundamental "
14874 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014876
Chris Forbesa36d69e2015-05-25 11:13:44 +120014877 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014878
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014879 char const *vsSource =
14880 "#version 450\n"
14881 "\n"
14882 "out gl_PerVertex {\n"
14883 " vec4 gl_Position;\n"
14884 "};\n"
14885 "void main(){\n"
14886 " gl_Position = vec4(1);\n"
14887 "}\n";
14888 char const *fsSource =
14889 "#version 450\n"
14890 "\n"
14891 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14892 "void main(){\n"
14893 " x = ivec4(1);\n"
14894 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014895
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014898
14899 VkPipelineObj pipe(m_device);
14900 pipe.AddShader(&vs);
14901 pipe.AddShader(&fs);
14902
Chia-I Wu08accc62015-07-07 11:50:03 +080014903 /* set up CB 0; type is UNORM by default */
14904 pipe.AddColorAttachment();
14905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014906
Chris Forbesa36d69e2015-05-25 11:13:44 +120014907 VkDescriptorSetObj descriptorSet(m_device);
14908 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014909 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014910
Tony Barbour5781e8f2015-08-04 16:23:11 -060014911 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014912
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014913 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014914}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014915
Karl Schultz6addd812016-02-02 17:17:23 -070014916TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014917 TEST_DESCRIPTION(
14918 "Test that an error is produced for a shader consuming a uniform "
14919 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014921
Chris Forbes556c76c2015-08-14 12:04:59 +120014922 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014923
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014924 char const *vsSource =
14925 "#version 450\n"
14926 "\n"
14927 "out gl_PerVertex {\n"
14928 " vec4 gl_Position;\n"
14929 "};\n"
14930 "void main(){\n"
14931 " gl_Position = vec4(1);\n"
14932 "}\n";
14933 char const *fsSource =
14934 "#version 450\n"
14935 "\n"
14936 "layout(location=0) out vec4 x;\n"
14937 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14938 "void main(){\n"
14939 " x = vec4(bar.y);\n"
14940 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014941
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014944
Chris Forbes556c76c2015-08-14 12:04:59 +120014945 VkPipelineObj pipe(m_device);
14946 pipe.AddShader(&vs);
14947 pipe.AddShader(&fs);
14948
14949 /* set up CB 0; type is UNORM by default */
14950 pipe.AddColorAttachment();
14951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14952
14953 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014954 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014955
14956 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14957
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014958 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014959}
14960
Chris Forbes5c59e902016-02-26 16:56:09 +130014961TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014962 TEST_DESCRIPTION(
14963 "Test that an error is produced for a shader consuming push constants "
14964 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014966
14967 ASSERT_NO_FATAL_FAILURE(InitState());
14968
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014969 char const *vsSource =
14970 "#version 450\n"
14971 "\n"
14972 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14973 "out gl_PerVertex {\n"
14974 " vec4 gl_Position;\n"
14975 "};\n"
14976 "void main(){\n"
14977 " gl_Position = vec4(consts.x);\n"
14978 "}\n";
14979 char const *fsSource =
14980 "#version 450\n"
14981 "\n"
14982 "layout(location=0) out vec4 x;\n"
14983 "void main(){\n"
14984 " x = vec4(1);\n"
14985 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014986
14987 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14988 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14989
14990 VkPipelineObj pipe(m_device);
14991 pipe.AddShader(&vs);
14992 pipe.AddShader(&fs);
14993
14994 /* set up CB 0; type is UNORM by default */
14995 pipe.AddColorAttachment();
14996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14997
14998 VkDescriptorSetObj descriptorSet(m_device);
14999 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15000
15001 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15002
15003 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015004 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015005}
15006
Chris Forbes3fb17902016-08-22 14:57:55 +120015007TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015008 TEST_DESCRIPTION(
15009 "Test that an error is produced for a shader consuming an input attachment "
15010 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15012 "consumes input attachment index 0 but not provided in subpass");
15013
15014 ASSERT_NO_FATAL_FAILURE(InitState());
15015
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015016 char const *vsSource =
15017 "#version 450\n"
15018 "\n"
15019 "out gl_PerVertex {\n"
15020 " vec4 gl_Position;\n"
15021 "};\n"
15022 "void main(){\n"
15023 " gl_Position = vec4(1);\n"
15024 "}\n";
15025 char const *fsSource =
15026 "#version 450\n"
15027 "\n"
15028 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15029 "layout(location=0) out vec4 color;\n"
15030 "void main() {\n"
15031 " color = subpassLoad(x);\n"
15032 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015033
15034 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15035 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15036
15037 VkPipelineObj pipe(m_device);
15038 pipe.AddShader(&vs);
15039 pipe.AddShader(&fs);
15040 pipe.AddColorAttachment();
15041 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015043 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15044 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015045 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015046 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015047 ASSERT_VK_SUCCESS(err);
15048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015050 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015051 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015052 ASSERT_VK_SUCCESS(err);
15053
15054 // error here.
15055 pipe.CreateVKPipeline(pl, renderPass());
15056
15057 m_errorMonitor->VerifyFound();
15058
15059 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15060 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15061}
15062
Chris Forbes5a9a0472016-08-22 16:02:09 +120015063TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015064 TEST_DESCRIPTION(
15065 "Test that an error is produced for a shader consuming an input attachment "
15066 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15068 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15069
15070 ASSERT_NO_FATAL_FAILURE(InitState());
15071
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015072 char const *vsSource =
15073 "#version 450\n"
15074 "\n"
15075 "out gl_PerVertex {\n"
15076 " vec4 gl_Position;\n"
15077 "};\n"
15078 "void main(){\n"
15079 " gl_Position = vec4(1);\n"
15080 "}\n";
15081 char const *fsSource =
15082 "#version 450\n"
15083 "\n"
15084 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15085 "layout(location=0) out vec4 color;\n"
15086 "void main() {\n"
15087 " color = subpassLoad(x);\n"
15088 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015089
15090 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15091 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15092
15093 VkPipelineObj pipe(m_device);
15094 pipe.AddShader(&vs);
15095 pipe.AddShader(&fs);
15096 pipe.AddColorAttachment();
15097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15100 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015101 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015102 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015103 ASSERT_VK_SUCCESS(err);
15104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015105 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015106 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015107 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015108 ASSERT_VK_SUCCESS(err);
15109
15110 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015111 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15112 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15113 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15114 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15115 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 +120015116 };
15117 VkAttachmentReference color = {
15118 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15119 };
15120 VkAttachmentReference input = {
15121 1, VK_IMAGE_LAYOUT_GENERAL,
15122 };
15123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015124 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015126 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015127 VkRenderPass rp;
15128 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15129 ASSERT_VK_SUCCESS(err);
15130
15131 // error here.
15132 pipe.CreateVKPipeline(pl, rp);
15133
15134 m_errorMonitor->VerifyFound();
15135
15136 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15137 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15138 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15139}
15140
Chris Forbes541f7b02016-08-22 15:30:27 +120015141TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015142 TEST_DESCRIPTION(
15143 "Test that an error is produced for a shader consuming an input attachment "
15144 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015146 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015147
15148 ASSERT_NO_FATAL_FAILURE(InitState());
15149
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015150 char const *vsSource =
15151 "#version 450\n"
15152 "\n"
15153 "out gl_PerVertex {\n"
15154 " vec4 gl_Position;\n"
15155 "};\n"
15156 "void main(){\n"
15157 " gl_Position = vec4(1);\n"
15158 "}\n";
15159 char const *fsSource =
15160 "#version 450\n"
15161 "\n"
15162 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15163 "layout(location=0) out vec4 color;\n"
15164 "void main() {\n"
15165 " color = subpassLoad(xs[0]);\n"
15166 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015167
15168 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15169 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15170
15171 VkPipelineObj pipe(m_device);
15172 pipe.AddShader(&vs);
15173 pipe.AddShader(&fs);
15174 pipe.AddColorAttachment();
15175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015177 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15178 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015179 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015180 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015181 ASSERT_VK_SUCCESS(err);
15182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015183 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015184 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015186 ASSERT_VK_SUCCESS(err);
15187
15188 // error here.
15189 pipe.CreateVKPipeline(pl, renderPass());
15190
15191 m_errorMonitor->VerifyFound();
15192
15193 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15194 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15195}
15196
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015197TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015198 TEST_DESCRIPTION(
15199 "Test that an error is produced for a compute pipeline consuming a "
15200 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015202
15203 ASSERT_NO_FATAL_FAILURE(InitState());
15204
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015205 char const *csSource =
15206 "#version 450\n"
15207 "\n"
15208 "layout(local_size_x=1) in;\n"
15209 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15210 "void main(){\n"
15211 " x = vec4(1);\n"
15212 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015213
15214 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15215
15216 VkDescriptorSetObj descriptorSet(m_device);
15217 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015219 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15220 nullptr,
15221 0,
15222 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15223 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15224 descriptorSet.GetPipelineLayout(),
15225 VK_NULL_HANDLE,
15226 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015227
15228 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015229 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015230
15231 m_errorMonitor->VerifyFound();
15232
15233 if (err == VK_SUCCESS) {
15234 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15235 }
15236}
15237
Chris Forbes22a9b092016-07-19 14:34:05 +120015238TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015239 TEST_DESCRIPTION(
15240 "Test that an error is produced for a pipeline consuming a "
15241 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15243 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015244
15245 ASSERT_NO_FATAL_FAILURE(InitState());
15246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015247 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15248 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015249 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015250 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015251 ASSERT_VK_SUCCESS(err);
15252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015253 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015254 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015255 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015256 ASSERT_VK_SUCCESS(err);
15257
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015258 char const *csSource =
15259 "#version 450\n"
15260 "\n"
15261 "layout(local_size_x=1) in;\n"
15262 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15263 "void main() {\n"
15264 " x.x = 1.0f;\n"
15265 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015266 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015268 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15269 nullptr,
15270 0,
15271 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15272 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15273 pl,
15274 VK_NULL_HANDLE,
15275 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015276
15277 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015278 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015279
15280 m_errorMonitor->VerifyFound();
15281
15282 if (err == VK_SUCCESS) {
15283 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15284 }
15285
15286 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15287 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15288}
15289
Chris Forbes50020592016-07-27 13:52:41 +120015290TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015291 TEST_DESCRIPTION(
15292 "Test that an error is produced when an image view type "
15293 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015295 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 +120015296
15297 ASSERT_NO_FATAL_FAILURE(InitState());
15298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15299
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015300 char const *vsSource =
15301 "#version 450\n"
15302 "\n"
15303 "out gl_PerVertex { vec4 gl_Position; };\n"
15304 "void main() { gl_Position = vec4(0); }\n";
15305 char const *fsSource =
15306 "#version 450\n"
15307 "\n"
15308 "layout(set=0, binding=0) uniform sampler3D s;\n"
15309 "layout(location=0) out vec4 color;\n"
15310 "void main() {\n"
15311 " color = texture(s, vec3(0));\n"
15312 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015313 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15314 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15315
15316 VkPipelineObj pipe(m_device);
15317 pipe.AddShader(&vs);
15318 pipe.AddShader(&fs);
15319 pipe.AddColorAttachment();
15320
15321 VkTextureObj texture(m_device, nullptr);
15322 VkSamplerObj sampler(m_device);
15323
15324 VkDescriptorSetObj descriptorSet(m_device);
15325 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15326 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15327
15328 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15329 ASSERT_VK_SUCCESS(err);
15330
Tony Barbour552f6c02016-12-21 14:34:07 -070015331 m_commandBuffer->BeginCommandBuffer();
15332 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015333
15334 m_commandBuffer->BindPipeline(pipe);
15335 m_commandBuffer->BindDescriptorSet(descriptorSet);
15336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015337 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015338 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015339 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015340 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15341
15342 // error produced here.
15343 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15344
15345 m_errorMonitor->VerifyFound();
15346
Tony Barbour552f6c02016-12-21 14:34:07 -070015347 m_commandBuffer->EndRenderPass();
15348 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015349}
15350
Chris Forbes5533bfc2016-07-27 14:12:34 +120015351TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015352 TEST_DESCRIPTION(
15353 "Test that an error is produced when a multisampled images "
15354 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015357
15358 ASSERT_NO_FATAL_FAILURE(InitState());
15359 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15360
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015361 char const *vsSource =
15362 "#version 450\n"
15363 "\n"
15364 "out gl_PerVertex { vec4 gl_Position; };\n"
15365 "void main() { gl_Position = vec4(0); }\n";
15366 char const *fsSource =
15367 "#version 450\n"
15368 "\n"
15369 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15370 "layout(location=0) out vec4 color;\n"
15371 "void main() {\n"
15372 " color = texelFetch(s, ivec2(0), 0);\n"
15373 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015374 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15375 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15376
15377 VkPipelineObj pipe(m_device);
15378 pipe.AddShader(&vs);
15379 pipe.AddShader(&fs);
15380 pipe.AddColorAttachment();
15381
15382 VkTextureObj texture(m_device, nullptr);
15383 VkSamplerObj sampler(m_device);
15384
15385 VkDescriptorSetObj descriptorSet(m_device);
15386 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15387 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15388
15389 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15390 ASSERT_VK_SUCCESS(err);
15391
Tony Barbour552f6c02016-12-21 14:34:07 -070015392 m_commandBuffer->BeginCommandBuffer();
15393 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015394
15395 m_commandBuffer->BindPipeline(pipe);
15396 m_commandBuffer->BindDescriptorSet(descriptorSet);
15397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015398 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015399 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015400 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015401 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15402
15403 // error produced here.
15404 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15405
15406 m_errorMonitor->VerifyFound();
15407
Tony Barbour552f6c02016-12-21 14:34:07 -070015408 m_commandBuffer->EndRenderPass();
15409 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015410}
15411
Mark Youngc48c4c12016-04-11 14:26:49 -060015412TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015414
15415 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015416
15417 // Create an image
15418 VkImage image;
15419
Karl Schultz6addd812016-02-02 17:17:23 -070015420 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15421 const int32_t tex_width = 32;
15422 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015423
15424 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015425 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15426 image_create_info.pNext = NULL;
15427 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15428 image_create_info.format = tex_format;
15429 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015430 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015431 image_create_info.extent.depth = 1;
15432 image_create_info.mipLevels = 1;
15433 image_create_info.arrayLayers = 1;
15434 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15435 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15436 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15437 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015438
15439 // Introduce error by sending down a bogus width extent
15440 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015441 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015442
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015443 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015444}
15445
Mark Youngc48c4c12016-04-11 14:26:49 -060015446TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015448
15449 ASSERT_NO_FATAL_FAILURE(InitState());
15450
15451 // Create an image
15452 VkImage image;
15453
15454 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15455 const int32_t tex_width = 32;
15456 const int32_t tex_height = 32;
15457
15458 VkImageCreateInfo image_create_info = {};
15459 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15460 image_create_info.pNext = NULL;
15461 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15462 image_create_info.format = tex_format;
15463 image_create_info.extent.width = tex_width;
15464 image_create_info.extent.height = tex_height;
15465 image_create_info.extent.depth = 1;
15466 image_create_info.mipLevels = 1;
15467 image_create_info.arrayLayers = 1;
15468 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15469 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15470 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15471 image_create_info.flags = 0;
15472
15473 // Introduce error by sending down a bogus width extent
15474 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015475 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015476 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15477
15478 m_errorMonitor->VerifyFound();
15479}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015480
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015481TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015482 TEST_DESCRIPTION(
15483 "Create a render pass with an attachment description "
15484 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015485
15486 ASSERT_NO_FATAL_FAILURE(InitState());
15487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15488
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015490
15491 VkAttachmentReference color_attach = {};
15492 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15493 color_attach.attachment = 0;
15494 VkSubpassDescription subpass = {};
15495 subpass.colorAttachmentCount = 1;
15496 subpass.pColorAttachments = &color_attach;
15497
15498 VkRenderPassCreateInfo rpci = {};
15499 rpci.subpassCount = 1;
15500 rpci.pSubpasses = &subpass;
15501 rpci.attachmentCount = 1;
15502 VkAttachmentDescription attach_desc = {};
15503 attach_desc.format = VK_FORMAT_UNDEFINED;
15504 rpci.pAttachments = &attach_desc;
15505 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15506 VkRenderPass rp;
15507 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15508
15509 m_errorMonitor->VerifyFound();
15510
15511 if (result == VK_SUCCESS) {
15512 vkDestroyRenderPass(m_device->device(), rp, NULL);
15513 }
15514}
15515
Karl Schultz6addd812016-02-02 17:17:23 -070015516TEST_F(VkLayerTest, InvalidImageView) {
15517 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015518
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015520
Tobin Ehliscde08892015-09-22 10:11:37 -060015521 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015522
Mike Stroyana3082432015-09-25 13:39:21 -060015523 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015524 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015525
Karl Schultz6addd812016-02-02 17:17:23 -070015526 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15527 const int32_t tex_width = 32;
15528 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015529
15530 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015531 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15532 image_create_info.pNext = NULL;
15533 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15534 image_create_info.format = tex_format;
15535 image_create_info.extent.width = tex_width;
15536 image_create_info.extent.height = tex_height;
15537 image_create_info.extent.depth = 1;
15538 image_create_info.mipLevels = 1;
15539 image_create_info.arrayLayers = 1;
15540 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15541 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15542 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15543 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015544
Chia-I Wuf7458c52015-10-26 21:10:41 +080015545 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015546 ASSERT_VK_SUCCESS(err);
15547
15548 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015549 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015550 image_view_create_info.image = image;
15551 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15552 image_view_create_info.format = tex_format;
15553 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015554 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015555 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015556 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015557
15558 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015559 m_errorMonitor->SetUnexpectedError(
15560 "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 -060015561 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015562
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015563 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015564 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015565}
Mike Stroyana3082432015-09-25 13:39:21 -060015566
Mark Youngd339ba32016-05-30 13:28:35 -060015567TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15568 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015570 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015571
15572 ASSERT_NO_FATAL_FAILURE(InitState());
15573
15574 // Create an image and try to create a view with no memory backing the image
15575 VkImage image;
15576
15577 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15578 const int32_t tex_width = 32;
15579 const int32_t tex_height = 32;
15580
15581 VkImageCreateInfo image_create_info = {};
15582 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15583 image_create_info.pNext = NULL;
15584 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15585 image_create_info.format = tex_format;
15586 image_create_info.extent.width = tex_width;
15587 image_create_info.extent.height = tex_height;
15588 image_create_info.extent.depth = 1;
15589 image_create_info.mipLevels = 1;
15590 image_create_info.arrayLayers = 1;
15591 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15592 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15593 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15594 image_create_info.flags = 0;
15595
15596 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15597 ASSERT_VK_SUCCESS(err);
15598
15599 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015600 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015601 image_view_create_info.image = image;
15602 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15603 image_view_create_info.format = tex_format;
15604 image_view_create_info.subresourceRange.layerCount = 1;
15605 image_view_create_info.subresourceRange.baseMipLevel = 0;
15606 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015607 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015608
15609 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015610 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015611
15612 m_errorMonitor->VerifyFound();
15613 vkDestroyImage(m_device->device(), image, NULL);
15614 // If last error is success, it still created the view, so delete it.
15615 if (err == VK_SUCCESS) {
15616 vkDestroyImageView(m_device->device(), view, NULL);
15617 }
Mark Youngd339ba32016-05-30 13:28:35 -060015618}
15619
Karl Schultz6addd812016-02-02 17:17:23 -070015620TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015621 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015623
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015624 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015625
Karl Schultz6addd812016-02-02 17:17:23 -070015626 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015627 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015628 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015629 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015630
15631 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015632 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015633 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015634 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15635 image_view_create_info.format = tex_format;
15636 image_view_create_info.subresourceRange.baseMipLevel = 0;
15637 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015638 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015639 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015640 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015641
15642 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015643 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015644
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015645 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015646}
15647
Mike Weiblena1e13f42017-02-09 21:25:59 -070015648TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15649 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15650
15651 ASSERT_NO_FATAL_FAILURE(InitState());
15652 VkSubresourceLayout subres_layout = {};
15653
15654 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15655 {
15656 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15657 VkImageObj img(m_device);
15658 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15659 ASSERT_TRUE(img.initialized());
15660
15661 VkImageSubresource subres = {};
15662 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15663 subres.mipLevel = 0;
15664 subres.arrayLayer = 0;
15665
15666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15667 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15668 m_errorMonitor->VerifyFound();
15669 }
15670
15671 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15672 {
15673 VkImageObj img(m_device);
15674 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15675 ASSERT_TRUE(img.initialized());
15676
15677 VkImageSubresource subres = {};
15678 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15679 subres.mipLevel = 0;
15680 subres.arrayLayer = 0;
15681
15682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15684 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15685 m_errorMonitor->VerifyFound();
15686 }
15687
15688 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15689 {
15690 VkImageObj img(m_device);
15691 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15692 ASSERT_TRUE(img.initialized());
15693
15694 VkImageSubresource subres = {};
15695 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15696 subres.mipLevel = 1; // ERROR: triggers VU 00739
15697 subres.arrayLayer = 0;
15698
15699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15700 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15701 m_errorMonitor->VerifyFound();
15702 }
15703
15704 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15705 {
15706 VkImageObj img(m_device);
15707 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15708 ASSERT_TRUE(img.initialized());
15709
15710 VkImageSubresource subres = {};
15711 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15712 subres.mipLevel = 0;
15713 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15714
15715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15716 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15717 m_errorMonitor->VerifyFound();
15718 }
15719}
15720
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015721TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015722 VkResult err;
15723 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015724
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015726
Mike Stroyana3082432015-09-25 13:39:21 -060015727 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015728
15729 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015730 VkImage srcImage;
15731 VkImage dstImage;
15732 VkDeviceMemory srcMem;
15733 VkDeviceMemory destMem;
15734 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015735
15736 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015737 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15738 image_create_info.pNext = NULL;
15739 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15740 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15741 image_create_info.extent.width = 32;
15742 image_create_info.extent.height = 32;
15743 image_create_info.extent.depth = 1;
15744 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015745 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015746 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15747 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15748 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15749 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015751 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015752 ASSERT_VK_SUCCESS(err);
15753
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015754 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015756 ASSERT_VK_SUCCESS(err);
15757
15758 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015759 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015760 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15761 memAlloc.pNext = NULL;
15762 memAlloc.allocationSize = 0;
15763 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015764
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015765 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015766 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015767 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015768 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015769 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015770 ASSERT_VK_SUCCESS(err);
15771
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015772 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015773 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015774 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015775 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015776 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015777 ASSERT_VK_SUCCESS(err);
15778
15779 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15780 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015781 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015782 ASSERT_VK_SUCCESS(err);
15783
Tony Barbour552f6c02016-12-21 14:34:07 -070015784 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015785 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015786 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015787 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015788 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015789 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015790 copyRegion.srcOffset.x = 0;
15791 copyRegion.srcOffset.y = 0;
15792 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015793 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015794 copyRegion.dstSubresource.mipLevel = 0;
15795 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015796 // Introduce failure by forcing the dst layerCount to differ from src
15797 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015798 copyRegion.dstOffset.x = 0;
15799 copyRegion.dstOffset.y = 0;
15800 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015801 copyRegion.extent.width = 1;
15802 copyRegion.extent.height = 1;
15803 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015804 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015805 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015806
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015807 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015808
Chia-I Wuf7458c52015-10-26 21:10:41 +080015809 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015810 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015811 vkFreeMemory(m_device->device(), srcMem, NULL);
15812 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015813}
15814
Tony Barbourd6673642016-05-05 14:46:39 -060015815TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015816 TEST_DESCRIPTION("Creating images with unsuported formats ");
15817
15818 ASSERT_NO_FATAL_FAILURE(InitState());
15819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15820 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015821 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 -060015822 VK_IMAGE_TILING_OPTIMAL, 0);
15823 ASSERT_TRUE(image.initialized());
15824
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015825 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015826 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015827 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015828 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15829 image_create_info.format = VK_FORMAT_UNDEFINED;
15830 image_create_info.extent.width = 32;
15831 image_create_info.extent.height = 32;
15832 image_create_info.extent.depth = 1;
15833 image_create_info.mipLevels = 1;
15834 image_create_info.arrayLayers = 1;
15835 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15836 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15837 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15840 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015841
15842 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015843 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15844 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15845 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15846 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015847 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15848 m_errorMonitor->VerifyFound();
15849
Tony Barbourd6673642016-05-05 14:46:39 -060015850 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015851 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015852 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15853 VkFormat format = static_cast<VkFormat>(f);
15854 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015855 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015856 unsupported = format;
15857 break;
15858 }
15859 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015860
Tony Barbourd6673642016-05-05 14:46:39 -060015861 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015862 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015864
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015865 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15866 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15867 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15868 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15869 m_errorMonitor->SetUnexpectedError(
15870 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15871 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15872 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015873 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015874 m_errorMonitor->VerifyFound();
15875 }
15876}
15877
15878TEST_F(VkLayerTest, ImageLayerViewTests) {
15879 VkResult ret;
15880 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15881
15882 ASSERT_NO_FATAL_FAILURE(InitState());
15883
15884 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015885 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 -060015886 VK_IMAGE_TILING_OPTIMAL, 0);
15887 ASSERT_TRUE(image.initialized());
15888
15889 VkImageView imgView;
15890 VkImageViewCreateInfo imgViewInfo = {};
15891 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15892 imgViewInfo.image = image.handle();
15893 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15894 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15895 imgViewInfo.subresourceRange.layerCount = 1;
15896 imgViewInfo.subresourceRange.baseMipLevel = 0;
15897 imgViewInfo.subresourceRange.levelCount = 1;
15898 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15899
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015901 // View can't have baseMipLevel >= image's mipLevels - Expect
15902 // VIEW_CREATE_ERROR
15903 imgViewInfo.subresourceRange.baseMipLevel = 1;
15904 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15905 m_errorMonitor->VerifyFound();
15906 imgViewInfo.subresourceRange.baseMipLevel = 0;
15907
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015909 // View can't have baseArrayLayer >= image's arraySize - Expect
15910 // VIEW_CREATE_ERROR
15911 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15912 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15913 m_errorMonitor->VerifyFound();
15914 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15915
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015917 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15918 imgViewInfo.subresourceRange.levelCount = 0;
15919 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15920 m_errorMonitor->VerifyFound();
15921 imgViewInfo.subresourceRange.levelCount = 1;
15922
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015923 m_errorMonitor->SetDesiredFailureMsg(
15924 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15925 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015926 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15927 imgViewInfo.subresourceRange.layerCount = 0;
15928 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15929 m_errorMonitor->VerifyFound();
15930 imgViewInfo.subresourceRange.layerCount = 1;
15931
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15933 "Formats MUST be IDENTICAL unless "
15934 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15935 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015936 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15937 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15938 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15939 m_errorMonitor->VerifyFound();
15940 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15941
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015943 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15944 // VIEW_CREATE_ERROR
15945 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15946 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15947 m_errorMonitor->VerifyFound();
15948 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15949
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015951 // TODO: Update framework to easily passing mutable flag into ImageObj init
15952 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015953 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15954 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15955 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015956 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15957 // VIEW_CREATE_ERROR
15958 VkImageCreateInfo mutImgInfo = image.create_info();
15959 VkImage mutImage;
15960 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015961 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015962 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15963 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15964 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15965 ASSERT_VK_SUCCESS(ret);
15966 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015967 m_errorMonitor->SetUnexpectedError(
15968 "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 -060015969 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15970 m_errorMonitor->VerifyFound();
15971 imgViewInfo.image = image.handle();
15972 vkDestroyImage(m_device->handle(), mutImage, NULL);
15973}
15974
Dave Houlton59a20702017-02-02 17:26:23 -070015975TEST_F(VkLayerTest, ImageBufferCopyTests) {
15976 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
15977
15978 ASSERT_NO_FATAL_FAILURE(InitState());
Dave Houlton584d51e2017-02-16 12:52:54 -070015979
15980 // Bail if any dimension of transfer granularity is 0.
15981 auto index = m_device->graphics_queue_node_index_;
15982 auto queue_family_properties = m_device->phy().queue_properties();
15983 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
15984 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
15985 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
15986 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
15987 return;
15988 }
15989
Dave Houlton59a20702017-02-02 17:26:23 -070015990 VkImageObj image_64k(m_device); // 128^2 texels, 64k
15991 VkImageObj image_16k(m_device); // 64^2 texels, 16k
15992 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070015993 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
15994 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
15995 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
15996 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
15997
Dave Houlton59a20702017-02-02 17:26:23 -070015998 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
15999 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16000 VK_IMAGE_TILING_OPTIMAL, 0);
16001 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16002 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16003 VK_IMAGE_TILING_OPTIMAL, 0);
16004 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16005 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016006 ASSERT_TRUE(image_64k.initialized());
16007 ASSERT_TRUE(image_16k.initialized());
16008 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016009
Dave Houltonf3229d52017-02-21 15:59:08 -070016010 // Verify all needed Depth/Stencil formats are supported
16011 bool missing_ds_support = false;
16012 VkFormatProperties props = {0, 0, 0};
16013 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16014 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16015 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16016 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16017 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16018 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16019 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16020 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16021
16022 if (!missing_ds_support) {
16023 ds_image_4D_1S.init(
16024 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16025 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16026 VK_IMAGE_TILING_OPTIMAL, 0);
16027 ASSERT_TRUE(ds_image_4D_1S.initialized());
16028
16029 ds_image_3D_1S.init(
16030 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16031 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16032 VK_IMAGE_TILING_OPTIMAL, 0);
16033 ASSERT_TRUE(ds_image_3D_1S.initialized());
16034
16035 ds_image_2D.init(
16036 256, 256, VK_FORMAT_D16_UNORM,
16037 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16038 VK_IMAGE_TILING_OPTIMAL, 0);
16039 ASSERT_TRUE(ds_image_2D.initialized());
16040
16041 ds_image_1S.init(
16042 256, 256, VK_FORMAT_S8_UINT,
16043 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16044 VK_IMAGE_TILING_OPTIMAL, 0);
16045 ASSERT_TRUE(ds_image_1S.initialized());
16046 }
16047
16048 // Allocate buffers
16049 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016050 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016051 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16052 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16053 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16054 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016055
16056 VkBufferImageCopy region = {};
16057 region.bufferRowLength = 0;
16058 region.bufferImageHeight = 0;
16059 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16060 region.imageSubresource.layerCount = 1;
16061 region.imageOffset = {0, 0, 0};
16062 region.imageExtent = {64, 64, 1};
16063 region.bufferOffset = 0;
16064
16065 // attempt copies before putting command buffer in recording state
16066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16067 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16068 &region);
16069 m_errorMonitor->VerifyFound();
16070
16071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16072 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16073 &region);
16074 m_errorMonitor->VerifyFound();
16075
16076 // start recording
16077 m_commandBuffer->BeginCommandBuffer();
16078
16079 // successful copies
16080 m_errorMonitor->ExpectSuccess();
16081 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16082 &region);
16083 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16084 &region);
16085 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16086 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16087 &region);
16088 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16089 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16090 &region);
16091 region.imageOffset.x = 0;
16092 region.imageExtent.height = 64;
16093 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16094 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16095 &region);
16096 m_errorMonitor->VerifyNotFound();
16097
16098 // image/buffer too small (extent) on copy to image
16099 region.imageExtent = {65, 64, 1};
16100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16101 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16102 &region);
16103 m_errorMonitor->VerifyFound();
16104
16105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16106 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16107 &region);
16108 m_errorMonitor->VerifyFound();
16109
16110 // image/buffer too small (offset) on copy to image
16111 region.imageExtent = {64, 64, 1};
16112 region.imageOffset = {0, 4, 0};
16113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16114 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16115 &region);
16116 m_errorMonitor->VerifyFound();
16117
16118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16119 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16120 &region);
16121 m_errorMonitor->VerifyFound();
16122
16123 // image/buffer too small on copy to buffer
16124 region.imageExtent = {64, 64, 1};
16125 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016126 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16128 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16129 &region);
16130 m_errorMonitor->VerifyFound();
16131
16132 region.imageExtent = {64, 65, 1};
16133 region.bufferOffset = 0;
16134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16135 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16136 &region);
16137 m_errorMonitor->VerifyFound();
16138
16139 // buffer size ok but rowlength causes loose packing
16140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16141 region.imageExtent = {64, 64, 1};
16142 region.bufferRowLength = 68;
16143 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16144 &region);
16145 m_errorMonitor->VerifyFound();
16146
Dave Houlton59a20702017-02-02 17:26:23 -070016147 // aspect bits
16148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16149 region.imageExtent = {64, 64, 1};
16150 region.bufferRowLength = 0;
16151 region.bufferImageHeight = 0;
16152 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16153 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16154 buffer_16k.handle(), 1, &region);
16155 m_errorMonitor->VerifyFound();
16156
16157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16158 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16159 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16160 &region);
16161 m_errorMonitor->VerifyFound();
16162
16163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16164 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16165 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16166 buffer_16k.handle(), 1, &region);
16167 m_errorMonitor->VerifyFound();
16168
Dave Houltonf3229d52017-02-21 15:59:08 -070016169 // Test Depth/Stencil copies
16170 if (missing_ds_support) {
16171 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16172 } else {
16173 VkBufferImageCopy ds_region = {};
16174 ds_region.bufferOffset = 0;
16175 ds_region.bufferRowLength = 0;
16176 ds_region.bufferImageHeight = 0;
16177 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16178 ds_region.imageSubresource.mipLevel = 0;
16179 ds_region.imageSubresource.baseArrayLayer = 0;
16180 ds_region.imageSubresource.layerCount = 1;
16181 ds_region.imageOffset = {0, 0, 0};
16182 ds_region.imageExtent = {256, 256, 1};
16183
16184 // Depth copies that should succeed
16185 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16186 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16187 buffer_256k.handle(), 1, &ds_region);
16188 m_errorMonitor->VerifyNotFound();
16189
16190 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16191 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16192 buffer_256k.handle(), 1, &ds_region);
16193 m_errorMonitor->VerifyNotFound();
16194
16195 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16196 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16197 buffer_128k.handle(), 1, &ds_region);
16198 m_errorMonitor->VerifyNotFound();
16199
16200 // Depth copies that should fail
16201 ds_region.bufferOffset = 4;
16202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16203 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16204 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16205 buffer_256k.handle(), 1, &ds_region);
16206 m_errorMonitor->VerifyFound();
16207
16208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16209 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16210 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16211 buffer_256k.handle(), 1, &ds_region);
16212 m_errorMonitor->VerifyFound();
16213
16214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16215 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16216 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16217 buffer_128k.handle(), 1, &ds_region);
16218 m_errorMonitor->VerifyFound();
16219
16220 // Stencil copies that should succeed
16221 ds_region.bufferOffset = 0;
16222 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16223 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16224 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16225 buffer_64k.handle(), 1, &ds_region);
16226 m_errorMonitor->VerifyNotFound();
16227
16228 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16229 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16230 buffer_64k.handle(), 1, &ds_region);
16231 m_errorMonitor->VerifyNotFound();
16232
16233 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16234 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16235 buffer_64k.handle(), 1, &ds_region);
16236 m_errorMonitor->VerifyNotFound();
16237
16238 // Stencil copies that should fail
16239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16240 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16241 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16242 buffer_16k.handle(), 1, &ds_region);
16243 m_errorMonitor->VerifyFound();
16244
16245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16246 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16247 ds_region.bufferRowLength = 260;
16248 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16249 buffer_64k.handle(), 1, &ds_region);
16250 m_errorMonitor->VerifyFound();
16251
16252 ds_region.bufferRowLength = 0;
16253 ds_region.bufferOffset = 4;
16254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16255 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16256 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16257 buffer_64k.handle(), 1, &ds_region);
16258 m_errorMonitor->VerifyFound();
16259 }
16260
Dave Houlton584d51e2017-02-16 12:52:54 -070016261 // Test compressed formats, if supported
16262 VkPhysicalDeviceFeatures device_features;
16263 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016264 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16265 device_features.textureCompressionASTC_LDR)) {
16266 printf(" No compressed formats supported - block compression tests skipped.\n");
16267 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070016268 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16269 if (device_features.textureCompressionBC) {
16270 image_16k_4x4comp.init(32, 32, VK_FORMAT_BC5_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16271 } else if (device_features.textureCompressionETC2) {
16272 image_16k_4x4comp.init(32, 32, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16273 VK_IMAGE_TILING_OPTIMAL, 0);
16274 } else {
16275 image_16k_4x4comp.init(32, 32, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16276 0);
16277 }
16278 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016279
Dave Houlton584d51e2017-02-16 12:52:54 -070016280 // Just fits
16281 m_errorMonitor->ExpectSuccess();
16282 region.imageExtent = {128, 128, 1};
16283 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16284 buffer_16k.handle(), 1, &region);
16285 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016286
Dave Houlton584d51e2017-02-16 12:52:54 -070016287 // with offset, too big for buffer
16288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16289 region.bufferOffset = 16;
16290 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16291 buffer_16k.handle(), 1, &region);
16292 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016293
Dave Houlton584d51e2017-02-16 12:52:54 -070016294 // buffer offset must be a multiple of texel block size (16)
16295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16297 region.imageExtent = {64, 64, 1};
16298 region.bufferOffset = 24;
16299 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16300 buffer_16k.handle(), 1, &region);
16301 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016302
Dave Houlton584d51e2017-02-16 12:52:54 -070016303 // rowlength not a multiple of block width (4)
16304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16305 region.bufferOffset = 0;
16306 region.bufferRowLength = 130;
16307 region.bufferImageHeight = 0;
16308 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16309 buffer_64k.handle(), 1, &region);
16310 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016311
Dave Houlton584d51e2017-02-16 12:52:54 -070016312 // imageheight not a multiple of block height (4)
16313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16314 region.bufferRowLength = 0;
16315 region.bufferImageHeight = 130;
16316 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16317 buffer_64k.handle(), 1, &region);
16318 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016319
Dave Houlton584d51e2017-02-16 12:52:54 -070016320 // image extents must be multiple of block dimensions (4x4)
16321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16322 region.bufferImageHeight = 0;
16323 region.imageOffset = {4, 6, 0};
16324 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16325 buffer_64k.handle(), 1, &region);
16326 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016327
Dave Houlton584d51e2017-02-16 12:52:54 -070016328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16329 region.imageOffset = {22, 0, 0};
16330 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16331 buffer_64k.handle(), 1, &region);
16332 m_errorMonitor->VerifyFound();
16333 }
Dave Houlton59a20702017-02-02 17:26:23 -070016334}
16335
Tony Barbourd6673642016-05-05 14:46:39 -060016336TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016337 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016338
16339 ASSERT_NO_FATAL_FAILURE(InitState());
16340
Rene Lindsay135204f2016-12-22 17:11:09 -070016341 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016342 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016343 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 -070016344 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016345 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016346 vk_testing::Buffer buffer;
16347 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016348 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016349 VkBufferImageCopy region = {};
16350 region.bufferRowLength = 128;
16351 region.bufferImageHeight = 128;
16352 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16353 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016354 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016355 region.imageExtent.height = 4;
16356 region.imageExtent.width = 4;
16357 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016358
16359 VkImageObj image2(m_device);
16360 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 -070016361 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016362 ASSERT_TRUE(image2.initialized());
16363 vk_testing::Buffer buffer2;
16364 VkMemoryPropertyFlags reqs2 = 0;
16365 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16366 VkBufferImageCopy region2 = {};
16367 region2.bufferRowLength = 128;
16368 region2.bufferImageHeight = 128;
16369 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16370 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16371 region2.imageSubresource.layerCount = 1;
16372 region2.imageExtent.height = 4;
16373 region2.imageExtent.width = 4;
16374 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016375 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016376
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016377 // Image must have offset.z of 0 and extent.depth of 1
16378 // Introduce failure by setting imageExtent.depth to 0
16379 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016381 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016382 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016383 m_errorMonitor->VerifyFound();
16384
16385 region.imageExtent.depth = 1;
16386
16387 // Image must have offset.z of 0 and extent.depth of 1
16388 // Introduce failure by setting imageOffset.z to 4
16389 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016391 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016392 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016393 m_errorMonitor->VerifyFound();
16394
16395 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016396 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16397 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016398 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016400 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16401 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016402 m_errorMonitor->VerifyFound();
16403
16404 // BufferOffset must be a multiple of 4
16405 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016406 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016408 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16409 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016410 m_errorMonitor->VerifyFound();
16411
16412 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16413 region.bufferOffset = 0;
16414 region.imageExtent.height = 128;
16415 region.imageExtent.width = 128;
16416 // Introduce failure by setting bufferRowLength > 0 but less than width
16417 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016419 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16420 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016421 m_errorMonitor->VerifyFound();
16422
16423 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16424 region.bufferRowLength = 128;
16425 // Introduce failure by setting bufferRowHeight > 0 but less than height
16426 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016428 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16429 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016430 m_errorMonitor->VerifyFound();
16431
16432 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016433 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016434 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16435 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016436 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016437 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16438 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016439 VkImageBlit blitRegion = {};
16440 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16441 blitRegion.srcSubresource.baseArrayLayer = 0;
16442 blitRegion.srcSubresource.layerCount = 1;
16443 blitRegion.srcSubresource.mipLevel = 0;
16444 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16445 blitRegion.dstSubresource.baseArrayLayer = 0;
16446 blitRegion.dstSubresource.layerCount = 1;
16447 blitRegion.dstSubresource.mipLevel = 0;
16448
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016449 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016451 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016452 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16453 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016454 m_errorMonitor->VerifyFound();
16455
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016457 VkImageMemoryBarrier img_barrier;
16458 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16459 img_barrier.pNext = NULL;
16460 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16461 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16462 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16463 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16464 img_barrier.image = image.handle();
16465 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16466 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16467 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16468 img_barrier.subresourceRange.baseArrayLayer = 0;
16469 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016470 img_barrier.subresourceRange.layerCount = 0;
16471 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016472 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16473 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016474 m_errorMonitor->VerifyFound();
16475 img_barrier.subresourceRange.layerCount = 1;
16476}
16477
16478TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016479 TEST_DESCRIPTION("Exceed the limits of image format ");
16480
Cody Northropc31a84f2016-08-22 10:41:47 -060016481 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016483 VkImageCreateInfo image_create_info = {};
16484 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16485 image_create_info.pNext = NULL;
16486 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16487 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16488 image_create_info.extent.width = 32;
16489 image_create_info.extent.height = 32;
16490 image_create_info.extent.depth = 1;
16491 image_create_info.mipLevels = 1;
16492 image_create_info.arrayLayers = 1;
16493 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16494 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16495 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16496 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16497 image_create_info.flags = 0;
16498
16499 VkImage nullImg;
16500 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016501 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16502 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016503 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016504 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16505 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16506 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016507 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016510 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16511 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16512 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16513 m_errorMonitor->VerifyFound();
16514 image_create_info.mipLevels = 1;
16515
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016517 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16518 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16519 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16520 m_errorMonitor->VerifyFound();
16521 image_create_info.arrayLayers = 1;
16522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016524 int samples = imgFmtProps.sampleCounts >> 1;
16525 image_create_info.samples = (VkSampleCountFlagBits)samples;
16526 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16527 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16528 m_errorMonitor->VerifyFound();
16529 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16530
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16532 "pCreateInfo->initialLayout, must be "
16533 "VK_IMAGE_LAYOUT_UNDEFINED or "
16534 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016535 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16536 // Expect INVALID_LAYOUT
16537 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16538 m_errorMonitor->VerifyFound();
16539 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16540}
16541
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016542TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016543 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016545
16546 ASSERT_NO_FATAL_FAILURE(InitState());
16547
16548 VkImageObj src_image(m_device);
16549 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16550 VkImageObj dst_image(m_device);
16551 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16552
Tony Barbour552f6c02016-12-21 14:34:07 -070016553 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016554 VkImageCopy copy_region;
16555 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16556 copy_region.srcSubresource.mipLevel = 0;
16557 copy_region.srcSubresource.baseArrayLayer = 0;
16558 copy_region.srcSubresource.layerCount = 0;
16559 copy_region.srcOffset.x = 0;
16560 copy_region.srcOffset.y = 0;
16561 copy_region.srcOffset.z = 0;
16562 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16563 copy_region.dstSubresource.mipLevel = 0;
16564 copy_region.dstSubresource.baseArrayLayer = 0;
16565 copy_region.dstSubresource.layerCount = 0;
16566 copy_region.dstOffset.x = 0;
16567 copy_region.dstOffset.y = 0;
16568 copy_region.dstOffset.z = 0;
16569 copy_region.extent.width = 64;
16570 copy_region.extent.height = 64;
16571 copy_region.extent.depth = 1;
16572 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16573 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016574 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016575
16576 m_errorMonitor->VerifyFound();
16577}
16578
16579TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016580 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016582
16583 ASSERT_NO_FATAL_FAILURE(InitState());
16584
16585 VkImageObj src_image(m_device);
16586 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16587 VkImageObj dst_image(m_device);
16588 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16589
Tony Barbour552f6c02016-12-21 14:34:07 -070016590 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016591 VkImageCopy copy_region;
16592 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16593 copy_region.srcSubresource.mipLevel = 0;
16594 copy_region.srcSubresource.baseArrayLayer = 0;
16595 copy_region.srcSubresource.layerCount = 0;
16596 copy_region.srcOffset.x = 0;
16597 copy_region.srcOffset.y = 0;
16598 copy_region.srcOffset.z = 0;
16599 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16600 copy_region.dstSubresource.mipLevel = 0;
16601 copy_region.dstSubresource.baseArrayLayer = 0;
16602 copy_region.dstSubresource.layerCount = 0;
16603 copy_region.dstOffset.x = 0;
16604 copy_region.dstOffset.y = 0;
16605 copy_region.dstOffset.z = 0;
16606 copy_region.extent.width = 64;
16607 copy_region.extent.height = 64;
16608 copy_region.extent.depth = 1;
16609 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16610 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016611 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016612
16613 m_errorMonitor->VerifyFound();
16614}
16615
Karl Schultz6addd812016-02-02 17:17:23 -070016616TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016617 VkResult err;
16618 bool pass;
16619
16620 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016622
16623 ASSERT_NO_FATAL_FAILURE(InitState());
16624
16625 // Create two images of different types and try to copy between them
16626 VkImage srcImage;
16627 VkImage dstImage;
16628 VkDeviceMemory srcMem;
16629 VkDeviceMemory destMem;
16630 VkMemoryRequirements memReqs;
16631
16632 VkImageCreateInfo image_create_info = {};
16633 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16634 image_create_info.pNext = NULL;
16635 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16636 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16637 image_create_info.extent.width = 32;
16638 image_create_info.extent.height = 32;
16639 image_create_info.extent.depth = 1;
16640 image_create_info.mipLevels = 1;
16641 image_create_info.arrayLayers = 1;
16642 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16643 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16644 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16645 image_create_info.flags = 0;
16646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016647 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016648 ASSERT_VK_SUCCESS(err);
16649
16650 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16651 // Introduce failure by creating second image with a different-sized format.
16652 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016654 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016655 ASSERT_VK_SUCCESS(err);
16656
16657 // Allocate memory
16658 VkMemoryAllocateInfo memAlloc = {};
16659 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16660 memAlloc.pNext = NULL;
16661 memAlloc.allocationSize = 0;
16662 memAlloc.memoryTypeIndex = 0;
16663
16664 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16665 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016666 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016667 ASSERT_TRUE(pass);
16668 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16669 ASSERT_VK_SUCCESS(err);
16670
16671 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16672 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016673 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016674 ASSERT_TRUE(pass);
16675 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16676 ASSERT_VK_SUCCESS(err);
16677
16678 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16679 ASSERT_VK_SUCCESS(err);
16680 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16681 ASSERT_VK_SUCCESS(err);
16682
Tony Barbour552f6c02016-12-21 14:34:07 -070016683 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016684 VkImageCopy copyRegion;
16685 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16686 copyRegion.srcSubresource.mipLevel = 0;
16687 copyRegion.srcSubresource.baseArrayLayer = 0;
16688 copyRegion.srcSubresource.layerCount = 0;
16689 copyRegion.srcOffset.x = 0;
16690 copyRegion.srcOffset.y = 0;
16691 copyRegion.srcOffset.z = 0;
16692 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16693 copyRegion.dstSubresource.mipLevel = 0;
16694 copyRegion.dstSubresource.baseArrayLayer = 0;
16695 copyRegion.dstSubresource.layerCount = 0;
16696 copyRegion.dstOffset.x = 0;
16697 copyRegion.dstOffset.y = 0;
16698 copyRegion.dstOffset.z = 0;
16699 copyRegion.extent.width = 1;
16700 copyRegion.extent.height = 1;
16701 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016702 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016703 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016704
16705 m_errorMonitor->VerifyFound();
16706
16707 vkDestroyImage(m_device->device(), srcImage, NULL);
16708 vkDestroyImage(m_device->device(), dstImage, NULL);
16709 vkFreeMemory(m_device->device(), srcMem, NULL);
16710 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016711}
16712
Karl Schultz6addd812016-02-02 17:17:23 -070016713TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16714 VkResult err;
16715 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016716
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016717 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16719 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016720
Mike Stroyana3082432015-09-25 13:39:21 -060016721 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016722
16723 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016724 VkImage srcImage;
16725 VkImage dstImage;
16726 VkDeviceMemory srcMem;
16727 VkDeviceMemory destMem;
16728 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016729
16730 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016731 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16732 image_create_info.pNext = NULL;
16733 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16734 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16735 image_create_info.extent.width = 32;
16736 image_create_info.extent.height = 32;
16737 image_create_info.extent.depth = 1;
16738 image_create_info.mipLevels = 1;
16739 image_create_info.arrayLayers = 1;
16740 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16741 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16742 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16743 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016744
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016745 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016746 ASSERT_VK_SUCCESS(err);
16747
Karl Schultzbdb75952016-04-19 11:36:49 -060016748 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16749
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016750 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016751 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016752 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016753 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016756 ASSERT_VK_SUCCESS(err);
16757
16758 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016759 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016760 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16761 memAlloc.pNext = NULL;
16762 memAlloc.allocationSize = 0;
16763 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016764
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016765 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016766 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016767 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016768 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016769 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016770 ASSERT_VK_SUCCESS(err);
16771
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016772 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016773 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016774 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016775 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016776 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016777 ASSERT_VK_SUCCESS(err);
16778
16779 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16780 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016781 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016782 ASSERT_VK_SUCCESS(err);
16783
Tony Barbour552f6c02016-12-21 14:34:07 -070016784 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016785 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016786 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016787 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016788 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016789 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016790 copyRegion.srcOffset.x = 0;
16791 copyRegion.srcOffset.y = 0;
16792 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016793 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016794 copyRegion.dstSubresource.mipLevel = 0;
16795 copyRegion.dstSubresource.baseArrayLayer = 0;
16796 copyRegion.dstSubresource.layerCount = 0;
16797 copyRegion.dstOffset.x = 0;
16798 copyRegion.dstOffset.y = 0;
16799 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016800 copyRegion.extent.width = 1;
16801 copyRegion.extent.height = 1;
16802 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016803 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016804 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016805
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016806 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016807
Chia-I Wuf7458c52015-10-26 21:10:41 +080016808 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016809 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016810 vkFreeMemory(m_device->device(), srcMem, NULL);
16811 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016812}
16813
Karl Schultz6addd812016-02-02 17:17:23 -070016814TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16815 VkResult err;
16816 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16819 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016820
Mike Stroyana3082432015-09-25 13:39:21 -060016821 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016822
16823 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016824 VkImage srcImage;
16825 VkImage dstImage;
16826 VkDeviceMemory srcMem;
16827 VkDeviceMemory destMem;
16828 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016829
16830 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016831 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16832 image_create_info.pNext = NULL;
16833 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16834 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16835 image_create_info.extent.width = 32;
16836 image_create_info.extent.height = 1;
16837 image_create_info.extent.depth = 1;
16838 image_create_info.mipLevels = 1;
16839 image_create_info.arrayLayers = 1;
16840 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16841 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16842 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16843 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016844
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016845 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016846 ASSERT_VK_SUCCESS(err);
16847
Karl Schultz6addd812016-02-02 17:17:23 -070016848 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016850 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016851 ASSERT_VK_SUCCESS(err);
16852
16853 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016854 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016855 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16856 memAlloc.pNext = NULL;
16857 memAlloc.allocationSize = 0;
16858 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016859
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016860 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016861 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016862 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016863 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016864 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016865 ASSERT_VK_SUCCESS(err);
16866
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016867 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016868 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016869 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016870 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016871 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016872 ASSERT_VK_SUCCESS(err);
16873
16874 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16875 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016876 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016877 ASSERT_VK_SUCCESS(err);
16878
Tony Barbour552f6c02016-12-21 14:34:07 -070016879 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016880 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016881 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16882 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016883 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016884 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016885 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016886 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016887 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016888 resolveRegion.srcOffset.x = 0;
16889 resolveRegion.srcOffset.y = 0;
16890 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016891 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016892 resolveRegion.dstSubresource.mipLevel = 0;
16893 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016894 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016895 resolveRegion.dstOffset.x = 0;
16896 resolveRegion.dstOffset.y = 0;
16897 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016898 resolveRegion.extent.width = 1;
16899 resolveRegion.extent.height = 1;
16900 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016901 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016902 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016903
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016904 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016905
Chia-I Wuf7458c52015-10-26 21:10:41 +080016906 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016907 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016908 vkFreeMemory(m_device->device(), srcMem, NULL);
16909 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016910}
16911
Karl Schultz6addd812016-02-02 17:17:23 -070016912TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16913 VkResult err;
16914 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16917 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016918
Mike Stroyana3082432015-09-25 13:39:21 -060016919 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016920
Chris Forbesa7530692016-05-08 12:35:39 +120016921 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016922 VkImage srcImage;
16923 VkImage dstImage;
16924 VkDeviceMemory srcMem;
16925 VkDeviceMemory destMem;
16926 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016927
16928 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016929 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16930 image_create_info.pNext = NULL;
16931 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16932 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16933 image_create_info.extent.width = 32;
16934 image_create_info.extent.height = 1;
16935 image_create_info.extent.depth = 1;
16936 image_create_info.mipLevels = 1;
16937 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016938 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016939 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16940 // Note: Some implementations expect color attachment usage for any
16941 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016942 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016943 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016944
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016945 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016946 ASSERT_VK_SUCCESS(err);
16947
Karl Schultz6addd812016-02-02 17:17:23 -070016948 // Note: Some implementations expect color attachment usage for any
16949 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016950 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016952 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016953 ASSERT_VK_SUCCESS(err);
16954
16955 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016956 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016957 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16958 memAlloc.pNext = NULL;
16959 memAlloc.allocationSize = 0;
16960 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016961
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016962 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016963 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016964 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016965 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016966 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016967 ASSERT_VK_SUCCESS(err);
16968
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016969 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016970 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016971 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016972 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016973 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016974 ASSERT_VK_SUCCESS(err);
16975
16976 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16977 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016978 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016979 ASSERT_VK_SUCCESS(err);
16980
Tony Barbour552f6c02016-12-21 14:34:07 -070016981 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016982 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016983 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16984 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016985 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016986 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016987 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016988 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016989 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016990 resolveRegion.srcOffset.x = 0;
16991 resolveRegion.srcOffset.y = 0;
16992 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016993 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016994 resolveRegion.dstSubresource.mipLevel = 0;
16995 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016996 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016997 resolveRegion.dstOffset.x = 0;
16998 resolveRegion.dstOffset.y = 0;
16999 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017000 resolveRegion.extent.width = 1;
17001 resolveRegion.extent.height = 1;
17002 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017003 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017004 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017005
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017006 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017007
Chia-I Wuf7458c52015-10-26 21:10:41 +080017008 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017009 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017010 vkFreeMemory(m_device->device(), srcMem, NULL);
17011 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017012}
17013
Karl Schultz6addd812016-02-02 17:17:23 -070017014TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17015 VkResult err;
17016 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017017
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017019 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017020
Mike Stroyana3082432015-09-25 13:39:21 -060017021 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017022
17023 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017024 VkImage srcImage;
17025 VkImage dstImage;
17026 VkDeviceMemory srcMem;
17027 VkDeviceMemory destMem;
17028 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017029
17030 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017031 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17032 image_create_info.pNext = NULL;
17033 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17034 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17035 image_create_info.extent.width = 32;
17036 image_create_info.extent.height = 1;
17037 image_create_info.extent.depth = 1;
17038 image_create_info.mipLevels = 1;
17039 image_create_info.arrayLayers = 1;
17040 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17041 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17042 // Note: Some implementations expect color attachment usage for any
17043 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017044 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017045 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017047 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017048 ASSERT_VK_SUCCESS(err);
17049
Karl Schultz6addd812016-02-02 17:17:23 -070017050 // Set format to something other than source image
17051 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17052 // Note: Some implementations expect color attachment usage for any
17053 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017054 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017055 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017057 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017058 ASSERT_VK_SUCCESS(err);
17059
17060 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017061 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017062 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17063 memAlloc.pNext = NULL;
17064 memAlloc.allocationSize = 0;
17065 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017066
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017067 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017068 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017069 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017070 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017071 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017072 ASSERT_VK_SUCCESS(err);
17073
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017074 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017075 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017076 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017077 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017078 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017079 ASSERT_VK_SUCCESS(err);
17080
17081 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17082 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017083 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017084 ASSERT_VK_SUCCESS(err);
17085
Tony Barbour552f6c02016-12-21 14:34:07 -070017086 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017087 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017088 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17089 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017090 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017091 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017092 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017093 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017094 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017095 resolveRegion.srcOffset.x = 0;
17096 resolveRegion.srcOffset.y = 0;
17097 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017098 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017099 resolveRegion.dstSubresource.mipLevel = 0;
17100 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017101 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017102 resolveRegion.dstOffset.x = 0;
17103 resolveRegion.dstOffset.y = 0;
17104 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017105 resolveRegion.extent.width = 1;
17106 resolveRegion.extent.height = 1;
17107 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017108 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017109 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017110
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017111 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017112
Chia-I Wuf7458c52015-10-26 21:10:41 +080017113 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017114 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017115 vkFreeMemory(m_device->device(), srcMem, NULL);
17116 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017117}
17118
Karl Schultz6addd812016-02-02 17:17:23 -070017119TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17120 VkResult err;
17121 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017122
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017124 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017125
Mike Stroyana3082432015-09-25 13:39:21 -060017126 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017127
17128 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017129 VkImage srcImage;
17130 VkImage dstImage;
17131 VkDeviceMemory srcMem;
17132 VkDeviceMemory destMem;
17133 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017134
17135 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017136 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17137 image_create_info.pNext = NULL;
17138 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17139 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17140 image_create_info.extent.width = 32;
17141 image_create_info.extent.height = 1;
17142 image_create_info.extent.depth = 1;
17143 image_create_info.mipLevels = 1;
17144 image_create_info.arrayLayers = 1;
17145 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17146 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17147 // Note: Some implementations expect color attachment usage for any
17148 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017149 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017150 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017152 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017153 ASSERT_VK_SUCCESS(err);
17154
Karl Schultz6addd812016-02-02 17:17:23 -070017155 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17156 // Note: Some implementations expect color attachment usage for any
17157 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017158 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017159 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017161 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017162 ASSERT_VK_SUCCESS(err);
17163
17164 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017165 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017166 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17167 memAlloc.pNext = NULL;
17168 memAlloc.allocationSize = 0;
17169 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017170
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017171 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017172 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017173 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017174 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017175 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017176 ASSERT_VK_SUCCESS(err);
17177
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017178 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017179 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017180 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017181 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017182 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017183 ASSERT_VK_SUCCESS(err);
17184
17185 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17186 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017187 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017188 ASSERT_VK_SUCCESS(err);
17189
Tony Barbour552f6c02016-12-21 14:34:07 -070017190 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017191 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017192 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17193 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017194 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017195 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017196 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017197 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017198 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017199 resolveRegion.srcOffset.x = 0;
17200 resolveRegion.srcOffset.y = 0;
17201 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017202 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017203 resolveRegion.dstSubresource.mipLevel = 0;
17204 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017205 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017206 resolveRegion.dstOffset.x = 0;
17207 resolveRegion.dstOffset.y = 0;
17208 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017209 resolveRegion.extent.width = 1;
17210 resolveRegion.extent.height = 1;
17211 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017212 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017213 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017214
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017215 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017216
Chia-I Wuf7458c52015-10-26 21:10:41 +080017217 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017218 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017219 vkFreeMemory(m_device->device(), srcMem, NULL);
17220 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017221}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017222
Karl Schultz6addd812016-02-02 17:17:23 -070017223TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017224 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017225 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17226 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017227 // The image format check comes 2nd in validation so we trigger it first,
17228 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017229 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17232 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017233
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017234 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017235
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017236 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017237 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17238 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017239
17240 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017241 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17242 ds_pool_ci.pNext = NULL;
17243 ds_pool_ci.maxSets = 1;
17244 ds_pool_ci.poolSizeCount = 1;
17245 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017246
17247 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017248 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017249 ASSERT_VK_SUCCESS(err);
17250
17251 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017252 dsl_binding.binding = 0;
17253 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17254 dsl_binding.descriptorCount = 1;
17255 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17256 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017257
17258 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017259 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17260 ds_layout_ci.pNext = NULL;
17261 ds_layout_ci.bindingCount = 1;
17262 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017263 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017264 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017265 ASSERT_VK_SUCCESS(err);
17266
17267 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017268 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017269 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017270 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017271 alloc_info.descriptorPool = ds_pool;
17272 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017273 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017274 ASSERT_VK_SUCCESS(err);
17275
Karl Schultz6addd812016-02-02 17:17:23 -070017276 VkImage image_bad;
17277 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017278 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017279 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017280 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017281 const int32_t tex_width = 32;
17282 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017283
17284 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017285 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17286 image_create_info.pNext = NULL;
17287 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17288 image_create_info.format = tex_format_bad;
17289 image_create_info.extent.width = tex_width;
17290 image_create_info.extent.height = tex_height;
17291 image_create_info.extent.depth = 1;
17292 image_create_info.mipLevels = 1;
17293 image_create_info.arrayLayers = 1;
17294 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17295 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017296 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017297 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017299 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017300 ASSERT_VK_SUCCESS(err);
17301 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017302 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17303 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017304 ASSERT_VK_SUCCESS(err);
17305
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017306 // ---Bind image memory---
17307 VkMemoryRequirements img_mem_reqs;
17308 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17309 VkMemoryAllocateInfo image_alloc_info = {};
17310 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17311 image_alloc_info.pNext = NULL;
17312 image_alloc_info.memoryTypeIndex = 0;
17313 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017314 bool pass =
17315 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 -070017316 ASSERT_TRUE(pass);
17317 VkDeviceMemory mem;
17318 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17319 ASSERT_VK_SUCCESS(err);
17320 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17321 ASSERT_VK_SUCCESS(err);
17322 // -----------------------
17323
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017324 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017325 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017326 image_view_create_info.image = image_bad;
17327 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17328 image_view_create_info.format = tex_format_bad;
17329 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17330 image_view_create_info.subresourceRange.baseMipLevel = 0;
17331 image_view_create_info.subresourceRange.layerCount = 1;
17332 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017333 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017334
17335 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017336 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017337
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017338 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017339
Chia-I Wuf7458c52015-10-26 21:10:41 +080017340 vkDestroyImage(m_device->device(), image_bad, NULL);
17341 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017342 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17343 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017344
17345 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017346}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017347
17348TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017349 TEST_DESCRIPTION(
17350 "Call ClearColorImage w/ a depth|stencil image and "
17351 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017352
17353 ASSERT_NO_FATAL_FAILURE(InitState());
17354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17355
Tony Barbour552f6c02016-12-21 14:34:07 -070017356 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017357
17358 // Color image
17359 VkClearColorValue clear_color;
17360 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17361 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17362 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17363 const int32_t img_width = 32;
17364 const int32_t img_height = 32;
17365 VkImageCreateInfo image_create_info = {};
17366 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17367 image_create_info.pNext = NULL;
17368 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17369 image_create_info.format = color_format;
17370 image_create_info.extent.width = img_width;
17371 image_create_info.extent.height = img_height;
17372 image_create_info.extent.depth = 1;
17373 image_create_info.mipLevels = 1;
17374 image_create_info.arrayLayers = 1;
17375 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17376 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17377 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17378
17379 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017380 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017382 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017383
17384 // Depth/Stencil image
17385 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017386 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017387 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17388 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17389 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17390 ds_image_create_info.extent.width = 64;
17391 ds_image_create_info.extent.height = 64;
17392 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017393 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 -060017394
17395 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017396 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017398 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 -060017399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017401
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017402 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017403 &color_range);
17404
17405 m_errorMonitor->VerifyFound();
17406
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17408 "vkCmdClearColorImage called with "
17409 "image created without "
17410 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017411
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017412 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017413 &color_range);
17414
17415 m_errorMonitor->VerifyFound();
17416
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017417 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17419 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017420
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017421 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17422 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017423
17424 m_errorMonitor->VerifyFound();
17425}
Tobin Ehliscde08892015-09-22 10:11:37 -060017426
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017427// WSI Enabled Tests
17428//
Chris Forbes09368e42016-10-13 11:59:22 +130017429#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017430TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17431
17432#if defined(VK_USE_PLATFORM_XCB_KHR)
17433 VkSurfaceKHR surface = VK_NULL_HANDLE;
17434
17435 VkResult err;
17436 bool pass;
17437 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17438 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17439 // uint32_t swapchain_image_count = 0;
17440 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17441 // uint32_t image_index = 0;
17442 // VkPresentInfoKHR present_info = {};
17443
17444 ASSERT_NO_FATAL_FAILURE(InitState());
17445
17446 // Use the create function from one of the VK_KHR_*_surface extension in
17447 // order to create a surface, testing all known errors in the process,
17448 // before successfully creating a surface:
17449 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17451 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17452 pass = (err != VK_SUCCESS);
17453 ASSERT_TRUE(pass);
17454 m_errorMonitor->VerifyFound();
17455
17456 // Next, try to create a surface with the wrong
17457 // VkXcbSurfaceCreateInfoKHR::sType:
17458 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17459 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17461 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17462 pass = (err != VK_SUCCESS);
17463 ASSERT_TRUE(pass);
17464 m_errorMonitor->VerifyFound();
17465
17466 // Create a native window, and then correctly create a surface:
17467 xcb_connection_t *connection;
17468 xcb_screen_t *screen;
17469 xcb_window_t xcb_window;
17470 xcb_intern_atom_reply_t *atom_wm_delete_window;
17471
17472 const xcb_setup_t *setup;
17473 xcb_screen_iterator_t iter;
17474 int scr;
17475 uint32_t value_mask, value_list[32];
17476 int width = 1;
17477 int height = 1;
17478
17479 connection = xcb_connect(NULL, &scr);
17480 ASSERT_TRUE(connection != NULL);
17481 setup = xcb_get_setup(connection);
17482 iter = xcb_setup_roots_iterator(setup);
17483 while (scr-- > 0)
17484 xcb_screen_next(&iter);
17485 screen = iter.data;
17486
17487 xcb_window = xcb_generate_id(connection);
17488
17489 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17490 value_list[0] = screen->black_pixel;
17491 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17492
17493 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17494 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17495
17496 /* Magic code that will send notification when window is destroyed */
17497 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17498 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17499
17500 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17501 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17502 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17503 free(reply);
17504
17505 xcb_map_window(connection, xcb_window);
17506
17507 // Force the x/y coordinates to 100,100 results are identical in consecutive
17508 // runs
17509 const uint32_t coords[] = { 100, 100 };
17510 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17511
17512 // Finally, try to correctly create a surface:
17513 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17514 xcb_create_info.pNext = NULL;
17515 xcb_create_info.flags = 0;
17516 xcb_create_info.connection = connection;
17517 xcb_create_info.window = xcb_window;
17518 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17519 pass = (err == VK_SUCCESS);
17520 ASSERT_TRUE(pass);
17521
17522 // Check if surface supports presentation:
17523
17524 // 1st, do so without having queried the queue families:
17525 VkBool32 supported = false;
17526 // TODO: Get the following error to come out:
17527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17528 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17529 "function");
17530 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17531 pass = (err != VK_SUCCESS);
17532 // ASSERT_TRUE(pass);
17533 // m_errorMonitor->VerifyFound();
17534
17535 // Next, query a queue family index that's too large:
17536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17537 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17538 pass = (err != VK_SUCCESS);
17539 ASSERT_TRUE(pass);
17540 m_errorMonitor->VerifyFound();
17541
17542 // Finally, do so correctly:
17543 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17544 // SUPPORTED
17545 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17546 pass = (err == VK_SUCCESS);
17547 ASSERT_TRUE(pass);
17548
17549 // Before proceeding, try to create a swapchain without having called
17550 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17551 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17552 swapchain_create_info.pNext = NULL;
17553 swapchain_create_info.flags = 0;
17554 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17555 swapchain_create_info.surface = surface;
17556 swapchain_create_info.imageArrayLayers = 1;
17557 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17558 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17560 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17561 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17562 pass = (err != VK_SUCCESS);
17563 ASSERT_TRUE(pass);
17564 m_errorMonitor->VerifyFound();
17565
17566 // Get the surface capabilities:
17567 VkSurfaceCapabilitiesKHR surface_capabilities;
17568
17569 // Do so correctly (only error logged by this entrypoint is if the
17570 // extension isn't enabled):
17571 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17572 pass = (err == VK_SUCCESS);
17573 ASSERT_TRUE(pass);
17574
17575 // Get the surface formats:
17576 uint32_t surface_format_count;
17577
17578 // First, try without a pointer to surface_format_count:
17579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17580 "specified as NULL");
17581 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17582 pass = (err == VK_SUCCESS);
17583 ASSERT_TRUE(pass);
17584 m_errorMonitor->VerifyFound();
17585
17586 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17587 // correctly done a 1st try (to get the count):
17588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17589 surface_format_count = 0;
17590 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17591 pass = (err == VK_SUCCESS);
17592 ASSERT_TRUE(pass);
17593 m_errorMonitor->VerifyFound();
17594
17595 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17596 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17597 pass = (err == VK_SUCCESS);
17598 ASSERT_TRUE(pass);
17599
17600 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17601 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17602
17603 // Next, do a 2nd try with surface_format_count being set too high:
17604 surface_format_count += 5;
17605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17606 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17607 pass = (err == VK_SUCCESS);
17608 ASSERT_TRUE(pass);
17609 m_errorMonitor->VerifyFound();
17610
17611 // Finally, do a correct 1st and 2nd try:
17612 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17613 pass = (err == VK_SUCCESS);
17614 ASSERT_TRUE(pass);
17615 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17616 pass = (err == VK_SUCCESS);
17617 ASSERT_TRUE(pass);
17618
17619 // Get the surface present modes:
17620 uint32_t surface_present_mode_count;
17621
17622 // First, try without a pointer to surface_format_count:
17623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17624 "specified as NULL");
17625
17626 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17627 pass = (err == VK_SUCCESS);
17628 ASSERT_TRUE(pass);
17629 m_errorMonitor->VerifyFound();
17630
17631 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17632 // correctly done a 1st try (to get the count):
17633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17634 surface_present_mode_count = 0;
17635 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17636 (VkPresentModeKHR *)&surface_present_mode_count);
17637 pass = (err == VK_SUCCESS);
17638 ASSERT_TRUE(pass);
17639 m_errorMonitor->VerifyFound();
17640
17641 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17642 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17643 pass = (err == VK_SUCCESS);
17644 ASSERT_TRUE(pass);
17645
17646 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17647 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17648
17649 // Next, do a 2nd try with surface_format_count being set too high:
17650 surface_present_mode_count += 5;
17651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17652 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17653 pass = (err == VK_SUCCESS);
17654 ASSERT_TRUE(pass);
17655 m_errorMonitor->VerifyFound();
17656
17657 // Finally, do a correct 1st and 2nd try:
17658 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17659 pass = (err == VK_SUCCESS);
17660 ASSERT_TRUE(pass);
17661 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17662 pass = (err == VK_SUCCESS);
17663 ASSERT_TRUE(pass);
17664
17665 // Create a swapchain:
17666
17667 // First, try without a pointer to swapchain_create_info:
17668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17669 "specified as NULL");
17670
17671 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17672 pass = (err != VK_SUCCESS);
17673 ASSERT_TRUE(pass);
17674 m_errorMonitor->VerifyFound();
17675
17676 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17677 // sType:
17678 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17680
17681 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17682 pass = (err != VK_SUCCESS);
17683 ASSERT_TRUE(pass);
17684 m_errorMonitor->VerifyFound();
17685
17686 // Next, call with a NULL swapchain pointer:
17687 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17688 swapchain_create_info.pNext = NULL;
17689 swapchain_create_info.flags = 0;
17690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17691 "specified as NULL");
17692
17693 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17694 pass = (err != VK_SUCCESS);
17695 ASSERT_TRUE(pass);
17696 m_errorMonitor->VerifyFound();
17697
17698 // TODO: Enhance swapchain layer so that
17699 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17700
17701 // Next, call with a queue family index that's too large:
17702 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17703 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17704 swapchain_create_info.queueFamilyIndexCount = 2;
17705 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17707 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17708 pass = (err != VK_SUCCESS);
17709 ASSERT_TRUE(pass);
17710 m_errorMonitor->VerifyFound();
17711
17712 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17713 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17714 swapchain_create_info.queueFamilyIndexCount = 1;
17715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17716 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17717 "pCreateInfo->pQueueFamilyIndices).");
17718 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17719 pass = (err != VK_SUCCESS);
17720 ASSERT_TRUE(pass);
17721 m_errorMonitor->VerifyFound();
17722
17723 // Next, call with an invalid imageSharingMode:
17724 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17725 swapchain_create_info.queueFamilyIndexCount = 1;
17726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17727 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17728 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17729 pass = (err != VK_SUCCESS);
17730 ASSERT_TRUE(pass);
17731 m_errorMonitor->VerifyFound();
17732 // Fix for the future:
17733 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17734 // SUPPORTED
17735 swapchain_create_info.queueFamilyIndexCount = 0;
17736 queueFamilyIndex[0] = 0;
17737 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17738
17739 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17740 // Get the images from a swapchain:
17741 // Acquire an image from a swapchain:
17742 // Present an image to a swapchain:
17743 // Destroy the swapchain:
17744
17745 // TODOs:
17746 //
17747 // - Try destroying the device without first destroying the swapchain
17748 //
17749 // - Try destroying the device without first destroying the surface
17750 //
17751 // - Try destroying the surface without first destroying the swapchain
17752
17753 // Destroy the surface:
17754 vkDestroySurfaceKHR(instance(), surface, NULL);
17755
17756 // Tear down the window:
17757 xcb_destroy_window(connection, xcb_window);
17758 xcb_disconnect(connection);
17759
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017760#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017761 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017762#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017763}
Chris Forbes09368e42016-10-13 11:59:22 +130017764#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017765
17766//
17767// POSITIVE VALIDATION TESTS
17768//
17769// These tests do not expect to encounter ANY validation errors pass only if this is true
17770
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070017771TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
17772 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
17773 ASSERT_NO_FATAL_FAILURE(InitState());
17774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17775
17776 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17777 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17778 command_buffer_allocate_info.commandPool = m_commandPool;
17779 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17780 command_buffer_allocate_info.commandBufferCount = 1;
17781
17782 VkCommandBuffer secondary_command_buffer;
17783 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17784 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17785 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17786 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17787 command_buffer_inheritance_info.renderPass = m_renderPass;
17788 command_buffer_inheritance_info.framebuffer = m_framebuffer;
17789
17790 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17791 command_buffer_begin_info.flags =
17792 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
17793 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17794
17795 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17796 VkClearAttachment color_attachment;
17797 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17798 color_attachment.clearValue.color.float32[0] = 0;
17799 color_attachment.clearValue.color.float32[1] = 0;
17800 color_attachment.clearValue.color.float32[2] = 0;
17801 color_attachment.clearValue.color.float32[3] = 0;
17802 color_attachment.colorAttachment = 0;
17803 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
17804 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
17805}
17806
Tobin Ehlise0006882016-11-03 10:14:28 -060017807TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017808 TEST_DESCRIPTION(
17809 "Perform an image layout transition in a secondary command buffer followed "
17810 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017811 VkResult err;
17812 m_errorMonitor->ExpectSuccess();
17813 ASSERT_NO_FATAL_FAILURE(InitState());
17814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17815 // Allocate a secondary and primary cmd buffer
17816 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17817 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17818 command_buffer_allocate_info.commandPool = m_commandPool;
17819 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17820 command_buffer_allocate_info.commandBufferCount = 1;
17821
17822 VkCommandBuffer secondary_command_buffer;
17823 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17824 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17825 VkCommandBuffer primary_command_buffer;
17826 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17827 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17828 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17829 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17830 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17831 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17832 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17833
17834 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17835 ASSERT_VK_SUCCESS(err);
17836 VkImageObj image(m_device);
17837 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17838 ASSERT_TRUE(image.initialized());
17839 VkImageMemoryBarrier img_barrier = {};
17840 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17841 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17842 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17843 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17844 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17845 img_barrier.image = image.handle();
17846 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17847 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17848 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17849 img_barrier.subresourceRange.baseArrayLayer = 0;
17850 img_barrier.subresourceRange.baseMipLevel = 0;
17851 img_barrier.subresourceRange.layerCount = 1;
17852 img_barrier.subresourceRange.levelCount = 1;
17853 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17854 0, nullptr, 1, &img_barrier);
17855 err = vkEndCommandBuffer(secondary_command_buffer);
17856 ASSERT_VK_SUCCESS(err);
17857
17858 // Now update primary cmd buffer to execute secondary and transitions image
17859 command_buffer_begin_info.pInheritanceInfo = nullptr;
17860 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17861 ASSERT_VK_SUCCESS(err);
17862 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17863 VkImageMemoryBarrier img_barrier2 = {};
17864 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17865 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17866 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17867 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17868 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17869 img_barrier2.image = image.handle();
17870 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17871 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17872 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17873 img_barrier2.subresourceRange.baseArrayLayer = 0;
17874 img_barrier2.subresourceRange.baseMipLevel = 0;
17875 img_barrier2.subresourceRange.layerCount = 1;
17876 img_barrier2.subresourceRange.levelCount = 1;
17877 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17878 nullptr, 1, &img_barrier2);
17879 err = vkEndCommandBuffer(primary_command_buffer);
17880 ASSERT_VK_SUCCESS(err);
17881 VkSubmitInfo submit_info = {};
17882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17883 submit_info.commandBufferCount = 1;
17884 submit_info.pCommandBuffers = &primary_command_buffer;
17885 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17886 ASSERT_VK_SUCCESS(err);
17887 m_errorMonitor->VerifyNotFound();
17888 err = vkDeviceWaitIdle(m_device->device());
17889 ASSERT_VK_SUCCESS(err);
17890 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17891 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17892}
17893
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017894// This is a positive test. No failures are expected.
17895TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017896 TEST_DESCRIPTION(
17897 "Ensure that the vkUpdateDescriptorSets validation code "
17898 "is ignoring VkWriteDescriptorSet members that are not "
17899 "related to the descriptor type specified by "
17900 "VkWriteDescriptorSet::descriptorType. Correct "
17901 "validation behavior will result in the test running to "
17902 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017903
17904 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17905
17906 ASSERT_NO_FATAL_FAILURE(InitState());
17907
17908 // Image Case
17909 {
17910 m_errorMonitor->ExpectSuccess();
17911
17912 VkImage image;
17913 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17914 const int32_t tex_width = 32;
17915 const int32_t tex_height = 32;
17916 VkImageCreateInfo image_create_info = {};
17917 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17918 image_create_info.pNext = NULL;
17919 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17920 image_create_info.format = tex_format;
17921 image_create_info.extent.width = tex_width;
17922 image_create_info.extent.height = tex_height;
17923 image_create_info.extent.depth = 1;
17924 image_create_info.mipLevels = 1;
17925 image_create_info.arrayLayers = 1;
17926 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17927 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17928 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17929 image_create_info.flags = 0;
17930 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17931 ASSERT_VK_SUCCESS(err);
17932
17933 VkMemoryRequirements memory_reqs;
17934 VkDeviceMemory image_memory;
17935 bool pass;
17936 VkMemoryAllocateInfo memory_info = {};
17937 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17938 memory_info.pNext = NULL;
17939 memory_info.allocationSize = 0;
17940 memory_info.memoryTypeIndex = 0;
17941 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17942 memory_info.allocationSize = memory_reqs.size;
17943 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17944 ASSERT_TRUE(pass);
17945 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17946 ASSERT_VK_SUCCESS(err);
17947 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17948 ASSERT_VK_SUCCESS(err);
17949
17950 VkImageViewCreateInfo image_view_create_info = {};
17951 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17952 image_view_create_info.image = image;
17953 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17954 image_view_create_info.format = tex_format;
17955 image_view_create_info.subresourceRange.layerCount = 1;
17956 image_view_create_info.subresourceRange.baseMipLevel = 0;
17957 image_view_create_info.subresourceRange.levelCount = 1;
17958 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17959
17960 VkImageView view;
17961 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17962 ASSERT_VK_SUCCESS(err);
17963
17964 VkDescriptorPoolSize ds_type_count = {};
17965 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17966 ds_type_count.descriptorCount = 1;
17967
17968 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17969 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17970 ds_pool_ci.pNext = NULL;
17971 ds_pool_ci.maxSets = 1;
17972 ds_pool_ci.poolSizeCount = 1;
17973 ds_pool_ci.pPoolSizes = &ds_type_count;
17974
17975 VkDescriptorPool ds_pool;
17976 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17977 ASSERT_VK_SUCCESS(err);
17978
17979 VkDescriptorSetLayoutBinding dsl_binding = {};
17980 dsl_binding.binding = 0;
17981 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17982 dsl_binding.descriptorCount = 1;
17983 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17984 dsl_binding.pImmutableSamplers = NULL;
17985
17986 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17987 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17988 ds_layout_ci.pNext = NULL;
17989 ds_layout_ci.bindingCount = 1;
17990 ds_layout_ci.pBindings = &dsl_binding;
17991 VkDescriptorSetLayout ds_layout;
17992 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17993 ASSERT_VK_SUCCESS(err);
17994
17995 VkDescriptorSet descriptor_set;
17996 VkDescriptorSetAllocateInfo alloc_info = {};
17997 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17998 alloc_info.descriptorSetCount = 1;
17999 alloc_info.descriptorPool = ds_pool;
18000 alloc_info.pSetLayouts = &ds_layout;
18001 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18002 ASSERT_VK_SUCCESS(err);
18003
18004 VkDescriptorImageInfo image_info = {};
18005 image_info.imageView = view;
18006 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18007
18008 VkWriteDescriptorSet descriptor_write;
18009 memset(&descriptor_write, 0, sizeof(descriptor_write));
18010 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18011 descriptor_write.dstSet = descriptor_set;
18012 descriptor_write.dstBinding = 0;
18013 descriptor_write.descriptorCount = 1;
18014 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18015 descriptor_write.pImageInfo = &image_info;
18016
18017 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18018 // be
18019 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18020 // This will most likely produce a crash if the parameter_validation
18021 // layer
18022 // does not correctly ignore pBufferInfo.
18023 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18024 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18025
18026 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18027
18028 m_errorMonitor->VerifyNotFound();
18029
18030 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18031 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18032 vkDestroyImageView(m_device->device(), view, NULL);
18033 vkDestroyImage(m_device->device(), image, NULL);
18034 vkFreeMemory(m_device->device(), image_memory, NULL);
18035 }
18036
18037 // Buffer Case
18038 {
18039 m_errorMonitor->ExpectSuccess();
18040
18041 VkBuffer buffer;
18042 uint32_t queue_family_index = 0;
18043 VkBufferCreateInfo buffer_create_info = {};
18044 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18045 buffer_create_info.size = 1024;
18046 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18047 buffer_create_info.queueFamilyIndexCount = 1;
18048 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18049
18050 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18051 ASSERT_VK_SUCCESS(err);
18052
18053 VkMemoryRequirements memory_reqs;
18054 VkDeviceMemory buffer_memory;
18055 bool pass;
18056 VkMemoryAllocateInfo memory_info = {};
18057 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18058 memory_info.pNext = NULL;
18059 memory_info.allocationSize = 0;
18060 memory_info.memoryTypeIndex = 0;
18061
18062 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18063 memory_info.allocationSize = memory_reqs.size;
18064 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18065 ASSERT_TRUE(pass);
18066
18067 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18068 ASSERT_VK_SUCCESS(err);
18069 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18070 ASSERT_VK_SUCCESS(err);
18071
18072 VkDescriptorPoolSize ds_type_count = {};
18073 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18074 ds_type_count.descriptorCount = 1;
18075
18076 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18077 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18078 ds_pool_ci.pNext = NULL;
18079 ds_pool_ci.maxSets = 1;
18080 ds_pool_ci.poolSizeCount = 1;
18081 ds_pool_ci.pPoolSizes = &ds_type_count;
18082
18083 VkDescriptorPool ds_pool;
18084 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18085 ASSERT_VK_SUCCESS(err);
18086
18087 VkDescriptorSetLayoutBinding dsl_binding = {};
18088 dsl_binding.binding = 0;
18089 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18090 dsl_binding.descriptorCount = 1;
18091 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18092 dsl_binding.pImmutableSamplers = NULL;
18093
18094 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18095 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18096 ds_layout_ci.pNext = NULL;
18097 ds_layout_ci.bindingCount = 1;
18098 ds_layout_ci.pBindings = &dsl_binding;
18099 VkDescriptorSetLayout ds_layout;
18100 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18101 ASSERT_VK_SUCCESS(err);
18102
18103 VkDescriptorSet descriptor_set;
18104 VkDescriptorSetAllocateInfo alloc_info = {};
18105 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18106 alloc_info.descriptorSetCount = 1;
18107 alloc_info.descriptorPool = ds_pool;
18108 alloc_info.pSetLayouts = &ds_layout;
18109 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18110 ASSERT_VK_SUCCESS(err);
18111
18112 VkDescriptorBufferInfo buffer_info = {};
18113 buffer_info.buffer = buffer;
18114 buffer_info.offset = 0;
18115 buffer_info.range = 1024;
18116
18117 VkWriteDescriptorSet descriptor_write;
18118 memset(&descriptor_write, 0, sizeof(descriptor_write));
18119 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18120 descriptor_write.dstSet = descriptor_set;
18121 descriptor_write.dstBinding = 0;
18122 descriptor_write.descriptorCount = 1;
18123 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18124 descriptor_write.pBufferInfo = &buffer_info;
18125
18126 // Set pImageInfo and pTexelBufferView to invalid values, which should
18127 // be
18128 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18129 // This will most likely produce a crash if the parameter_validation
18130 // layer
18131 // does not correctly ignore pImageInfo.
18132 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18133 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18134
18135 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18136
18137 m_errorMonitor->VerifyNotFound();
18138
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018139 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18140 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18141 vkDestroyBuffer(m_device->device(), buffer, NULL);
18142 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18143 }
18144
18145 // Texel Buffer Case
18146 {
18147 m_errorMonitor->ExpectSuccess();
18148
18149 VkBuffer buffer;
18150 uint32_t queue_family_index = 0;
18151 VkBufferCreateInfo buffer_create_info = {};
18152 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18153 buffer_create_info.size = 1024;
18154 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18155 buffer_create_info.queueFamilyIndexCount = 1;
18156 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18157
18158 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18159 ASSERT_VK_SUCCESS(err);
18160
18161 VkMemoryRequirements memory_reqs;
18162 VkDeviceMemory buffer_memory;
18163 bool pass;
18164 VkMemoryAllocateInfo memory_info = {};
18165 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18166 memory_info.pNext = NULL;
18167 memory_info.allocationSize = 0;
18168 memory_info.memoryTypeIndex = 0;
18169
18170 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18171 memory_info.allocationSize = memory_reqs.size;
18172 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18173 ASSERT_TRUE(pass);
18174
18175 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18176 ASSERT_VK_SUCCESS(err);
18177 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18178 ASSERT_VK_SUCCESS(err);
18179
18180 VkBufferViewCreateInfo buff_view_ci = {};
18181 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18182 buff_view_ci.buffer = buffer;
18183 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18184 buff_view_ci.range = VK_WHOLE_SIZE;
18185 VkBufferView buffer_view;
18186 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18187
18188 VkDescriptorPoolSize ds_type_count = {};
18189 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18190 ds_type_count.descriptorCount = 1;
18191
18192 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18193 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18194 ds_pool_ci.pNext = NULL;
18195 ds_pool_ci.maxSets = 1;
18196 ds_pool_ci.poolSizeCount = 1;
18197 ds_pool_ci.pPoolSizes = &ds_type_count;
18198
18199 VkDescriptorPool ds_pool;
18200 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18201 ASSERT_VK_SUCCESS(err);
18202
18203 VkDescriptorSetLayoutBinding dsl_binding = {};
18204 dsl_binding.binding = 0;
18205 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18206 dsl_binding.descriptorCount = 1;
18207 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18208 dsl_binding.pImmutableSamplers = NULL;
18209
18210 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18211 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18212 ds_layout_ci.pNext = NULL;
18213 ds_layout_ci.bindingCount = 1;
18214 ds_layout_ci.pBindings = &dsl_binding;
18215 VkDescriptorSetLayout ds_layout;
18216 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18217 ASSERT_VK_SUCCESS(err);
18218
18219 VkDescriptorSet descriptor_set;
18220 VkDescriptorSetAllocateInfo alloc_info = {};
18221 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18222 alloc_info.descriptorSetCount = 1;
18223 alloc_info.descriptorPool = ds_pool;
18224 alloc_info.pSetLayouts = &ds_layout;
18225 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18226 ASSERT_VK_SUCCESS(err);
18227
18228 VkWriteDescriptorSet descriptor_write;
18229 memset(&descriptor_write, 0, sizeof(descriptor_write));
18230 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18231 descriptor_write.dstSet = descriptor_set;
18232 descriptor_write.dstBinding = 0;
18233 descriptor_write.descriptorCount = 1;
18234 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18235 descriptor_write.pTexelBufferView = &buffer_view;
18236
18237 // Set pImageInfo and pBufferInfo to invalid values, which should be
18238 // ignored for descriptorType ==
18239 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18240 // This will most likely produce a crash if the parameter_validation
18241 // layer
18242 // does not correctly ignore pImageInfo and pBufferInfo.
18243 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18244 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18245
18246 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18247
18248 m_errorMonitor->VerifyNotFound();
18249
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018250 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18251 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18252 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18253 vkDestroyBuffer(m_device->device(), buffer, NULL);
18254 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18255 }
18256}
18257
Tobin Ehlisf7428442016-10-25 07:58:24 -060018258TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18259 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18260
18261 ASSERT_NO_FATAL_FAILURE(InitState());
18262 // Create layout where two binding #s are "1"
18263 static const uint32_t NUM_BINDINGS = 3;
18264 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18265 dsl_binding[0].binding = 1;
18266 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18267 dsl_binding[0].descriptorCount = 1;
18268 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18269 dsl_binding[0].pImmutableSamplers = NULL;
18270 dsl_binding[1].binding = 0;
18271 dsl_binding[1].descriptorCount = 1;
18272 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18273 dsl_binding[1].descriptorCount = 1;
18274 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18275 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018276 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018277 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18278 dsl_binding[2].descriptorCount = 1;
18279 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18280 dsl_binding[2].pImmutableSamplers = NULL;
18281
18282 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18283 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18284 ds_layout_ci.pNext = NULL;
18285 ds_layout_ci.bindingCount = NUM_BINDINGS;
18286 ds_layout_ci.pBindings = dsl_binding;
18287 VkDescriptorSetLayout ds_layout;
18288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18289 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18290 m_errorMonitor->VerifyFound();
18291}
18292
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018293TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018294 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18295
18296 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018297
Tony Barbour552f6c02016-12-21 14:34:07 -070018298 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018299
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018300 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18301
18302 {
18303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18304 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18305 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18306 m_errorMonitor->VerifyFound();
18307 }
18308
18309 {
18310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18311 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18312 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18313 m_errorMonitor->VerifyFound();
18314 }
18315
18316 {
18317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18318 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18319 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18320 m_errorMonitor->VerifyFound();
18321 }
18322
18323 {
18324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18325 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18326 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18327 m_errorMonitor->VerifyFound();
18328 }
18329
18330 {
18331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18332 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18333 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18334 m_errorMonitor->VerifyFound();
18335 }
18336
18337 {
18338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18339 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18340 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18341 m_errorMonitor->VerifyFound();
18342 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018343
18344 {
18345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18346 VkRect2D scissor = {{-1, 0}, {16, 16}};
18347 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18348 m_errorMonitor->VerifyFound();
18349 }
18350
18351 {
18352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18353 VkRect2D scissor = {{0, -2}, {16, 16}};
18354 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18355 m_errorMonitor->VerifyFound();
18356 }
18357
18358 {
18359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18360 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18361 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18362 m_errorMonitor->VerifyFound();
18363 }
18364
18365 {
18366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18367 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18368 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18369 m_errorMonitor->VerifyFound();
18370 }
18371
Tony Barbour552f6c02016-12-21 14:34:07 -070018372 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018373}
18374
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018375// This is a positive test. No failures are expected.
18376TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18377 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18378 VkResult err;
18379
18380 ASSERT_NO_FATAL_FAILURE(InitState());
18381 m_errorMonitor->ExpectSuccess();
18382 VkDescriptorPoolSize ds_type_count = {};
18383 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18384 ds_type_count.descriptorCount = 2;
18385
18386 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18387 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18388 ds_pool_ci.pNext = NULL;
18389 ds_pool_ci.maxSets = 1;
18390 ds_pool_ci.poolSizeCount = 1;
18391 ds_pool_ci.pPoolSizes = &ds_type_count;
18392
18393 VkDescriptorPool ds_pool;
18394 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18395 ASSERT_VK_SUCCESS(err);
18396
18397 // Create layout with two uniform buffer descriptors w/ empty binding between them
18398 static const uint32_t NUM_BINDINGS = 3;
18399 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18400 dsl_binding[0].binding = 0;
18401 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18402 dsl_binding[0].descriptorCount = 1;
18403 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18404 dsl_binding[0].pImmutableSamplers = NULL;
18405 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018406 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018407 dsl_binding[2].binding = 2;
18408 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18409 dsl_binding[2].descriptorCount = 1;
18410 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18411 dsl_binding[2].pImmutableSamplers = NULL;
18412
18413 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18414 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18415 ds_layout_ci.pNext = NULL;
18416 ds_layout_ci.bindingCount = NUM_BINDINGS;
18417 ds_layout_ci.pBindings = dsl_binding;
18418 VkDescriptorSetLayout ds_layout;
18419 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18420 ASSERT_VK_SUCCESS(err);
18421
18422 VkDescriptorSet descriptor_set = {};
18423 VkDescriptorSetAllocateInfo alloc_info = {};
18424 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18425 alloc_info.descriptorSetCount = 1;
18426 alloc_info.descriptorPool = ds_pool;
18427 alloc_info.pSetLayouts = &ds_layout;
18428 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18429 ASSERT_VK_SUCCESS(err);
18430
18431 // Create a buffer to be used for update
18432 VkBufferCreateInfo buff_ci = {};
18433 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18434 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18435 buff_ci.size = 256;
18436 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18437 VkBuffer buffer;
18438 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18439 ASSERT_VK_SUCCESS(err);
18440 // Have to bind memory to buffer before descriptor update
18441 VkMemoryAllocateInfo mem_alloc = {};
18442 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18443 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018444 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018445 mem_alloc.memoryTypeIndex = 0;
18446
18447 VkMemoryRequirements mem_reqs;
18448 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18449 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18450 if (!pass) {
18451 vkDestroyBuffer(m_device->device(), buffer, NULL);
18452 return;
18453 }
18454
18455 VkDeviceMemory mem;
18456 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18457 ASSERT_VK_SUCCESS(err);
18458 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18459 ASSERT_VK_SUCCESS(err);
18460
18461 // Only update the descriptor at binding 2
18462 VkDescriptorBufferInfo buff_info = {};
18463 buff_info.buffer = buffer;
18464 buff_info.offset = 0;
18465 buff_info.range = VK_WHOLE_SIZE;
18466 VkWriteDescriptorSet descriptor_write = {};
18467 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18468 descriptor_write.dstBinding = 2;
18469 descriptor_write.descriptorCount = 1;
18470 descriptor_write.pTexelBufferView = nullptr;
18471 descriptor_write.pBufferInfo = &buff_info;
18472 descriptor_write.pImageInfo = nullptr;
18473 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18474 descriptor_write.dstSet = descriptor_set;
18475
18476 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18477
18478 m_errorMonitor->VerifyNotFound();
18479 // Cleanup
18480 vkFreeMemory(m_device->device(), mem, NULL);
18481 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18482 vkDestroyBuffer(m_device->device(), buffer, NULL);
18483 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18484}
18485
18486// This is a positive test. No failures are expected.
18487TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18488 VkResult err;
18489 bool pass;
18490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018491 TEST_DESCRIPTION(
18492 "Create a buffer, allocate memory, bind memory, destroy "
18493 "the buffer, create an image, and bind the same memory to "
18494 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018495
18496 m_errorMonitor->ExpectSuccess();
18497
18498 ASSERT_NO_FATAL_FAILURE(InitState());
18499
18500 VkBuffer buffer;
18501 VkImage image;
18502 VkDeviceMemory mem;
18503 VkMemoryRequirements mem_reqs;
18504
18505 VkBufferCreateInfo buf_info = {};
18506 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18507 buf_info.pNext = NULL;
18508 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18509 buf_info.size = 256;
18510 buf_info.queueFamilyIndexCount = 0;
18511 buf_info.pQueueFamilyIndices = NULL;
18512 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18513 buf_info.flags = 0;
18514 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18515 ASSERT_VK_SUCCESS(err);
18516
18517 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18518
18519 VkMemoryAllocateInfo alloc_info = {};
18520 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18521 alloc_info.pNext = NULL;
18522 alloc_info.memoryTypeIndex = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070018523
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018524 // Ensure memory is big enough for both bindings
18525 alloc_info.allocationSize = 0x10000;
18526
18527 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18528 if (!pass) {
18529 vkDestroyBuffer(m_device->device(), buffer, NULL);
18530 return;
18531 }
18532
18533 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18534 ASSERT_VK_SUCCESS(err);
18535
18536 uint8_t *pData;
18537 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18538 ASSERT_VK_SUCCESS(err);
18539
18540 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18541
18542 vkUnmapMemory(m_device->device(), mem);
18543
18544 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18545 ASSERT_VK_SUCCESS(err);
18546
18547 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18548 // memory. In fact, it was never used by the GPU.
18549 // Just be be sure, wait for idle.
18550 vkDestroyBuffer(m_device->device(), buffer, NULL);
18551 vkDeviceWaitIdle(m_device->device());
18552
Tobin Ehlis6a005702016-12-28 15:25:56 -070018553 // Use optimal as some platforms report linear support but then fail image creation
18554 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18555 VkImageFormatProperties image_format_properties;
18556 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18557 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18558 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018559 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018560 vkFreeMemory(m_device->device(), mem, NULL);
18561 return;
18562 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018563 VkImageCreateInfo image_create_info = {};
18564 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18565 image_create_info.pNext = NULL;
18566 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18567 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18568 image_create_info.extent.width = 64;
18569 image_create_info.extent.height = 64;
18570 image_create_info.extent.depth = 1;
18571 image_create_info.mipLevels = 1;
18572 image_create_info.arrayLayers = 1;
18573 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018574 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018575 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18576 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18577 image_create_info.queueFamilyIndexCount = 0;
18578 image_create_info.pQueueFamilyIndices = NULL;
18579 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18580 image_create_info.flags = 0;
18581
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018582 /* Create a mappable image. It will be the texture if linear images are ok
18583 * to be textures or it will be the staging image if they are not.
18584 */
18585 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18586 ASSERT_VK_SUCCESS(err);
18587
18588 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18589
Tobin Ehlis6a005702016-12-28 15:25:56 -070018590 VkMemoryAllocateInfo mem_alloc = {};
18591 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18592 mem_alloc.pNext = NULL;
18593 mem_alloc.allocationSize = 0;
18594 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018595 mem_alloc.allocationSize = mem_reqs.size;
18596
18597 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18598 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018599 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018600 vkDestroyImage(m_device->device(), image, NULL);
18601 return;
18602 }
18603
18604 // VALIDATION FAILURE:
18605 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18606 ASSERT_VK_SUCCESS(err);
18607
18608 m_errorMonitor->VerifyNotFound();
18609
18610 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018611 vkDestroyImage(m_device->device(), image, NULL);
18612}
18613
Tony Barbourab713912017-02-02 14:17:35 -070018614// This is a positive test. No failures are expected.
18615TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18616 VkResult err;
18617
18618 TEST_DESCRIPTION(
18619 "Call all applicable destroy and free routines with NULL"
18620 "handles, expecting no validation errors");
18621
18622 m_errorMonitor->ExpectSuccess();
18623
18624 ASSERT_NO_FATAL_FAILURE(InitState());
18625 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18626 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18627 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18628 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18629 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18630 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18631 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18632 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18633 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18634 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18635 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18636 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18637 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18638 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18639 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18640 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18641 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18642 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18643 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18644 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18645
18646 VkCommandPool command_pool;
18647 VkCommandPoolCreateInfo pool_create_info{};
18648 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18649 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18650 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18651 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18652 VkCommandBuffer command_buffers[3] = {};
18653 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18654 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18655 command_buffer_allocate_info.commandPool = command_pool;
18656 command_buffer_allocate_info.commandBufferCount = 1;
18657 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18658 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18659 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18660 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18661
18662 VkDescriptorPoolSize ds_type_count = {};
18663 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18664 ds_type_count.descriptorCount = 1;
18665
18666 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18667 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18668 ds_pool_ci.pNext = NULL;
18669 ds_pool_ci.maxSets = 1;
18670 ds_pool_ci.poolSizeCount = 1;
18671 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18672 ds_pool_ci.pPoolSizes = &ds_type_count;
18673
18674 VkDescriptorPool ds_pool;
18675 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18676 ASSERT_VK_SUCCESS(err);
18677
18678 VkDescriptorSetLayoutBinding dsl_binding = {};
18679 dsl_binding.binding = 2;
18680 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18681 dsl_binding.descriptorCount = 1;
18682 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18683 dsl_binding.pImmutableSamplers = NULL;
18684 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18685 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18686 ds_layout_ci.pNext = NULL;
18687 ds_layout_ci.bindingCount = 1;
18688 ds_layout_ci.pBindings = &dsl_binding;
18689 VkDescriptorSetLayout ds_layout;
18690 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18691 ASSERT_VK_SUCCESS(err);
18692
18693 VkDescriptorSet descriptor_sets[3] = {};
18694 VkDescriptorSetAllocateInfo alloc_info = {};
18695 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18696 alloc_info.descriptorSetCount = 1;
18697 alloc_info.descriptorPool = ds_pool;
18698 alloc_info.pSetLayouts = &ds_layout;
18699 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18700 ASSERT_VK_SUCCESS(err);
18701 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18702 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18703 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18704
18705 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18706
18707 m_errorMonitor->VerifyNotFound();
18708}
18709
Tony Barbour626994c2017-02-08 15:29:37 -070018710TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018711 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018712
18713 m_errorMonitor->ExpectSuccess();
18714
18715 ASSERT_NO_FATAL_FAILURE(InitState());
18716 VkCommandBuffer cmd_bufs[4];
18717 VkCommandBufferAllocateInfo alloc_info;
18718 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18719 alloc_info.pNext = NULL;
18720 alloc_info.commandBufferCount = 4;
18721 alloc_info.commandPool = m_commandPool;
18722 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18723 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18724 VkImageObj image(m_device);
18725 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18726 ASSERT_TRUE(image.initialized());
18727 VkCommandBufferBeginInfo cb_binfo;
18728 cb_binfo.pNext = NULL;
18729 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18730 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18731 cb_binfo.flags = 0;
18732 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18733 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18734 VkImageMemoryBarrier img_barrier = {};
18735 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18736 img_barrier.pNext = NULL;
18737 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18738 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18739 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18740 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18741 img_barrier.image = image.handle();
18742 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18743 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18744 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18745 img_barrier.subresourceRange.baseArrayLayer = 0;
18746 img_barrier.subresourceRange.baseMipLevel = 0;
18747 img_barrier.subresourceRange.layerCount = 1;
18748 img_barrier.subresourceRange.levelCount = 1;
18749 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18750 &img_barrier);
18751 vkEndCommandBuffer(cmd_bufs[0]);
18752 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18753 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18754 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18755 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18756 &img_barrier);
18757 vkEndCommandBuffer(cmd_bufs[1]);
18758 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18759 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18760 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18761 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18762 &img_barrier);
18763 vkEndCommandBuffer(cmd_bufs[2]);
18764 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18765 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18766 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18767 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18768 &img_barrier);
18769 vkEndCommandBuffer(cmd_bufs[3]);
18770
18771 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18772 VkSemaphore semaphore1, semaphore2;
18773 VkSemaphoreCreateInfo semaphore_create_info{};
18774 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18775 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18776 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18777 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18778 VkSubmitInfo submit_info[3];
18779 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18780 submit_info[0].pNext = nullptr;
18781 submit_info[0].commandBufferCount = 1;
18782 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18783 submit_info[0].signalSemaphoreCount = 1;
18784 submit_info[0].pSignalSemaphores = &semaphore1;
18785 submit_info[0].waitSemaphoreCount = 0;
18786 submit_info[0].pWaitDstStageMask = nullptr;
18787 submit_info[0].pWaitDstStageMask = flags;
18788 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18789 submit_info[1].pNext = nullptr;
18790 submit_info[1].commandBufferCount = 1;
18791 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18792 submit_info[1].waitSemaphoreCount = 1;
18793 submit_info[1].pWaitSemaphores = &semaphore1;
18794 submit_info[1].signalSemaphoreCount = 1;
18795 submit_info[1].pSignalSemaphores = &semaphore2;
18796 submit_info[1].pWaitDstStageMask = flags;
18797 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18798 submit_info[2].pNext = nullptr;
18799 submit_info[2].commandBufferCount = 2;
18800 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18801 submit_info[2].waitSemaphoreCount = 1;
18802 submit_info[2].pWaitSemaphores = &semaphore2;
18803 submit_info[2].signalSemaphoreCount = 0;
18804 submit_info[2].pSignalSemaphores = nullptr;
18805 submit_info[2].pWaitDstStageMask = flags;
18806 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18807 vkQueueWaitIdle(m_device->m_queue);
18808
18809 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18810 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18811 m_errorMonitor->VerifyNotFound();
18812}
18813
Tobin Ehlis953e8392016-11-17 10:54:13 -070018814TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18815 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18816 // We previously had a bug where dynamic offset of inactive bindings was still being used
18817 VkResult err;
18818 m_errorMonitor->ExpectSuccess();
18819
18820 ASSERT_NO_FATAL_FAILURE(InitState());
18821 ASSERT_NO_FATAL_FAILURE(InitViewport());
18822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18823
18824 VkDescriptorPoolSize ds_type_count = {};
18825 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18826 ds_type_count.descriptorCount = 3;
18827
18828 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18829 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18830 ds_pool_ci.pNext = NULL;
18831 ds_pool_ci.maxSets = 1;
18832 ds_pool_ci.poolSizeCount = 1;
18833 ds_pool_ci.pPoolSizes = &ds_type_count;
18834
18835 VkDescriptorPool ds_pool;
18836 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18837 ASSERT_VK_SUCCESS(err);
18838
18839 const uint32_t BINDING_COUNT = 3;
18840 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018841 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018842 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18843 dsl_binding[0].descriptorCount = 1;
18844 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18845 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018846 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018847 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18848 dsl_binding[1].descriptorCount = 1;
18849 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18850 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018851 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018852 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18853 dsl_binding[2].descriptorCount = 1;
18854 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18855 dsl_binding[2].pImmutableSamplers = NULL;
18856
18857 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18858 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18859 ds_layout_ci.pNext = NULL;
18860 ds_layout_ci.bindingCount = BINDING_COUNT;
18861 ds_layout_ci.pBindings = dsl_binding;
18862 VkDescriptorSetLayout ds_layout;
18863 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18864 ASSERT_VK_SUCCESS(err);
18865
18866 VkDescriptorSet descriptor_set;
18867 VkDescriptorSetAllocateInfo alloc_info = {};
18868 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18869 alloc_info.descriptorSetCount = 1;
18870 alloc_info.descriptorPool = ds_pool;
18871 alloc_info.pSetLayouts = &ds_layout;
18872 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18873 ASSERT_VK_SUCCESS(err);
18874
18875 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18876 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18877 pipeline_layout_ci.pNext = NULL;
18878 pipeline_layout_ci.setLayoutCount = 1;
18879 pipeline_layout_ci.pSetLayouts = &ds_layout;
18880
18881 VkPipelineLayout pipeline_layout;
18882 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18883 ASSERT_VK_SUCCESS(err);
18884
18885 // Create two buffers to update the descriptors with
18886 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18887 uint32_t qfi = 0;
18888 VkBufferCreateInfo buffCI = {};
18889 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18890 buffCI.size = 2048;
18891 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18892 buffCI.queueFamilyIndexCount = 1;
18893 buffCI.pQueueFamilyIndices = &qfi;
18894
18895 VkBuffer dyub1;
18896 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18897 ASSERT_VK_SUCCESS(err);
18898 // buffer2
18899 buffCI.size = 1024;
18900 VkBuffer dyub2;
18901 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18902 ASSERT_VK_SUCCESS(err);
18903 // Allocate memory and bind to buffers
18904 VkMemoryAllocateInfo mem_alloc[2] = {};
18905 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18906 mem_alloc[0].pNext = NULL;
18907 mem_alloc[0].memoryTypeIndex = 0;
18908 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18909 mem_alloc[1].pNext = NULL;
18910 mem_alloc[1].memoryTypeIndex = 0;
18911
18912 VkMemoryRequirements mem_reqs1;
18913 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18914 VkMemoryRequirements mem_reqs2;
18915 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18916 mem_alloc[0].allocationSize = mem_reqs1.size;
18917 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18918 mem_alloc[1].allocationSize = mem_reqs2.size;
18919 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18920 if (!pass) {
18921 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18922 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18923 return;
18924 }
18925
18926 VkDeviceMemory mem1;
18927 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18928 ASSERT_VK_SUCCESS(err);
18929 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18930 ASSERT_VK_SUCCESS(err);
18931 VkDeviceMemory mem2;
18932 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18933 ASSERT_VK_SUCCESS(err);
18934 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18935 ASSERT_VK_SUCCESS(err);
18936 // Update descriptors
18937 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18938 buff_info[0].buffer = dyub1;
18939 buff_info[0].offset = 0;
18940 buff_info[0].range = 256;
18941 buff_info[1].buffer = dyub1;
18942 buff_info[1].offset = 256;
18943 buff_info[1].range = 512;
18944 buff_info[2].buffer = dyub2;
18945 buff_info[2].offset = 0;
18946 buff_info[2].range = 512;
18947
18948 VkWriteDescriptorSet descriptor_write;
18949 memset(&descriptor_write, 0, sizeof(descriptor_write));
18950 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18951 descriptor_write.dstSet = descriptor_set;
18952 descriptor_write.dstBinding = 0;
18953 descriptor_write.descriptorCount = BINDING_COUNT;
18954 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18955 descriptor_write.pBufferInfo = buff_info;
18956
18957 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18958
Tony Barbour552f6c02016-12-21 14:34:07 -070018959 m_commandBuffer->BeginCommandBuffer();
18960 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018961
18962 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018963 char const *vsSource =
18964 "#version 450\n"
18965 "\n"
18966 "out gl_PerVertex { \n"
18967 " vec4 gl_Position;\n"
18968 "};\n"
18969 "void main(){\n"
18970 " gl_Position = vec4(1);\n"
18971 "}\n";
18972 char const *fsSource =
18973 "#version 450\n"
18974 "\n"
18975 "layout(location=0) out vec4 x;\n"
18976 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18977 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18978 "void main(){\n"
18979 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18980 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018981 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18982 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18983 VkPipelineObj pipe(m_device);
18984 pipe.SetViewport(m_viewports);
18985 pipe.SetScissor(m_scissors);
18986 pipe.AddShader(&vs);
18987 pipe.AddShader(&fs);
18988 pipe.AddColorAttachment();
18989 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18990
18991 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18992 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18993 // we used to have a bug in this case.
18994 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18995 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18996 &descriptor_set, BINDING_COUNT, dyn_off);
18997 Draw(1, 0, 0, 0);
18998 m_errorMonitor->VerifyNotFound();
18999
19000 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19001 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19002 vkFreeMemory(m_device->device(), mem1, NULL);
19003 vkFreeMemory(m_device->device(), mem2, NULL);
19004
19005 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19006 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19007 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19008}
19009
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019010TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019011 TEST_DESCRIPTION(
19012 "Ensure that validations handling of non-coherent memory "
19013 "mapping while using VK_WHOLE_SIZE does not cause access "
19014 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019015 VkResult err;
19016 uint8_t *pData;
19017 ASSERT_NO_FATAL_FAILURE(InitState());
19018
19019 VkDeviceMemory mem;
19020 VkMemoryRequirements mem_reqs;
19021 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019022 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019023 VkMemoryAllocateInfo alloc_info = {};
19024 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19025 alloc_info.pNext = NULL;
19026 alloc_info.memoryTypeIndex = 0;
19027
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019028 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019029 alloc_info.allocationSize = allocation_size;
19030
19031 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19032 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 -070019033 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019034 if (!pass) {
19035 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019036 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19037 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019038 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019039 pass = m_device->phy().set_memory_type(
19040 mem_reqs.memoryTypeBits, &alloc_info,
19041 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19042 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019043 if (!pass) {
19044 return;
19045 }
19046 }
19047 }
19048
19049 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19050 ASSERT_VK_SUCCESS(err);
19051
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019052 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019053 m_errorMonitor->ExpectSuccess();
19054 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19055 ASSERT_VK_SUCCESS(err);
19056 VkMappedMemoryRange mmr = {};
19057 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19058 mmr.memory = mem;
19059 mmr.offset = 0;
19060 mmr.size = VK_WHOLE_SIZE;
19061 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19062 ASSERT_VK_SUCCESS(err);
19063 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19064 ASSERT_VK_SUCCESS(err);
19065 m_errorMonitor->VerifyNotFound();
19066 vkUnmapMemory(m_device->device(), mem);
19067
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019068 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019069 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019070 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019071 ASSERT_VK_SUCCESS(err);
19072 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19073 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019074 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019075 mmr.size = VK_WHOLE_SIZE;
19076 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19077 ASSERT_VK_SUCCESS(err);
19078 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19079 ASSERT_VK_SUCCESS(err);
19080 m_errorMonitor->VerifyNotFound();
19081 vkUnmapMemory(m_device->device(), mem);
19082
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019083 // Map with offset and size
19084 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019085 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019086 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019087 ASSERT_VK_SUCCESS(err);
19088 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19089 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019090 mmr.offset = 4 * atom_size;
19091 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019092 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19093 ASSERT_VK_SUCCESS(err);
19094 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19095 ASSERT_VK_SUCCESS(err);
19096 m_errorMonitor->VerifyNotFound();
19097 vkUnmapMemory(m_device->device(), mem);
19098
19099 // Map without offset and flush WHOLE_SIZE with two separate offsets
19100 m_errorMonitor->ExpectSuccess();
19101 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19102 ASSERT_VK_SUCCESS(err);
19103 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19104 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019105 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019106 mmr.size = VK_WHOLE_SIZE;
19107 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19108 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019109 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019110 mmr.size = VK_WHOLE_SIZE;
19111 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19112 ASSERT_VK_SUCCESS(err);
19113 m_errorMonitor->VerifyNotFound();
19114 vkUnmapMemory(m_device->device(), mem);
19115
19116 vkFreeMemory(m_device->device(), mem, NULL);
19117}
19118
19119// This is a positive test. We used to expect error in this case but spec now allows it
19120TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19121 m_errorMonitor->ExpectSuccess();
19122 vk_testing::Fence testFence;
19123 VkFenceCreateInfo fenceInfo = {};
19124 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19125 fenceInfo.pNext = NULL;
19126
19127 ASSERT_NO_FATAL_FAILURE(InitState());
19128 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019129 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019130 VkResult result = vkResetFences(m_device->device(), 1, fences);
19131 ASSERT_VK_SUCCESS(result);
19132
19133 m_errorMonitor->VerifyNotFound();
19134}
19135
19136TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19137 m_errorMonitor->ExpectSuccess();
19138
19139 ASSERT_NO_FATAL_FAILURE(InitState());
19140 VkResult err;
19141
19142 // Record (empty!) command buffer that can be submitted multiple times
19143 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019144 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19145 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019146 m_commandBuffer->BeginCommandBuffer(&cbbi);
19147 m_commandBuffer->EndCommandBuffer();
19148
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019149 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019150 VkFence fence;
19151 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19152 ASSERT_VK_SUCCESS(err);
19153
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019154 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019155 VkSemaphore s1, s2;
19156 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19157 ASSERT_VK_SUCCESS(err);
19158 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19159 ASSERT_VK_SUCCESS(err);
19160
19161 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019162 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019163 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19164 ASSERT_VK_SUCCESS(err);
19165
19166 // Submit CB again, signaling s2.
19167 si.pSignalSemaphores = &s2;
19168 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19169 ASSERT_VK_SUCCESS(err);
19170
19171 // Wait for fence.
19172 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19173 ASSERT_VK_SUCCESS(err);
19174
19175 // CB is still in flight from second submission, but semaphore s1 is no
19176 // longer in flight. delete it.
19177 vkDestroySemaphore(m_device->device(), s1, nullptr);
19178
19179 m_errorMonitor->VerifyNotFound();
19180
19181 // Force device idle and clean up remaining objects
19182 vkDeviceWaitIdle(m_device->device());
19183 vkDestroySemaphore(m_device->device(), s2, nullptr);
19184 vkDestroyFence(m_device->device(), fence, nullptr);
19185}
19186
19187TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19188 m_errorMonitor->ExpectSuccess();
19189
19190 ASSERT_NO_FATAL_FAILURE(InitState());
19191 VkResult err;
19192
19193 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019194 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019195 VkFence f1;
19196 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19197 ASSERT_VK_SUCCESS(err);
19198
19199 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019200 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019201 VkFence f2;
19202 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19203 ASSERT_VK_SUCCESS(err);
19204
19205 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019206 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019207 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19208
19209 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019210 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019211 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19212
19213 // Should have both retired!
19214 vkDestroyFence(m_device->device(), f1, nullptr);
19215 vkDestroyFence(m_device->device(), f2, nullptr);
19216
19217 m_errorMonitor->VerifyNotFound();
19218}
19219
19220TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019221 TEST_DESCRIPTION(
19222 "Verify that creating an image view from an image with valid usage "
19223 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019224
19225 ASSERT_NO_FATAL_FAILURE(InitState());
19226
19227 m_errorMonitor->ExpectSuccess();
19228 // Verify that we can create a view with usage INPUT_ATTACHMENT
19229 VkImageObj image(m_device);
19230 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19231 ASSERT_TRUE(image.initialized());
19232 VkImageView imageView;
19233 VkImageViewCreateInfo ivci = {};
19234 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19235 ivci.image = image.handle();
19236 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19237 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19238 ivci.subresourceRange.layerCount = 1;
19239 ivci.subresourceRange.baseMipLevel = 0;
19240 ivci.subresourceRange.levelCount = 1;
19241 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19242
19243 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19244 m_errorMonitor->VerifyNotFound();
19245 vkDestroyImageView(m_device->device(), imageView, NULL);
19246}
19247
19248// This is a positive test. No failures are expected.
19249TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019250 TEST_DESCRIPTION(
19251 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19252 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019253
19254 ASSERT_NO_FATAL_FAILURE(InitState());
19255
19256 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019257 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019258
19259 m_errorMonitor->ExpectSuccess();
19260
19261 VkImage image;
19262 VkImageCreateInfo image_create_info = {};
19263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19264 image_create_info.pNext = NULL;
19265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19266 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19267 image_create_info.extent.width = 64;
19268 image_create_info.extent.height = 64;
19269 image_create_info.extent.depth = 1;
19270 image_create_info.mipLevels = 1;
19271 image_create_info.arrayLayers = 1;
19272 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19273 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19274 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19275 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19276 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19277 ASSERT_VK_SUCCESS(err);
19278
19279 VkMemoryRequirements memory_reqs;
19280 VkDeviceMemory memory_one, memory_two;
19281 bool pass;
19282 VkMemoryAllocateInfo memory_info = {};
19283 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19284 memory_info.pNext = NULL;
19285 memory_info.allocationSize = 0;
19286 memory_info.memoryTypeIndex = 0;
19287 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19288 // Find an image big enough to allow sparse mapping of 2 memory regions
19289 // Increase the image size until it is at least twice the
19290 // size of the required alignment, to ensure we can bind both
19291 // allocated memory blocks to the image on aligned offsets.
19292 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19293 vkDestroyImage(m_device->device(), image, nullptr);
19294 image_create_info.extent.width *= 2;
19295 image_create_info.extent.height *= 2;
19296 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19297 ASSERT_VK_SUCCESS(err);
19298 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19299 }
19300 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19301 // at the end of the first
19302 memory_info.allocationSize = memory_reqs.alignment;
19303 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19304 ASSERT_TRUE(pass);
19305 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19306 ASSERT_VK_SUCCESS(err);
19307 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19308 ASSERT_VK_SUCCESS(err);
19309 VkSparseMemoryBind binds[2];
19310 binds[0].flags = 0;
19311 binds[0].memory = memory_one;
19312 binds[0].memoryOffset = 0;
19313 binds[0].resourceOffset = 0;
19314 binds[0].size = memory_info.allocationSize;
19315 binds[1].flags = 0;
19316 binds[1].memory = memory_two;
19317 binds[1].memoryOffset = 0;
19318 binds[1].resourceOffset = memory_info.allocationSize;
19319 binds[1].size = memory_info.allocationSize;
19320
19321 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19322 opaqueBindInfo.image = image;
19323 opaqueBindInfo.bindCount = 2;
19324 opaqueBindInfo.pBinds = binds;
19325
19326 VkFence fence = VK_NULL_HANDLE;
19327 VkBindSparseInfo bindSparseInfo = {};
19328 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19329 bindSparseInfo.imageOpaqueBindCount = 1;
19330 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19331
19332 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19333 vkQueueWaitIdle(m_device->m_queue);
19334 vkDestroyImage(m_device->device(), image, NULL);
19335 vkFreeMemory(m_device->device(), memory_one, NULL);
19336 vkFreeMemory(m_device->device(), memory_two, NULL);
19337 m_errorMonitor->VerifyNotFound();
19338}
19339
19340TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019341 TEST_DESCRIPTION(
19342 "Ensure that CmdBeginRenderPass with an attachment's "
19343 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19344 "the command buffer has prior knowledge of that "
19345 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019346
19347 m_errorMonitor->ExpectSuccess();
19348
19349 ASSERT_NO_FATAL_FAILURE(InitState());
19350
19351 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019352 VkAttachmentDescription attachment = {0,
19353 VK_FORMAT_R8G8B8A8_UNORM,
19354 VK_SAMPLE_COUNT_1_BIT,
19355 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19356 VK_ATTACHMENT_STORE_OP_STORE,
19357 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19358 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19359 VK_IMAGE_LAYOUT_UNDEFINED,
19360 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019361
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019362 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019363
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019364 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019365
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019366 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019367
19368 VkRenderPass rp;
19369 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19370 ASSERT_VK_SUCCESS(err);
19371
19372 // A compatible framebuffer.
19373 VkImageObj image(m_device);
19374 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19375 ASSERT_TRUE(image.initialized());
19376
19377 VkImageViewCreateInfo ivci = {
19378 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19379 nullptr,
19380 0,
19381 image.handle(),
19382 VK_IMAGE_VIEW_TYPE_2D,
19383 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019384 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19385 VK_COMPONENT_SWIZZLE_IDENTITY},
19386 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019387 };
19388 VkImageView view;
19389 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19390 ASSERT_VK_SUCCESS(err);
19391
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019392 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019393 VkFramebuffer fb;
19394 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19395 ASSERT_VK_SUCCESS(err);
19396
19397 // Record a single command buffer which uses this renderpass twice. The
19398 // bug is triggered at the beginning of the second renderpass, when the
19399 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019400 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 -070019401 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019402 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19403 vkCmdEndRenderPass(m_commandBuffer->handle());
19404 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19405
19406 m_errorMonitor->VerifyNotFound();
19407
19408 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019409 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019410
19411 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19412 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19413 vkDestroyImageView(m_device->device(), view, nullptr);
19414}
19415
19416TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019417 TEST_DESCRIPTION(
19418 "This test should pass. Create a Framebuffer and "
19419 "command buffer, bind them together, then destroy "
19420 "command pool and framebuffer and verify there are no "
19421 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019422
19423 m_errorMonitor->ExpectSuccess();
19424
19425 ASSERT_NO_FATAL_FAILURE(InitState());
19426
19427 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019428 VkAttachmentDescription attachment = {0,
19429 VK_FORMAT_R8G8B8A8_UNORM,
19430 VK_SAMPLE_COUNT_1_BIT,
19431 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19432 VK_ATTACHMENT_STORE_OP_STORE,
19433 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19434 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19435 VK_IMAGE_LAYOUT_UNDEFINED,
19436 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019437
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019438 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019439
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019440 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019441
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019442 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019443
19444 VkRenderPass rp;
19445 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19446 ASSERT_VK_SUCCESS(err);
19447
19448 // A compatible framebuffer.
19449 VkImageObj image(m_device);
19450 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19451 ASSERT_TRUE(image.initialized());
19452
19453 VkImageViewCreateInfo ivci = {
19454 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19455 nullptr,
19456 0,
19457 image.handle(),
19458 VK_IMAGE_VIEW_TYPE_2D,
19459 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019460 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19461 VK_COMPONENT_SWIZZLE_IDENTITY},
19462 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019463 };
19464 VkImageView view;
19465 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19466 ASSERT_VK_SUCCESS(err);
19467
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019468 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019469 VkFramebuffer fb;
19470 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19471 ASSERT_VK_SUCCESS(err);
19472
19473 // Explicitly create a command buffer to bind the FB to so that we can then
19474 // destroy the command pool in order to implicitly free command buffer
19475 VkCommandPool command_pool;
19476 VkCommandPoolCreateInfo pool_create_info{};
19477 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19478 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19479 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19480 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19481
19482 VkCommandBuffer command_buffer;
19483 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19484 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19485 command_buffer_allocate_info.commandPool = command_pool;
19486 command_buffer_allocate_info.commandBufferCount = 1;
19487 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19488 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19489
19490 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019491 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 -060019492 VkCommandBufferBeginInfo begin_info{};
19493 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19494 vkBeginCommandBuffer(command_buffer, &begin_info);
19495
19496 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19497 vkCmdEndRenderPass(command_buffer);
19498 vkEndCommandBuffer(command_buffer);
19499 vkDestroyImageView(m_device->device(), view, nullptr);
19500 // Destroy command pool to implicitly free command buffer
19501 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19502 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19503 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19504 m_errorMonitor->VerifyNotFound();
19505}
19506
19507TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019508 TEST_DESCRIPTION(
19509 "Ensure that CmdBeginRenderPass applies the layout "
19510 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019511
19512 m_errorMonitor->ExpectSuccess();
19513
19514 ASSERT_NO_FATAL_FAILURE(InitState());
19515
19516 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019517 VkAttachmentDescription attachment = {0,
19518 VK_FORMAT_R8G8B8A8_UNORM,
19519 VK_SAMPLE_COUNT_1_BIT,
19520 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19521 VK_ATTACHMENT_STORE_OP_STORE,
19522 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19523 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19524 VK_IMAGE_LAYOUT_UNDEFINED,
19525 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019526
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019527 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019528
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019529 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019530
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019531 VkSubpassDependency dep = {0,
19532 0,
19533 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19534 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19535 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19536 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19537 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019538
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019539 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019540
19541 VkResult err;
19542 VkRenderPass rp;
19543 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19544 ASSERT_VK_SUCCESS(err);
19545
19546 // A compatible framebuffer.
19547 VkImageObj image(m_device);
19548 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19549 ASSERT_TRUE(image.initialized());
19550
19551 VkImageViewCreateInfo ivci = {
19552 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19553 nullptr,
19554 0,
19555 image.handle(),
19556 VK_IMAGE_VIEW_TYPE_2D,
19557 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019558 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19559 VK_COMPONENT_SWIZZLE_IDENTITY},
19560 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019561 };
19562 VkImageView view;
19563 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19564 ASSERT_VK_SUCCESS(err);
19565
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019566 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019567 VkFramebuffer fb;
19568 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19569 ASSERT_VK_SUCCESS(err);
19570
19571 // Record a single command buffer which issues a pipeline barrier w/
19572 // image memory barrier for the attachment. This detects the previously
19573 // missing tracking of the subpass layout by throwing a validation error
19574 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019575 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 -070019576 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019577 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19578
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019579 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19580 nullptr,
19581 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19582 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19583 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19584 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19585 VK_QUEUE_FAMILY_IGNORED,
19586 VK_QUEUE_FAMILY_IGNORED,
19587 image.handle(),
19588 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019589 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019590 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19591 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019592
19593 vkCmdEndRenderPass(m_commandBuffer->handle());
19594 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019595 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019596
19597 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19598 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19599 vkDestroyImageView(m_device->device(), view, nullptr);
19600}
19601
19602TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019603 TEST_DESCRIPTION(
19604 "Validate that when an imageView of a depth/stencil image "
19605 "is used as a depth/stencil framebuffer attachment, the "
19606 "aspectMask is ignored and both depth and stencil image "
19607 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019608
19609 VkFormatProperties format_properties;
19610 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19611 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19612 return;
19613 }
19614
19615 m_errorMonitor->ExpectSuccess();
19616
19617 ASSERT_NO_FATAL_FAILURE(InitState());
19618
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019619 VkAttachmentDescription attachment = {0,
19620 VK_FORMAT_D32_SFLOAT_S8_UINT,
19621 VK_SAMPLE_COUNT_1_BIT,
19622 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19623 VK_ATTACHMENT_STORE_OP_STORE,
19624 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19625 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19626 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19627 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019628
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019629 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019630
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019631 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019632
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019633 VkSubpassDependency dep = {0,
19634 0,
19635 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19636 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19637 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19638 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19639 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019640
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019641 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019642
19643 VkResult err;
19644 VkRenderPass rp;
19645 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19646 ASSERT_VK_SUCCESS(err);
19647
19648 VkImageObj image(m_device);
19649 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019650 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019651 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019652 ASSERT_TRUE(image.initialized());
19653 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19654
19655 VkImageViewCreateInfo ivci = {
19656 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19657 nullptr,
19658 0,
19659 image.handle(),
19660 VK_IMAGE_VIEW_TYPE_2D,
19661 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019662 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19663 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019664 };
19665 VkImageView view;
19666 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19667 ASSERT_VK_SUCCESS(err);
19668
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019669 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019670 VkFramebuffer fb;
19671 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19672 ASSERT_VK_SUCCESS(err);
19673
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019674 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 -070019675 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019676 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19677
19678 VkImageMemoryBarrier imb = {};
19679 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19680 imb.pNext = nullptr;
19681 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19682 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19683 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19684 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19685 imb.srcQueueFamilyIndex = 0;
19686 imb.dstQueueFamilyIndex = 0;
19687 imb.image = image.handle();
19688 imb.subresourceRange.aspectMask = 0x6;
19689 imb.subresourceRange.baseMipLevel = 0;
19690 imb.subresourceRange.levelCount = 0x1;
19691 imb.subresourceRange.baseArrayLayer = 0;
19692 imb.subresourceRange.layerCount = 0x1;
19693
19694 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019695 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19696 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019697
19698 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019699 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019700 QueueCommandBuffer(false);
19701 m_errorMonitor->VerifyNotFound();
19702
19703 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19704 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19705 vkDestroyImageView(m_device->device(), view, nullptr);
19706}
19707
19708TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019709 TEST_DESCRIPTION(
19710 "Ensure that layout transitions work correctly without "
19711 "errors, when an attachment reference is "
19712 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019713
19714 m_errorMonitor->ExpectSuccess();
19715
19716 ASSERT_NO_FATAL_FAILURE(InitState());
19717
19718 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019719 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019720
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019721 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019722
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019723 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019724
19725 VkRenderPass rp;
19726 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19727 ASSERT_VK_SUCCESS(err);
19728
19729 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019730 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019731 VkFramebuffer fb;
19732 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19733 ASSERT_VK_SUCCESS(err);
19734
19735 // Record a command buffer which just begins and ends the renderpass. The
19736 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019737 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 -070019738 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019739 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19740 vkCmdEndRenderPass(m_commandBuffer->handle());
19741 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019742 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019743
19744 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19745 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19746}
19747
19748// This is a positive test. No errors are expected.
19749TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019750 TEST_DESCRIPTION(
19751 "Create a stencil-only attachment with a LOAD_OP set to "
19752 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019753 VkResult result = VK_SUCCESS;
19754 VkImageFormatProperties formatProps;
19755 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019756 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19757 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019758 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19759 return;
19760 }
19761
19762 ASSERT_NO_FATAL_FAILURE(InitState());
19763 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19764 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019765 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019766 VkAttachmentDescription att = {};
19767 VkAttachmentReference ref = {};
19768 att.format = depth_stencil_fmt;
19769 att.samples = VK_SAMPLE_COUNT_1_BIT;
19770 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19771 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19772 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19773 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19774 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19775 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19776
19777 VkClearValue clear;
19778 clear.depthStencil.depth = 1.0;
19779 clear.depthStencil.stencil = 0;
19780 ref.attachment = 0;
19781 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19782
19783 VkSubpassDescription subpass = {};
19784 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19785 subpass.flags = 0;
19786 subpass.inputAttachmentCount = 0;
19787 subpass.pInputAttachments = NULL;
19788 subpass.colorAttachmentCount = 0;
19789 subpass.pColorAttachments = NULL;
19790 subpass.pResolveAttachments = NULL;
19791 subpass.pDepthStencilAttachment = &ref;
19792 subpass.preserveAttachmentCount = 0;
19793 subpass.pPreserveAttachments = NULL;
19794
19795 VkRenderPass rp;
19796 VkRenderPassCreateInfo rp_info = {};
19797 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19798 rp_info.attachmentCount = 1;
19799 rp_info.pAttachments = &att;
19800 rp_info.subpassCount = 1;
19801 rp_info.pSubpasses = &subpass;
19802 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19803 ASSERT_VK_SUCCESS(result);
19804
19805 VkImageView *depthView = m_depthStencil->BindInfo();
19806 VkFramebufferCreateInfo fb_info = {};
19807 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19808 fb_info.pNext = NULL;
19809 fb_info.renderPass = rp;
19810 fb_info.attachmentCount = 1;
19811 fb_info.pAttachments = depthView;
19812 fb_info.width = 100;
19813 fb_info.height = 100;
19814 fb_info.layers = 1;
19815 VkFramebuffer fb;
19816 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19817 ASSERT_VK_SUCCESS(result);
19818
19819 VkRenderPassBeginInfo rpbinfo = {};
19820 rpbinfo.clearValueCount = 1;
19821 rpbinfo.pClearValues = &clear;
19822 rpbinfo.pNext = NULL;
19823 rpbinfo.renderPass = rp;
19824 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19825 rpbinfo.renderArea.extent.width = 100;
19826 rpbinfo.renderArea.extent.height = 100;
19827 rpbinfo.renderArea.offset.x = 0;
19828 rpbinfo.renderArea.offset.y = 0;
19829 rpbinfo.framebuffer = fb;
19830
19831 VkFence fence = {};
19832 VkFenceCreateInfo fence_ci = {};
19833 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19834 fence_ci.pNext = nullptr;
19835 fence_ci.flags = 0;
19836 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19837 ASSERT_VK_SUCCESS(result);
19838
19839 m_commandBuffer->BeginCommandBuffer();
19840 m_commandBuffer->BeginRenderPass(rpbinfo);
19841 m_commandBuffer->EndRenderPass();
19842 m_commandBuffer->EndCommandBuffer();
19843 m_commandBuffer->QueueCommandBuffer(fence);
19844
19845 VkImageObj destImage(m_device);
19846 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 -070019847 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019848 VkImageMemoryBarrier barrier = {};
19849 VkImageSubresourceRange range;
19850 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19851 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19852 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19853 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19854 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19855 barrier.image = m_depthStencil->handle();
19856 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19857 range.baseMipLevel = 0;
19858 range.levelCount = 1;
19859 range.baseArrayLayer = 0;
19860 range.layerCount = 1;
19861 barrier.subresourceRange = range;
19862 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19863 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19864 cmdbuf.BeginCommandBuffer();
19865 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 -070019866 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019867 barrier.srcAccessMask = 0;
19868 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19869 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19870 barrier.image = destImage.handle();
19871 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19872 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 -070019873 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019874 VkImageCopy cregion;
19875 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19876 cregion.srcSubresource.mipLevel = 0;
19877 cregion.srcSubresource.baseArrayLayer = 0;
19878 cregion.srcSubresource.layerCount = 1;
19879 cregion.srcOffset.x = 0;
19880 cregion.srcOffset.y = 0;
19881 cregion.srcOffset.z = 0;
19882 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19883 cregion.dstSubresource.mipLevel = 0;
19884 cregion.dstSubresource.baseArrayLayer = 0;
19885 cregion.dstSubresource.layerCount = 1;
19886 cregion.dstOffset.x = 0;
19887 cregion.dstOffset.y = 0;
19888 cregion.dstOffset.z = 0;
19889 cregion.extent.width = 100;
19890 cregion.extent.height = 100;
19891 cregion.extent.depth = 1;
19892 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019893 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019894 cmdbuf.EndCommandBuffer();
19895
19896 VkSubmitInfo submit_info;
19897 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19898 submit_info.pNext = NULL;
19899 submit_info.waitSemaphoreCount = 0;
19900 submit_info.pWaitSemaphores = NULL;
19901 submit_info.pWaitDstStageMask = NULL;
19902 submit_info.commandBufferCount = 1;
19903 submit_info.pCommandBuffers = &cmdbuf.handle();
19904 submit_info.signalSemaphoreCount = 0;
19905 submit_info.pSignalSemaphores = NULL;
19906
19907 m_errorMonitor->ExpectSuccess();
19908 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19909 m_errorMonitor->VerifyNotFound();
19910
19911 vkQueueWaitIdle(m_device->m_queue);
19912 vkDestroyFence(m_device->device(), fence, nullptr);
19913 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19914 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19915}
19916
19917// This is a positive test. No errors should be generated.
19918TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19919 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19920
19921 m_errorMonitor->ExpectSuccess();
19922 ASSERT_NO_FATAL_FAILURE(InitState());
19923
19924 VkEvent event;
19925 VkEventCreateInfo event_create_info{};
19926 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19927 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19928
19929 VkCommandPool command_pool;
19930 VkCommandPoolCreateInfo pool_create_info{};
19931 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19932 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19933 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19934 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19935
19936 VkCommandBuffer command_buffer;
19937 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19938 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19939 command_buffer_allocate_info.commandPool = command_pool;
19940 command_buffer_allocate_info.commandBufferCount = 1;
19941 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19942 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19943
19944 VkQueue queue = VK_NULL_HANDLE;
19945 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19946
19947 {
19948 VkCommandBufferBeginInfo begin_info{};
19949 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19950 vkBeginCommandBuffer(command_buffer, &begin_info);
19951
19952 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 -070019953 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019954 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19955 vkEndCommandBuffer(command_buffer);
19956 }
19957 {
19958 VkSubmitInfo submit_info{};
19959 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19960 submit_info.commandBufferCount = 1;
19961 submit_info.pCommandBuffers = &command_buffer;
19962 submit_info.signalSemaphoreCount = 0;
19963 submit_info.pSignalSemaphores = nullptr;
19964 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19965 }
19966 { vkSetEvent(m_device->device(), event); }
19967
19968 vkQueueWaitIdle(queue);
19969
19970 vkDestroyEvent(m_device->device(), event, nullptr);
19971 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19972 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19973
19974 m_errorMonitor->VerifyNotFound();
19975}
19976// This is a positive test. No errors should be generated.
19977TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19978 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19979
19980 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019981 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019982
19983 m_errorMonitor->ExpectSuccess();
19984
19985 VkQueryPool query_pool;
19986 VkQueryPoolCreateInfo query_pool_create_info{};
19987 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19988 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19989 query_pool_create_info.queryCount = 1;
19990 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19991
19992 VkCommandPool command_pool;
19993 VkCommandPoolCreateInfo pool_create_info{};
19994 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19995 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19996 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19997 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19998
19999 VkCommandBuffer command_buffer;
20000 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20001 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20002 command_buffer_allocate_info.commandPool = command_pool;
20003 command_buffer_allocate_info.commandBufferCount = 1;
20004 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20005 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20006
20007 VkCommandBuffer secondary_command_buffer;
20008 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20009 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20010
20011 VkQueue queue = VK_NULL_HANDLE;
20012 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20013
20014 uint32_t qfi = 0;
20015 VkBufferCreateInfo buff_create_info = {};
20016 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20017 buff_create_info.size = 1024;
20018 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20019 buff_create_info.queueFamilyIndexCount = 1;
20020 buff_create_info.pQueueFamilyIndices = &qfi;
20021
20022 VkResult err;
20023 VkBuffer buffer;
20024 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20025 ASSERT_VK_SUCCESS(err);
20026 VkMemoryAllocateInfo mem_alloc = {};
20027 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20028 mem_alloc.pNext = NULL;
20029 mem_alloc.allocationSize = 1024;
20030 mem_alloc.memoryTypeIndex = 0;
20031
20032 VkMemoryRequirements memReqs;
20033 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20034 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20035 if (!pass) {
20036 vkDestroyBuffer(m_device->device(), buffer, NULL);
20037 return;
20038 }
20039
20040 VkDeviceMemory mem;
20041 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20042 ASSERT_VK_SUCCESS(err);
20043 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20044 ASSERT_VK_SUCCESS(err);
20045
20046 VkCommandBufferInheritanceInfo hinfo = {};
20047 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20048 hinfo.renderPass = VK_NULL_HANDLE;
20049 hinfo.subpass = 0;
20050 hinfo.framebuffer = VK_NULL_HANDLE;
20051 hinfo.occlusionQueryEnable = VK_FALSE;
20052 hinfo.queryFlags = 0;
20053 hinfo.pipelineStatistics = 0;
20054
20055 {
20056 VkCommandBufferBeginInfo begin_info{};
20057 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20058 begin_info.pInheritanceInfo = &hinfo;
20059 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20060
20061 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20062 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20063
20064 vkEndCommandBuffer(secondary_command_buffer);
20065
20066 begin_info.pInheritanceInfo = nullptr;
20067 vkBeginCommandBuffer(command_buffer, &begin_info);
20068
20069 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20070 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20071
20072 vkEndCommandBuffer(command_buffer);
20073 }
20074 {
20075 VkSubmitInfo submit_info{};
20076 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20077 submit_info.commandBufferCount = 1;
20078 submit_info.pCommandBuffers = &command_buffer;
20079 submit_info.signalSemaphoreCount = 0;
20080 submit_info.pSignalSemaphores = nullptr;
20081 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20082 }
20083
20084 vkQueueWaitIdle(queue);
20085
20086 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20087 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20088 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20089 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20090 vkDestroyBuffer(m_device->device(), buffer, NULL);
20091 vkFreeMemory(m_device->device(), mem, NULL);
20092
20093 m_errorMonitor->VerifyNotFound();
20094}
20095
20096// This is a positive test. No errors should be generated.
20097TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20098 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20099
20100 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020101 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020102
20103 m_errorMonitor->ExpectSuccess();
20104
20105 VkQueryPool query_pool;
20106 VkQueryPoolCreateInfo query_pool_create_info{};
20107 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20108 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20109 query_pool_create_info.queryCount = 1;
20110 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20111
20112 VkCommandPool command_pool;
20113 VkCommandPoolCreateInfo pool_create_info{};
20114 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20115 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20116 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20117 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20118
20119 VkCommandBuffer command_buffer[2];
20120 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20121 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20122 command_buffer_allocate_info.commandPool = command_pool;
20123 command_buffer_allocate_info.commandBufferCount = 2;
20124 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20125 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20126
20127 VkQueue queue = VK_NULL_HANDLE;
20128 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20129
20130 uint32_t qfi = 0;
20131 VkBufferCreateInfo buff_create_info = {};
20132 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20133 buff_create_info.size = 1024;
20134 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20135 buff_create_info.queueFamilyIndexCount = 1;
20136 buff_create_info.pQueueFamilyIndices = &qfi;
20137
20138 VkResult err;
20139 VkBuffer buffer;
20140 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20141 ASSERT_VK_SUCCESS(err);
20142 VkMemoryAllocateInfo mem_alloc = {};
20143 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20144 mem_alloc.pNext = NULL;
20145 mem_alloc.allocationSize = 1024;
20146 mem_alloc.memoryTypeIndex = 0;
20147
20148 VkMemoryRequirements memReqs;
20149 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20150 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20151 if (!pass) {
20152 vkDestroyBuffer(m_device->device(), buffer, NULL);
20153 return;
20154 }
20155
20156 VkDeviceMemory mem;
20157 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20158 ASSERT_VK_SUCCESS(err);
20159 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20160 ASSERT_VK_SUCCESS(err);
20161
20162 {
20163 VkCommandBufferBeginInfo begin_info{};
20164 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20165 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20166
20167 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20168 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20169
20170 vkEndCommandBuffer(command_buffer[0]);
20171
20172 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20173
20174 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20175
20176 vkEndCommandBuffer(command_buffer[1]);
20177 }
20178 {
20179 VkSubmitInfo submit_info{};
20180 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20181 submit_info.commandBufferCount = 2;
20182 submit_info.pCommandBuffers = command_buffer;
20183 submit_info.signalSemaphoreCount = 0;
20184 submit_info.pSignalSemaphores = nullptr;
20185 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20186 }
20187
20188 vkQueueWaitIdle(queue);
20189
20190 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20191 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20192 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20193 vkDestroyBuffer(m_device->device(), buffer, NULL);
20194 vkFreeMemory(m_device->device(), mem, NULL);
20195
20196 m_errorMonitor->VerifyNotFound();
20197}
20198
Tony Barbourc46924f2016-11-04 11:49:52 -060020199TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020200 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20201
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020202 ASSERT_NO_FATAL_FAILURE(InitState());
20203 VkEvent event;
20204 VkEventCreateInfo event_create_info{};
20205 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20206 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20207
20208 VkCommandPool command_pool;
20209 VkCommandPoolCreateInfo pool_create_info{};
20210 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20211 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20212 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20213 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20214
20215 VkCommandBuffer command_buffer;
20216 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20217 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20218 command_buffer_allocate_info.commandPool = command_pool;
20219 command_buffer_allocate_info.commandBufferCount = 1;
20220 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20221 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20222
20223 VkQueue queue = VK_NULL_HANDLE;
20224 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20225
20226 {
20227 VkCommandBufferBeginInfo begin_info{};
20228 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20229 vkBeginCommandBuffer(command_buffer, &begin_info);
20230
20231 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020232 vkEndCommandBuffer(command_buffer);
20233 }
20234 {
20235 VkSubmitInfo submit_info{};
20236 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20237 submit_info.commandBufferCount = 1;
20238 submit_info.pCommandBuffers = &command_buffer;
20239 submit_info.signalSemaphoreCount = 0;
20240 submit_info.pSignalSemaphores = nullptr;
20241 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20242 }
20243 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20245 "that is already in use by a "
20246 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020247 vkSetEvent(m_device->device(), event);
20248 m_errorMonitor->VerifyFound();
20249 }
20250
20251 vkQueueWaitIdle(queue);
20252
20253 vkDestroyEvent(m_device->device(), event, nullptr);
20254 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20255 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20256}
20257
20258// This is a positive test. No errors should be generated.
20259TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020260 TEST_DESCRIPTION(
20261 "Two command buffers with two separate fences are each "
20262 "run through a Submit & WaitForFences cycle 3 times. This "
20263 "previously revealed a bug so running this positive test "
20264 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020265 m_errorMonitor->ExpectSuccess();
20266
20267 ASSERT_NO_FATAL_FAILURE(InitState());
20268 VkQueue queue = VK_NULL_HANDLE;
20269 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20270
20271 static const uint32_t NUM_OBJECTS = 2;
20272 static const uint32_t NUM_FRAMES = 3;
20273 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20274 VkFence fences[NUM_OBJECTS] = {};
20275
20276 VkCommandPool cmd_pool;
20277 VkCommandPoolCreateInfo cmd_pool_ci = {};
20278 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20279 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20280 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20281 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20282 ASSERT_VK_SUCCESS(err);
20283
20284 VkCommandBufferAllocateInfo cmd_buf_info = {};
20285 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20286 cmd_buf_info.commandPool = cmd_pool;
20287 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20288 cmd_buf_info.commandBufferCount = 1;
20289
20290 VkFenceCreateInfo fence_ci = {};
20291 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20292 fence_ci.pNext = nullptr;
20293 fence_ci.flags = 0;
20294
20295 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20296 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20297 ASSERT_VK_SUCCESS(err);
20298 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20299 ASSERT_VK_SUCCESS(err);
20300 }
20301
20302 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20303 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20304 // Create empty cmd buffer
20305 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20306 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20307
20308 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20309 ASSERT_VK_SUCCESS(err);
20310 err = vkEndCommandBuffer(cmd_buffers[obj]);
20311 ASSERT_VK_SUCCESS(err);
20312
20313 VkSubmitInfo submit_info = {};
20314 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20315 submit_info.commandBufferCount = 1;
20316 submit_info.pCommandBuffers = &cmd_buffers[obj];
20317 // Submit cmd buffer and wait for fence
20318 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20319 ASSERT_VK_SUCCESS(err);
20320 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20321 ASSERT_VK_SUCCESS(err);
20322 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20323 ASSERT_VK_SUCCESS(err);
20324 }
20325 }
20326 m_errorMonitor->VerifyNotFound();
20327 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20328 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20329 vkDestroyFence(m_device->device(), fences[i], nullptr);
20330 }
20331}
20332// This is a positive test. No errors should be generated.
20333TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020334 TEST_DESCRIPTION(
20335 "Two command buffers, each in a separate QueueSubmit call "
20336 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020337
20338 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020339 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020340
20341 m_errorMonitor->ExpectSuccess();
20342
20343 VkSemaphore semaphore;
20344 VkSemaphoreCreateInfo semaphore_create_info{};
20345 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20346 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20347
20348 VkCommandPool command_pool;
20349 VkCommandPoolCreateInfo pool_create_info{};
20350 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20351 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20352 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20353 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20354
20355 VkCommandBuffer command_buffer[2];
20356 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20357 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20358 command_buffer_allocate_info.commandPool = command_pool;
20359 command_buffer_allocate_info.commandBufferCount = 2;
20360 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20361 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20362
20363 VkQueue queue = VK_NULL_HANDLE;
20364 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20365
20366 {
20367 VkCommandBufferBeginInfo begin_info{};
20368 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20369 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20370
20371 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 -070020372 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020373
20374 VkViewport viewport{};
20375 viewport.maxDepth = 1.0f;
20376 viewport.minDepth = 0.0f;
20377 viewport.width = 512;
20378 viewport.height = 512;
20379 viewport.x = 0;
20380 viewport.y = 0;
20381 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20382 vkEndCommandBuffer(command_buffer[0]);
20383 }
20384 {
20385 VkCommandBufferBeginInfo begin_info{};
20386 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20387 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20388
20389 VkViewport viewport{};
20390 viewport.maxDepth = 1.0f;
20391 viewport.minDepth = 0.0f;
20392 viewport.width = 512;
20393 viewport.height = 512;
20394 viewport.x = 0;
20395 viewport.y = 0;
20396 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20397 vkEndCommandBuffer(command_buffer[1]);
20398 }
20399 {
20400 VkSubmitInfo submit_info{};
20401 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20402 submit_info.commandBufferCount = 1;
20403 submit_info.pCommandBuffers = &command_buffer[0];
20404 submit_info.signalSemaphoreCount = 1;
20405 submit_info.pSignalSemaphores = &semaphore;
20406 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20407 }
20408 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020409 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020410 VkSubmitInfo submit_info{};
20411 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20412 submit_info.commandBufferCount = 1;
20413 submit_info.pCommandBuffers = &command_buffer[1];
20414 submit_info.waitSemaphoreCount = 1;
20415 submit_info.pWaitSemaphores = &semaphore;
20416 submit_info.pWaitDstStageMask = flags;
20417 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20418 }
20419
20420 vkQueueWaitIdle(m_device->m_queue);
20421
20422 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20423 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20424 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20425
20426 m_errorMonitor->VerifyNotFound();
20427}
20428
20429// This is a positive test. No errors should be generated.
20430TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020431 TEST_DESCRIPTION(
20432 "Two command buffers, each in a separate QueueSubmit call "
20433 "submitted on separate queues, the second having a fence"
20434 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020435
20436 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020437 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020438
20439 m_errorMonitor->ExpectSuccess();
20440
20441 VkFence fence;
20442 VkFenceCreateInfo fence_create_info{};
20443 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20444 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20445
20446 VkSemaphore semaphore;
20447 VkSemaphoreCreateInfo semaphore_create_info{};
20448 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20449 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20450
20451 VkCommandPool command_pool;
20452 VkCommandPoolCreateInfo pool_create_info{};
20453 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20454 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20455 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20456 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20457
20458 VkCommandBuffer command_buffer[2];
20459 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20460 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20461 command_buffer_allocate_info.commandPool = command_pool;
20462 command_buffer_allocate_info.commandBufferCount = 2;
20463 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20464 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20465
20466 VkQueue queue = VK_NULL_HANDLE;
20467 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20468
20469 {
20470 VkCommandBufferBeginInfo begin_info{};
20471 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20472 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20473
20474 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 -070020475 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020476
20477 VkViewport viewport{};
20478 viewport.maxDepth = 1.0f;
20479 viewport.minDepth = 0.0f;
20480 viewport.width = 512;
20481 viewport.height = 512;
20482 viewport.x = 0;
20483 viewport.y = 0;
20484 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20485 vkEndCommandBuffer(command_buffer[0]);
20486 }
20487 {
20488 VkCommandBufferBeginInfo begin_info{};
20489 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20490 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20491
20492 VkViewport viewport{};
20493 viewport.maxDepth = 1.0f;
20494 viewport.minDepth = 0.0f;
20495 viewport.width = 512;
20496 viewport.height = 512;
20497 viewport.x = 0;
20498 viewport.y = 0;
20499 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20500 vkEndCommandBuffer(command_buffer[1]);
20501 }
20502 {
20503 VkSubmitInfo submit_info{};
20504 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20505 submit_info.commandBufferCount = 1;
20506 submit_info.pCommandBuffers = &command_buffer[0];
20507 submit_info.signalSemaphoreCount = 1;
20508 submit_info.pSignalSemaphores = &semaphore;
20509 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20510 }
20511 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020512 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020513 VkSubmitInfo submit_info{};
20514 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20515 submit_info.commandBufferCount = 1;
20516 submit_info.pCommandBuffers = &command_buffer[1];
20517 submit_info.waitSemaphoreCount = 1;
20518 submit_info.pWaitSemaphores = &semaphore;
20519 submit_info.pWaitDstStageMask = flags;
20520 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20521 }
20522
20523 vkQueueWaitIdle(m_device->m_queue);
20524
20525 vkDestroyFence(m_device->device(), fence, nullptr);
20526 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20527 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20528 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20529
20530 m_errorMonitor->VerifyNotFound();
20531}
20532
20533// This is a positive test. No errors should be generated.
20534TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020535 TEST_DESCRIPTION(
20536 "Two command buffers, each in a separate QueueSubmit call "
20537 "submitted on separate queues, the second having a fence"
20538 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020539
20540 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020541 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020542
20543 m_errorMonitor->ExpectSuccess();
20544
20545 VkFence fence;
20546 VkFenceCreateInfo fence_create_info{};
20547 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20548 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20549
20550 VkSemaphore semaphore;
20551 VkSemaphoreCreateInfo semaphore_create_info{};
20552 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20553 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20554
20555 VkCommandPool command_pool;
20556 VkCommandPoolCreateInfo pool_create_info{};
20557 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20558 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20559 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20560 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20561
20562 VkCommandBuffer command_buffer[2];
20563 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20564 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20565 command_buffer_allocate_info.commandPool = command_pool;
20566 command_buffer_allocate_info.commandBufferCount = 2;
20567 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20568 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20569
20570 VkQueue queue = VK_NULL_HANDLE;
20571 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20572
20573 {
20574 VkCommandBufferBeginInfo begin_info{};
20575 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20576 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20577
20578 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 -070020579 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020580
20581 VkViewport viewport{};
20582 viewport.maxDepth = 1.0f;
20583 viewport.minDepth = 0.0f;
20584 viewport.width = 512;
20585 viewport.height = 512;
20586 viewport.x = 0;
20587 viewport.y = 0;
20588 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20589 vkEndCommandBuffer(command_buffer[0]);
20590 }
20591 {
20592 VkCommandBufferBeginInfo begin_info{};
20593 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20594 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20595
20596 VkViewport viewport{};
20597 viewport.maxDepth = 1.0f;
20598 viewport.minDepth = 0.0f;
20599 viewport.width = 512;
20600 viewport.height = 512;
20601 viewport.x = 0;
20602 viewport.y = 0;
20603 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20604 vkEndCommandBuffer(command_buffer[1]);
20605 }
20606 {
20607 VkSubmitInfo submit_info{};
20608 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20609 submit_info.commandBufferCount = 1;
20610 submit_info.pCommandBuffers = &command_buffer[0];
20611 submit_info.signalSemaphoreCount = 1;
20612 submit_info.pSignalSemaphores = &semaphore;
20613 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20614 }
20615 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020616 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020617 VkSubmitInfo submit_info{};
20618 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20619 submit_info.commandBufferCount = 1;
20620 submit_info.pCommandBuffers = &command_buffer[1];
20621 submit_info.waitSemaphoreCount = 1;
20622 submit_info.pWaitSemaphores = &semaphore;
20623 submit_info.pWaitDstStageMask = flags;
20624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20625 }
20626
20627 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20628 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20629
20630 vkDestroyFence(m_device->device(), fence, nullptr);
20631 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20632 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20633 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20634
20635 m_errorMonitor->VerifyNotFound();
20636}
20637
20638TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020639 ASSERT_NO_FATAL_FAILURE(InitState());
20640 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020641 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020642 return;
20643 }
20644
20645 VkResult err;
20646
20647 m_errorMonitor->ExpectSuccess();
20648
20649 VkQueue q0 = m_device->m_queue;
20650 VkQueue q1 = nullptr;
20651 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20652 ASSERT_NE(q1, nullptr);
20653
20654 // An (empty) command buffer. We must have work in the first submission --
20655 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020656 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020657 VkCommandPool pool;
20658 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20659 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020660 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20661 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020662 VkCommandBuffer cb;
20663 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20664 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020665 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020666 err = vkBeginCommandBuffer(cb, &cbbi);
20667 ASSERT_VK_SUCCESS(err);
20668 err = vkEndCommandBuffer(cb);
20669 ASSERT_VK_SUCCESS(err);
20670
20671 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020672 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020673 VkSemaphore s;
20674 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20675 ASSERT_VK_SUCCESS(err);
20676
20677 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020678 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020679
20680 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20681 ASSERT_VK_SUCCESS(err);
20682
20683 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020684 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020685 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020686
20687 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20688 ASSERT_VK_SUCCESS(err);
20689
20690 // Wait for q0 idle
20691 err = vkQueueWaitIdle(q0);
20692 ASSERT_VK_SUCCESS(err);
20693
20694 // Command buffer should have been completed (it was on q0); reset the pool.
20695 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20696
20697 m_errorMonitor->VerifyNotFound();
20698
20699 // Force device completely idle and clean up resources
20700 vkDeviceWaitIdle(m_device->device());
20701 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20702 vkDestroySemaphore(m_device->device(), s, nullptr);
20703}
20704
20705// This is a positive test. No errors should be generated.
20706TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020707 TEST_DESCRIPTION(
20708 "Two command buffers, each in a separate QueueSubmit call "
20709 "submitted on separate queues, the second having a fence, "
20710 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020711
20712 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020713 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020714
20715 m_errorMonitor->ExpectSuccess();
20716
20717 ASSERT_NO_FATAL_FAILURE(InitState());
20718 VkFence fence;
20719 VkFenceCreateInfo fence_create_info{};
20720 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20721 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20722
20723 VkSemaphore semaphore;
20724 VkSemaphoreCreateInfo semaphore_create_info{};
20725 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20726 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20727
20728 VkCommandPool command_pool;
20729 VkCommandPoolCreateInfo pool_create_info{};
20730 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20731 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20732 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20733 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20734
20735 VkCommandBuffer command_buffer[2];
20736 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20737 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20738 command_buffer_allocate_info.commandPool = command_pool;
20739 command_buffer_allocate_info.commandBufferCount = 2;
20740 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20741 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20742
20743 VkQueue queue = VK_NULL_HANDLE;
20744 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20745
20746 {
20747 VkCommandBufferBeginInfo begin_info{};
20748 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20749 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20750
20751 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 -070020752 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020753
20754 VkViewport viewport{};
20755 viewport.maxDepth = 1.0f;
20756 viewport.minDepth = 0.0f;
20757 viewport.width = 512;
20758 viewport.height = 512;
20759 viewport.x = 0;
20760 viewport.y = 0;
20761 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20762 vkEndCommandBuffer(command_buffer[0]);
20763 }
20764 {
20765 VkCommandBufferBeginInfo begin_info{};
20766 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20767 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20768
20769 VkViewport viewport{};
20770 viewport.maxDepth = 1.0f;
20771 viewport.minDepth = 0.0f;
20772 viewport.width = 512;
20773 viewport.height = 512;
20774 viewport.x = 0;
20775 viewport.y = 0;
20776 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20777 vkEndCommandBuffer(command_buffer[1]);
20778 }
20779 {
20780 VkSubmitInfo submit_info{};
20781 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20782 submit_info.commandBufferCount = 1;
20783 submit_info.pCommandBuffers = &command_buffer[0];
20784 submit_info.signalSemaphoreCount = 1;
20785 submit_info.pSignalSemaphores = &semaphore;
20786 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20787 }
20788 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020789 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020790 VkSubmitInfo submit_info{};
20791 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20792 submit_info.commandBufferCount = 1;
20793 submit_info.pCommandBuffers = &command_buffer[1];
20794 submit_info.waitSemaphoreCount = 1;
20795 submit_info.pWaitSemaphores = &semaphore;
20796 submit_info.pWaitDstStageMask = flags;
20797 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20798 }
20799
20800 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20801
20802 vkDestroyFence(m_device->device(), fence, nullptr);
20803 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20804 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20805 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20806
20807 m_errorMonitor->VerifyNotFound();
20808}
20809
20810// This is a positive test. No errors should be generated.
20811TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020812 TEST_DESCRIPTION(
20813 "Two command buffers, each in a separate QueueSubmit call "
20814 "on the same queue, sharing a signal/wait semaphore, the "
20815 "second having a fence, "
20816 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020817
20818 m_errorMonitor->ExpectSuccess();
20819
20820 ASSERT_NO_FATAL_FAILURE(InitState());
20821 VkFence fence;
20822 VkFenceCreateInfo fence_create_info{};
20823 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20824 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20825
20826 VkSemaphore semaphore;
20827 VkSemaphoreCreateInfo semaphore_create_info{};
20828 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20829 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20830
20831 VkCommandPool command_pool;
20832 VkCommandPoolCreateInfo pool_create_info{};
20833 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20834 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20835 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20836 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20837
20838 VkCommandBuffer command_buffer[2];
20839 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20840 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20841 command_buffer_allocate_info.commandPool = command_pool;
20842 command_buffer_allocate_info.commandBufferCount = 2;
20843 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20844 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20845
20846 {
20847 VkCommandBufferBeginInfo begin_info{};
20848 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20849 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20850
20851 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 -070020852 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020853
20854 VkViewport viewport{};
20855 viewport.maxDepth = 1.0f;
20856 viewport.minDepth = 0.0f;
20857 viewport.width = 512;
20858 viewport.height = 512;
20859 viewport.x = 0;
20860 viewport.y = 0;
20861 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20862 vkEndCommandBuffer(command_buffer[0]);
20863 }
20864 {
20865 VkCommandBufferBeginInfo begin_info{};
20866 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20867 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20868
20869 VkViewport viewport{};
20870 viewport.maxDepth = 1.0f;
20871 viewport.minDepth = 0.0f;
20872 viewport.width = 512;
20873 viewport.height = 512;
20874 viewport.x = 0;
20875 viewport.y = 0;
20876 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20877 vkEndCommandBuffer(command_buffer[1]);
20878 }
20879 {
20880 VkSubmitInfo submit_info{};
20881 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20882 submit_info.commandBufferCount = 1;
20883 submit_info.pCommandBuffers = &command_buffer[0];
20884 submit_info.signalSemaphoreCount = 1;
20885 submit_info.pSignalSemaphores = &semaphore;
20886 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20887 }
20888 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020889 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020890 VkSubmitInfo submit_info{};
20891 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20892 submit_info.commandBufferCount = 1;
20893 submit_info.pCommandBuffers = &command_buffer[1];
20894 submit_info.waitSemaphoreCount = 1;
20895 submit_info.pWaitSemaphores = &semaphore;
20896 submit_info.pWaitDstStageMask = flags;
20897 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20898 }
20899
20900 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20901
20902 vkDestroyFence(m_device->device(), fence, nullptr);
20903 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20904 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20905 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20906
20907 m_errorMonitor->VerifyNotFound();
20908}
20909
20910// This is a positive test. No errors should be generated.
20911TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020912 TEST_DESCRIPTION(
20913 "Two command buffers, each in a separate QueueSubmit call "
20914 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20915 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020916
20917 m_errorMonitor->ExpectSuccess();
20918
20919 ASSERT_NO_FATAL_FAILURE(InitState());
20920 VkFence fence;
20921 VkFenceCreateInfo fence_create_info{};
20922 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20923 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20924
20925 VkCommandPool command_pool;
20926 VkCommandPoolCreateInfo pool_create_info{};
20927 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20928 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20929 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20930 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20931
20932 VkCommandBuffer command_buffer[2];
20933 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20934 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20935 command_buffer_allocate_info.commandPool = command_pool;
20936 command_buffer_allocate_info.commandBufferCount = 2;
20937 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20938 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20939
20940 {
20941 VkCommandBufferBeginInfo begin_info{};
20942 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20943 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20944
20945 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 -070020946 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020947
20948 VkViewport viewport{};
20949 viewport.maxDepth = 1.0f;
20950 viewport.minDepth = 0.0f;
20951 viewport.width = 512;
20952 viewport.height = 512;
20953 viewport.x = 0;
20954 viewport.y = 0;
20955 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20956 vkEndCommandBuffer(command_buffer[0]);
20957 }
20958 {
20959 VkCommandBufferBeginInfo begin_info{};
20960 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20961 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20962
20963 VkViewport viewport{};
20964 viewport.maxDepth = 1.0f;
20965 viewport.minDepth = 0.0f;
20966 viewport.width = 512;
20967 viewport.height = 512;
20968 viewport.x = 0;
20969 viewport.y = 0;
20970 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20971 vkEndCommandBuffer(command_buffer[1]);
20972 }
20973 {
20974 VkSubmitInfo submit_info{};
20975 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20976 submit_info.commandBufferCount = 1;
20977 submit_info.pCommandBuffers = &command_buffer[0];
20978 submit_info.signalSemaphoreCount = 0;
20979 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20980 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20981 }
20982 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020983 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020984 VkSubmitInfo submit_info{};
20985 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20986 submit_info.commandBufferCount = 1;
20987 submit_info.pCommandBuffers = &command_buffer[1];
20988 submit_info.waitSemaphoreCount = 0;
20989 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20990 submit_info.pWaitDstStageMask = flags;
20991 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20992 }
20993
20994 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20995
20996 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20997 ASSERT_VK_SUCCESS(err);
20998
20999 vkDestroyFence(m_device->device(), fence, nullptr);
21000 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21001 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21002
21003 m_errorMonitor->VerifyNotFound();
21004}
21005
21006// This is a positive test. No errors should be generated.
21007TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021008 TEST_DESCRIPTION(
21009 "Two command buffers, each in a separate QueueSubmit call "
21010 "on the same queue, the second having a fence, followed "
21011 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021012
21013 m_errorMonitor->ExpectSuccess();
21014
21015 ASSERT_NO_FATAL_FAILURE(InitState());
21016 VkFence fence;
21017 VkFenceCreateInfo fence_create_info{};
21018 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21019 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21020
21021 VkCommandPool command_pool;
21022 VkCommandPoolCreateInfo pool_create_info{};
21023 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21024 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21025 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21026 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21027
21028 VkCommandBuffer command_buffer[2];
21029 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21030 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21031 command_buffer_allocate_info.commandPool = command_pool;
21032 command_buffer_allocate_info.commandBufferCount = 2;
21033 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21034 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21035
21036 {
21037 VkCommandBufferBeginInfo begin_info{};
21038 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21039 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21040
21041 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 -070021042 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021043
21044 VkViewport viewport{};
21045 viewport.maxDepth = 1.0f;
21046 viewport.minDepth = 0.0f;
21047 viewport.width = 512;
21048 viewport.height = 512;
21049 viewport.x = 0;
21050 viewport.y = 0;
21051 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21052 vkEndCommandBuffer(command_buffer[0]);
21053 }
21054 {
21055 VkCommandBufferBeginInfo begin_info{};
21056 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21057 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21058
21059 VkViewport viewport{};
21060 viewport.maxDepth = 1.0f;
21061 viewport.minDepth = 0.0f;
21062 viewport.width = 512;
21063 viewport.height = 512;
21064 viewport.x = 0;
21065 viewport.y = 0;
21066 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21067 vkEndCommandBuffer(command_buffer[1]);
21068 }
21069 {
21070 VkSubmitInfo submit_info{};
21071 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21072 submit_info.commandBufferCount = 1;
21073 submit_info.pCommandBuffers = &command_buffer[0];
21074 submit_info.signalSemaphoreCount = 0;
21075 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21076 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21077 }
21078 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021079 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021080 VkSubmitInfo submit_info{};
21081 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21082 submit_info.commandBufferCount = 1;
21083 submit_info.pCommandBuffers = &command_buffer[1];
21084 submit_info.waitSemaphoreCount = 0;
21085 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21086 submit_info.pWaitDstStageMask = flags;
21087 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21088 }
21089
21090 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21091
21092 vkDestroyFence(m_device->device(), fence, nullptr);
21093 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21094 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21095
21096 m_errorMonitor->VerifyNotFound();
21097}
21098
21099// This is a positive test. No errors should be generated.
21100TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021101 TEST_DESCRIPTION(
21102 "Two command buffers each in a separate SubmitInfo sent in a single "
21103 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021104 ASSERT_NO_FATAL_FAILURE(InitState());
21105
21106 m_errorMonitor->ExpectSuccess();
21107
21108 VkFence fence;
21109 VkFenceCreateInfo fence_create_info{};
21110 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21111 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21112
21113 VkSemaphore semaphore;
21114 VkSemaphoreCreateInfo semaphore_create_info{};
21115 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21116 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21117
21118 VkCommandPool command_pool;
21119 VkCommandPoolCreateInfo pool_create_info{};
21120 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21121 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21122 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21123 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21124
21125 VkCommandBuffer command_buffer[2];
21126 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21127 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21128 command_buffer_allocate_info.commandPool = command_pool;
21129 command_buffer_allocate_info.commandBufferCount = 2;
21130 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21131 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21132
21133 {
21134 VkCommandBufferBeginInfo begin_info{};
21135 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21136 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21137
21138 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 -070021139 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021140
21141 VkViewport viewport{};
21142 viewport.maxDepth = 1.0f;
21143 viewport.minDepth = 0.0f;
21144 viewport.width = 512;
21145 viewport.height = 512;
21146 viewport.x = 0;
21147 viewport.y = 0;
21148 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21149 vkEndCommandBuffer(command_buffer[0]);
21150 }
21151 {
21152 VkCommandBufferBeginInfo begin_info{};
21153 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21154 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21155
21156 VkViewport viewport{};
21157 viewport.maxDepth = 1.0f;
21158 viewport.minDepth = 0.0f;
21159 viewport.width = 512;
21160 viewport.height = 512;
21161 viewport.x = 0;
21162 viewport.y = 0;
21163 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21164 vkEndCommandBuffer(command_buffer[1]);
21165 }
21166 {
21167 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021168 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021169
21170 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21171 submit_info[0].pNext = NULL;
21172 submit_info[0].commandBufferCount = 1;
21173 submit_info[0].pCommandBuffers = &command_buffer[0];
21174 submit_info[0].signalSemaphoreCount = 1;
21175 submit_info[0].pSignalSemaphores = &semaphore;
21176 submit_info[0].waitSemaphoreCount = 0;
21177 submit_info[0].pWaitSemaphores = NULL;
21178 submit_info[0].pWaitDstStageMask = 0;
21179
21180 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21181 submit_info[1].pNext = NULL;
21182 submit_info[1].commandBufferCount = 1;
21183 submit_info[1].pCommandBuffers = &command_buffer[1];
21184 submit_info[1].waitSemaphoreCount = 1;
21185 submit_info[1].pWaitSemaphores = &semaphore;
21186 submit_info[1].pWaitDstStageMask = flags;
21187 submit_info[1].signalSemaphoreCount = 0;
21188 submit_info[1].pSignalSemaphores = NULL;
21189 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21190 }
21191
21192 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21193
21194 vkDestroyFence(m_device->device(), fence, nullptr);
21195 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21196 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21197 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21198
21199 m_errorMonitor->VerifyNotFound();
21200}
21201
21202TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21203 m_errorMonitor->ExpectSuccess();
21204
21205 ASSERT_NO_FATAL_FAILURE(InitState());
21206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21207
Tony Barbour552f6c02016-12-21 14:34:07 -070021208 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021209
21210 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21211 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21212 m_errorMonitor->VerifyNotFound();
21213 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21214 m_errorMonitor->VerifyNotFound();
21215 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21216 m_errorMonitor->VerifyNotFound();
21217
21218 m_commandBuffer->EndCommandBuffer();
21219 m_errorMonitor->VerifyNotFound();
21220}
21221
21222TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021223 TEST_DESCRIPTION(
21224 "Positive test where we create a renderpass with an "
21225 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21226 "has a valid layout, and a second subpass then uses a "
21227 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021228 m_errorMonitor->ExpectSuccess();
21229 ASSERT_NO_FATAL_FAILURE(InitState());
21230
21231 VkAttachmentReference attach[2] = {};
21232 attach[0].attachment = 0;
21233 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21234 attach[1].attachment = 0;
21235 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21236 VkSubpassDescription subpasses[2] = {};
21237 // First subpass clears DS attach on load
21238 subpasses[0].pDepthStencilAttachment = &attach[0];
21239 // 2nd subpass reads in DS as input attachment
21240 subpasses[1].inputAttachmentCount = 1;
21241 subpasses[1].pInputAttachments = &attach[1];
21242 VkAttachmentDescription attach_desc = {};
21243 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
21244 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21245 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21246 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21247 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21248 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21249 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21250 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21251 VkRenderPassCreateInfo rpci = {};
21252 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21253 rpci.attachmentCount = 1;
21254 rpci.pAttachments = &attach_desc;
21255 rpci.subpassCount = 2;
21256 rpci.pSubpasses = subpasses;
21257
21258 // Now create RenderPass and verify no errors
21259 VkRenderPass rp;
21260 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21261 m_errorMonitor->VerifyNotFound();
21262
21263 vkDestroyRenderPass(m_device->device(), rp, NULL);
21264}
21265
Tobin Ehlis01103de2017-02-16 13:22:47 -070021266TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21267 TEST_DESCRIPTION(
21268 "Create a render pass with depth-stencil attachment where layout transition "
21269 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21270 "transition has correctly occurred at queue submit time with no validation errors.");
21271
21272 VkFormat ds_format = VK_FORMAT_D24_UNORM_S8_UINT;
21273 VkImageFormatProperties format_props;
21274 vkGetPhysicalDeviceImageFormatProperties(gpu(), ds_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
21275 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21276 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
21277 printf("DS format VK_FORMAT_D24_UNORM_S8_UINT not supported, RenderPassDepthStencilLayoutTransition skipped.\n");
21278 return;
21279 }
21280
21281 m_errorMonitor->ExpectSuccess();
21282 ASSERT_NO_FATAL_FAILURE(InitState());
21283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21284
21285 // A renderpass with one depth/stencil attachment.
21286 VkAttachmentDescription attachment = {0,
21287 ds_format,
21288 VK_SAMPLE_COUNT_1_BIT,
21289 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21290 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21291 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21292 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21293 VK_IMAGE_LAYOUT_UNDEFINED,
21294 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21295
21296 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21297
21298 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21299
21300 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21301
21302 VkRenderPass rp;
21303 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21304 ASSERT_VK_SUCCESS(err);
21305 // A compatible ds image.
21306 VkImageObj image(m_device);
21307 image.init(32, 32, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
21308 ASSERT_TRUE(image.initialized());
21309
21310 VkImageViewCreateInfo ivci = {
21311 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21312 nullptr,
21313 0,
21314 image.handle(),
21315 VK_IMAGE_VIEW_TYPE_2D,
21316 ds_format,
21317 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21318 VK_COMPONENT_SWIZZLE_IDENTITY},
21319 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21320 };
21321 VkImageView view;
21322 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21323 ASSERT_VK_SUCCESS(err);
21324
21325 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21326 VkFramebuffer fb;
21327 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21328 ASSERT_VK_SUCCESS(err);
21329
21330 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21331 m_commandBuffer->BeginCommandBuffer();
21332 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21333 vkCmdEndRenderPass(m_commandBuffer->handle());
21334 m_commandBuffer->EndCommandBuffer();
21335 QueueCommandBuffer(false);
21336 m_errorMonitor->VerifyNotFound();
21337
21338 // Cleanup
21339 vkDestroyImageView(m_device->device(), view, NULL);
21340 vkDestroyRenderPass(m_device->device(), rp, NULL);
21341 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21342}
21343
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021344TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021345 TEST_DESCRIPTION(
21346 "Test that pipeline validation accepts matrices passed "
21347 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021348 m_errorMonitor->ExpectSuccess();
21349
21350 ASSERT_NO_FATAL_FAILURE(InitState());
21351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21352
21353 VkVertexInputBindingDescription input_binding;
21354 memset(&input_binding, 0, sizeof(input_binding));
21355
21356 VkVertexInputAttributeDescription input_attribs[2];
21357 memset(input_attribs, 0, sizeof(input_attribs));
21358
21359 for (int i = 0; i < 2; i++) {
21360 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21361 input_attribs[i].location = i;
21362 }
21363
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021364 char const *vsSource =
21365 "#version 450\n"
21366 "\n"
21367 "layout(location=0) in mat2x4 x;\n"
21368 "out gl_PerVertex {\n"
21369 " vec4 gl_Position;\n"
21370 "};\n"
21371 "void main(){\n"
21372 " gl_Position = x[0] + x[1];\n"
21373 "}\n";
21374 char const *fsSource =
21375 "#version 450\n"
21376 "\n"
21377 "layout(location=0) out vec4 color;\n"
21378 "void main(){\n"
21379 " color = vec4(1);\n"
21380 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021381
21382 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21383 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21384
21385 VkPipelineObj pipe(m_device);
21386 pipe.AddColorAttachment();
21387 pipe.AddShader(&vs);
21388 pipe.AddShader(&fs);
21389
21390 pipe.AddVertexInputBindings(&input_binding, 1);
21391 pipe.AddVertexInputAttribs(input_attribs, 2);
21392
21393 VkDescriptorSetObj descriptorSet(m_device);
21394 descriptorSet.AppendDummy();
21395 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21396
21397 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21398
21399 /* expect success */
21400 m_errorMonitor->VerifyNotFound();
21401}
21402
21403TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21404 m_errorMonitor->ExpectSuccess();
21405
21406 ASSERT_NO_FATAL_FAILURE(InitState());
21407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21408
21409 VkVertexInputBindingDescription input_binding;
21410 memset(&input_binding, 0, sizeof(input_binding));
21411
21412 VkVertexInputAttributeDescription input_attribs[2];
21413 memset(input_attribs, 0, sizeof(input_attribs));
21414
21415 for (int i = 0; i < 2; i++) {
21416 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21417 input_attribs[i].location = i;
21418 }
21419
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021420 char const *vsSource =
21421 "#version 450\n"
21422 "\n"
21423 "layout(location=0) in vec4 x[2];\n"
21424 "out gl_PerVertex {\n"
21425 " vec4 gl_Position;\n"
21426 "};\n"
21427 "void main(){\n"
21428 " gl_Position = x[0] + x[1];\n"
21429 "}\n";
21430 char const *fsSource =
21431 "#version 450\n"
21432 "\n"
21433 "layout(location=0) out vec4 color;\n"
21434 "void main(){\n"
21435 " color = vec4(1);\n"
21436 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021437
21438 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21439 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21440
21441 VkPipelineObj pipe(m_device);
21442 pipe.AddColorAttachment();
21443 pipe.AddShader(&vs);
21444 pipe.AddShader(&fs);
21445
21446 pipe.AddVertexInputBindings(&input_binding, 1);
21447 pipe.AddVertexInputAttribs(input_attribs, 2);
21448
21449 VkDescriptorSetObj descriptorSet(m_device);
21450 descriptorSet.AppendDummy();
21451 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21452
21453 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21454
21455 m_errorMonitor->VerifyNotFound();
21456}
21457
21458TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021459 TEST_DESCRIPTION(
21460 "Test that pipeline validation accepts consuming a vertex attribute "
21461 "through multiple vertex shader inputs, each consuming a different "
21462 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021463 m_errorMonitor->ExpectSuccess();
21464
21465 ASSERT_NO_FATAL_FAILURE(InitState());
21466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21467
21468 VkVertexInputBindingDescription input_binding;
21469 memset(&input_binding, 0, sizeof(input_binding));
21470
21471 VkVertexInputAttributeDescription input_attribs[3];
21472 memset(input_attribs, 0, sizeof(input_attribs));
21473
21474 for (int i = 0; i < 3; i++) {
21475 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21476 input_attribs[i].location = i;
21477 }
21478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021479 char const *vsSource =
21480 "#version 450\n"
21481 "\n"
21482 "layout(location=0) in vec4 x;\n"
21483 "layout(location=1) in vec3 y1;\n"
21484 "layout(location=1, component=3) in float y2;\n"
21485 "layout(location=2) in vec4 z;\n"
21486 "out gl_PerVertex {\n"
21487 " vec4 gl_Position;\n"
21488 "};\n"
21489 "void main(){\n"
21490 " gl_Position = x + vec4(y1, y2) + z;\n"
21491 "}\n";
21492 char const *fsSource =
21493 "#version 450\n"
21494 "\n"
21495 "layout(location=0) out vec4 color;\n"
21496 "void main(){\n"
21497 " color = vec4(1);\n"
21498 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021499
21500 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21501 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21502
21503 VkPipelineObj pipe(m_device);
21504 pipe.AddColorAttachment();
21505 pipe.AddShader(&vs);
21506 pipe.AddShader(&fs);
21507
21508 pipe.AddVertexInputBindings(&input_binding, 1);
21509 pipe.AddVertexInputAttribs(input_attribs, 3);
21510
21511 VkDescriptorSetObj descriptorSet(m_device);
21512 descriptorSet.AppendDummy();
21513 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21514
21515 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21516
21517 m_errorMonitor->VerifyNotFound();
21518}
21519
21520TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21521 m_errorMonitor->ExpectSuccess();
21522
21523 ASSERT_NO_FATAL_FAILURE(InitState());
21524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21525
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021526 char const *vsSource =
21527 "#version 450\n"
21528 "out gl_PerVertex {\n"
21529 " vec4 gl_Position;\n"
21530 "};\n"
21531 "void main(){\n"
21532 " gl_Position = vec4(0);\n"
21533 "}\n";
21534 char const *fsSource =
21535 "#version 450\n"
21536 "\n"
21537 "layout(location=0) out vec4 color;\n"
21538 "void main(){\n"
21539 " color = vec4(1);\n"
21540 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021541
21542 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21543 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21544
21545 VkPipelineObj pipe(m_device);
21546 pipe.AddColorAttachment();
21547 pipe.AddShader(&vs);
21548 pipe.AddShader(&fs);
21549
21550 VkDescriptorSetObj descriptorSet(m_device);
21551 descriptorSet.AppendDummy();
21552 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21553
21554 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21555
21556 m_errorMonitor->VerifyNotFound();
21557}
21558
21559TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021560 TEST_DESCRIPTION(
21561 "Test that pipeline validation accepts the relaxed type matching rules "
21562 "set out in 14.1.3: fundamental type must match, and producer side must "
21563 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021564 m_errorMonitor->ExpectSuccess();
21565
21566 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21567
21568 ASSERT_NO_FATAL_FAILURE(InitState());
21569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21570
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021571 char const *vsSource =
21572 "#version 450\n"
21573 "out gl_PerVertex {\n"
21574 " vec4 gl_Position;\n"
21575 "};\n"
21576 "layout(location=0) out vec3 x;\n"
21577 "layout(location=1) out ivec3 y;\n"
21578 "layout(location=2) out vec3 z;\n"
21579 "void main(){\n"
21580 " gl_Position = vec4(0);\n"
21581 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21582 "}\n";
21583 char const *fsSource =
21584 "#version 450\n"
21585 "\n"
21586 "layout(location=0) out vec4 color;\n"
21587 "layout(location=0) in float x;\n"
21588 "layout(location=1) flat in int y;\n"
21589 "layout(location=2) in vec2 z;\n"
21590 "void main(){\n"
21591 " color = vec4(1 + x + y + z.x);\n"
21592 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021593
21594 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21595 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21596
21597 VkPipelineObj pipe(m_device);
21598 pipe.AddColorAttachment();
21599 pipe.AddShader(&vs);
21600 pipe.AddShader(&fs);
21601
21602 VkDescriptorSetObj descriptorSet(m_device);
21603 descriptorSet.AppendDummy();
21604 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21605
21606 VkResult err = VK_SUCCESS;
21607 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21608 ASSERT_VK_SUCCESS(err);
21609
21610 m_errorMonitor->VerifyNotFound();
21611}
21612
21613TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021614 TEST_DESCRIPTION(
21615 "Test that pipeline validation accepts per-vertex variables "
21616 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021617 m_errorMonitor->ExpectSuccess();
21618
21619 ASSERT_NO_FATAL_FAILURE(InitState());
21620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21621
21622 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021623 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021624 return;
21625 }
21626
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021627 char const *vsSource =
21628 "#version 450\n"
21629 "void main(){}\n";
21630 char const *tcsSource =
21631 "#version 450\n"
21632 "layout(location=0) out int x[];\n"
21633 "layout(vertices=3) out;\n"
21634 "void main(){\n"
21635 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21636 " gl_TessLevelInner[0] = 1;\n"
21637 " x[gl_InvocationID] = gl_InvocationID;\n"
21638 "}\n";
21639 char const *tesSource =
21640 "#version 450\n"
21641 "layout(triangles, equal_spacing, cw) in;\n"
21642 "layout(location=0) in int x[];\n"
21643 "out gl_PerVertex { vec4 gl_Position; };\n"
21644 "void main(){\n"
21645 " gl_Position.xyz = gl_TessCoord;\n"
21646 " gl_Position.w = x[0] + x[1] + x[2];\n"
21647 "}\n";
21648 char const *fsSource =
21649 "#version 450\n"
21650 "layout(location=0) out vec4 color;\n"
21651 "void main(){\n"
21652 " color = vec4(1);\n"
21653 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021654
21655 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21656 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21657 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21658 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21659
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021660 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21661 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021662
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021663 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021664
21665 VkPipelineObj pipe(m_device);
21666 pipe.SetInputAssembly(&iasci);
21667 pipe.SetTessellation(&tsci);
21668 pipe.AddColorAttachment();
21669 pipe.AddShader(&vs);
21670 pipe.AddShader(&tcs);
21671 pipe.AddShader(&tes);
21672 pipe.AddShader(&fs);
21673
21674 VkDescriptorSetObj descriptorSet(m_device);
21675 descriptorSet.AppendDummy();
21676 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21677
21678 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21679
21680 m_errorMonitor->VerifyNotFound();
21681}
21682
21683TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021684 TEST_DESCRIPTION(
21685 "Test that pipeline validation accepts a user-defined "
21686 "interface block passed into the geometry shader. This "
21687 "is interesting because the 'extra' array level is not "
21688 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021689 m_errorMonitor->ExpectSuccess();
21690
21691 ASSERT_NO_FATAL_FAILURE(InitState());
21692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21693
21694 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021695 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021696 return;
21697 }
21698
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021699 char const *vsSource =
21700 "#version 450\n"
21701 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21702 "void main(){\n"
21703 " vs_out.x = vec4(1);\n"
21704 "}\n";
21705 char const *gsSource =
21706 "#version 450\n"
21707 "layout(triangles) in;\n"
21708 "layout(triangle_strip, max_vertices=3) out;\n"
21709 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21710 "out gl_PerVertex { vec4 gl_Position; };\n"
21711 "void main() {\n"
21712 " gl_Position = gs_in[0].x;\n"
21713 " EmitVertex();\n"
21714 "}\n";
21715 char const *fsSource =
21716 "#version 450\n"
21717 "layout(location=0) out vec4 color;\n"
21718 "void main(){\n"
21719 " color = vec4(1);\n"
21720 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021721
21722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21723 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21724 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21725
21726 VkPipelineObj pipe(m_device);
21727 pipe.AddColorAttachment();
21728 pipe.AddShader(&vs);
21729 pipe.AddShader(&gs);
21730 pipe.AddShader(&fs);
21731
21732 VkDescriptorSetObj descriptorSet(m_device);
21733 descriptorSet.AppendDummy();
21734 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21735
21736 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21737
21738 m_errorMonitor->VerifyNotFound();
21739}
21740
21741TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021742 TEST_DESCRIPTION(
21743 "Test that pipeline validation accepts basic use of 64bit vertex "
21744 "attributes. This is interesting because they consume multiple "
21745 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021746 m_errorMonitor->ExpectSuccess();
21747
21748 ASSERT_NO_FATAL_FAILURE(InitState());
21749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21750
21751 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021752 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021753 return;
21754 }
21755
21756 VkVertexInputBindingDescription input_bindings[1];
21757 memset(input_bindings, 0, sizeof(input_bindings));
21758
21759 VkVertexInputAttributeDescription input_attribs[4];
21760 memset(input_attribs, 0, sizeof(input_attribs));
21761 input_attribs[0].location = 0;
21762 input_attribs[0].offset = 0;
21763 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21764 input_attribs[1].location = 2;
21765 input_attribs[1].offset = 32;
21766 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21767 input_attribs[2].location = 4;
21768 input_attribs[2].offset = 64;
21769 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21770 input_attribs[3].location = 6;
21771 input_attribs[3].offset = 96;
21772 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21773
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021774 char const *vsSource =
21775 "#version 450\n"
21776 "\n"
21777 "layout(location=0) in dmat4 x;\n"
21778 "out gl_PerVertex {\n"
21779 " vec4 gl_Position;\n"
21780 "};\n"
21781 "void main(){\n"
21782 " gl_Position = vec4(x[0][0]);\n"
21783 "}\n";
21784 char const *fsSource =
21785 "#version 450\n"
21786 "\n"
21787 "layout(location=0) out vec4 color;\n"
21788 "void main(){\n"
21789 " color = vec4(1);\n"
21790 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021791
21792 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21793 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21794
21795 VkPipelineObj pipe(m_device);
21796 pipe.AddColorAttachment();
21797 pipe.AddShader(&vs);
21798 pipe.AddShader(&fs);
21799
21800 pipe.AddVertexInputBindings(input_bindings, 1);
21801 pipe.AddVertexInputAttribs(input_attribs, 4);
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, CreatePipelineInputAttachmentPositive) {
21813 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21814 m_errorMonitor->ExpectSuccess();
21815
21816 ASSERT_NO_FATAL_FAILURE(InitState());
21817
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021818 char const *vsSource =
21819 "#version 450\n"
21820 "\n"
21821 "out gl_PerVertex {\n"
21822 " vec4 gl_Position;\n"
21823 "};\n"
21824 "void main(){\n"
21825 " gl_Position = vec4(1);\n"
21826 "}\n";
21827 char const *fsSource =
21828 "#version 450\n"
21829 "\n"
21830 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21831 "layout(location=0) out vec4 color;\n"
21832 "void main() {\n"
21833 " color = subpassLoad(x);\n"
21834 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021835
21836 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21837 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21838
21839 VkPipelineObj pipe(m_device);
21840 pipe.AddShader(&vs);
21841 pipe.AddShader(&fs);
21842 pipe.AddColorAttachment();
21843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21844
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021845 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21846 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021847 VkDescriptorSetLayout dsl;
21848 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21849 ASSERT_VK_SUCCESS(err);
21850
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021851 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021852 VkPipelineLayout pl;
21853 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21854 ASSERT_VK_SUCCESS(err);
21855
21856 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021857 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21858 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21859 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21860 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21861 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 -060021862 };
21863 VkAttachmentReference color = {
21864 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21865 };
21866 VkAttachmentReference input = {
21867 1, VK_IMAGE_LAYOUT_GENERAL,
21868 };
21869
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021870 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021871
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021872 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021873 VkRenderPass rp;
21874 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21875 ASSERT_VK_SUCCESS(err);
21876
21877 // should be OK. would go wrong here if it's going to...
21878 pipe.CreateVKPipeline(pl, rp);
21879
21880 m_errorMonitor->VerifyNotFound();
21881
21882 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21883 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21884 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21885}
21886
21887TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021888 TEST_DESCRIPTION(
21889 "Test that pipeline validation accepts a compute pipeline which declares a "
21890 "descriptor-backed resource which is not provided, but the shader does not "
21891 "statically use it. This is interesting because it requires compute pipelines "
21892 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021893 m_errorMonitor->ExpectSuccess();
21894
21895 ASSERT_NO_FATAL_FAILURE(InitState());
21896
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021897 char const *csSource =
21898 "#version 450\n"
21899 "\n"
21900 "layout(local_size_x=1) in;\n"
21901 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21902 "void main(){\n"
21903 " // x is not used.\n"
21904 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021905
21906 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21907
21908 VkDescriptorSetObj descriptorSet(m_device);
21909 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21910
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021911 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21912 nullptr,
21913 0,
21914 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21915 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21916 descriptorSet.GetPipelineLayout(),
21917 VK_NULL_HANDLE,
21918 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021919
21920 VkPipeline pipe;
21921 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21922
21923 m_errorMonitor->VerifyNotFound();
21924
21925 if (err == VK_SUCCESS) {
21926 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21927 }
21928}
21929
21930TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021931 TEST_DESCRIPTION(
21932 "Test that pipeline validation accepts a shader consuming only the "
21933 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021934 m_errorMonitor->ExpectSuccess();
21935
21936 ASSERT_NO_FATAL_FAILURE(InitState());
21937
21938 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021939 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21940 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21941 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021942 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021943 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021944 VkDescriptorSetLayout dsl;
21945 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21946 ASSERT_VK_SUCCESS(err);
21947
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021948 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021949 VkPipelineLayout pl;
21950 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21951 ASSERT_VK_SUCCESS(err);
21952
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021953 char const *csSource =
21954 "#version 450\n"
21955 "\n"
21956 "layout(local_size_x=1) in;\n"
21957 "layout(set=0, binding=0) uniform sampler s;\n"
21958 "layout(set=0, binding=1) uniform texture2D t;\n"
21959 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21960 "void main() {\n"
21961 " x = texture(sampler2D(t, s), vec2(0));\n"
21962 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021963 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21964
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021965 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21966 nullptr,
21967 0,
21968 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21969 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21970 pl,
21971 VK_NULL_HANDLE,
21972 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021973
21974 VkPipeline pipe;
21975 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21976
21977 m_errorMonitor->VerifyNotFound();
21978
21979 if (err == VK_SUCCESS) {
21980 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21981 }
21982
21983 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21984 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21985}
21986
21987TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021988 TEST_DESCRIPTION(
21989 "Test that pipeline validation accepts a shader consuming only the "
21990 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021991 m_errorMonitor->ExpectSuccess();
21992
21993 ASSERT_NO_FATAL_FAILURE(InitState());
21994
21995 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021996 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21997 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21998 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021999 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022000 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022001 VkDescriptorSetLayout dsl;
22002 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22003 ASSERT_VK_SUCCESS(err);
22004
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022005 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022006 VkPipelineLayout pl;
22007 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22008 ASSERT_VK_SUCCESS(err);
22009
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022010 char const *csSource =
22011 "#version 450\n"
22012 "\n"
22013 "layout(local_size_x=1) in;\n"
22014 "layout(set=0, binding=0) uniform texture2D t;\n"
22015 "layout(set=0, binding=1) uniform sampler s;\n"
22016 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22017 "void main() {\n"
22018 " x = texture(sampler2D(t, s), vec2(0));\n"
22019 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022020 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22021
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022022 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22023 nullptr,
22024 0,
22025 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22026 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22027 pl,
22028 VK_NULL_HANDLE,
22029 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022030
22031 VkPipeline pipe;
22032 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22033
22034 m_errorMonitor->VerifyNotFound();
22035
22036 if (err == VK_SUCCESS) {
22037 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22038 }
22039
22040 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22041 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22042}
22043
22044TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022045 TEST_DESCRIPTION(
22046 "Test that pipeline validation accepts a shader consuming "
22047 "both the sampler and the image of a combined image+sampler "
22048 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022049 m_errorMonitor->ExpectSuccess();
22050
22051 ASSERT_NO_FATAL_FAILURE(InitState());
22052
22053 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022054 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22055 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022056 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022057 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022058 VkDescriptorSetLayout dsl;
22059 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22060 ASSERT_VK_SUCCESS(err);
22061
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022062 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022063 VkPipelineLayout pl;
22064 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22065 ASSERT_VK_SUCCESS(err);
22066
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022067 char const *csSource =
22068 "#version 450\n"
22069 "\n"
22070 "layout(local_size_x=1) in;\n"
22071 "layout(set=0, binding=0) uniform texture2D t;\n"
22072 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22073 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22074 "void main() {\n"
22075 " x = texture(sampler2D(t, s), vec2(0));\n"
22076 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022077 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22078
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022079 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22080 nullptr,
22081 0,
22082 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22083 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22084 pl,
22085 VK_NULL_HANDLE,
22086 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022087
22088 VkPipeline pipe;
22089 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22090
22091 m_errorMonitor->VerifyNotFound();
22092
22093 if (err == VK_SUCCESS) {
22094 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22095 }
22096
22097 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22098 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22099}
22100
22101TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22102 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22103
22104 ASSERT_NO_FATAL_FAILURE(InitState());
22105
22106 // Positive test to check parameter_validation and unique_objects support
22107 // for NV_dedicated_allocation
22108 uint32_t extension_count = 0;
22109 bool supports_nv_dedicated_allocation = false;
22110 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22111 ASSERT_VK_SUCCESS(err);
22112
22113 if (extension_count > 0) {
22114 std::vector<VkExtensionProperties> available_extensions(extension_count);
22115
22116 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22117 ASSERT_VK_SUCCESS(err);
22118
22119 for (const auto &extension_props : available_extensions) {
22120 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22121 supports_nv_dedicated_allocation = true;
22122 }
22123 }
22124 }
22125
22126 if (supports_nv_dedicated_allocation) {
22127 m_errorMonitor->ExpectSuccess();
22128
22129 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22130 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22131 dedicated_buffer_create_info.pNext = nullptr;
22132 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22133
22134 uint32_t queue_family_index = 0;
22135 VkBufferCreateInfo buffer_create_info = {};
22136 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22137 buffer_create_info.pNext = &dedicated_buffer_create_info;
22138 buffer_create_info.size = 1024;
22139 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22140 buffer_create_info.queueFamilyIndexCount = 1;
22141 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22142
22143 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022144 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022145 ASSERT_VK_SUCCESS(err);
22146
22147 VkMemoryRequirements memory_reqs;
22148 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22149
22150 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22151 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22152 dedicated_memory_info.pNext = nullptr;
22153 dedicated_memory_info.buffer = buffer;
22154 dedicated_memory_info.image = VK_NULL_HANDLE;
22155
22156 VkMemoryAllocateInfo memory_info = {};
22157 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22158 memory_info.pNext = &dedicated_memory_info;
22159 memory_info.allocationSize = memory_reqs.size;
22160
22161 bool pass;
22162 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22163 ASSERT_TRUE(pass);
22164
22165 VkDeviceMemory buffer_memory;
22166 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22167 ASSERT_VK_SUCCESS(err);
22168
22169 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22170 ASSERT_VK_SUCCESS(err);
22171
22172 vkDestroyBuffer(m_device->device(), buffer, NULL);
22173 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22174
22175 m_errorMonitor->VerifyNotFound();
22176 }
22177}
22178
22179TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22180 VkResult err;
22181
22182 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22183
22184 ASSERT_NO_FATAL_FAILURE(InitState());
22185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22186
22187 std::vector<const char *> device_extension_names;
22188 auto features = m_device->phy().features();
22189 // Artificially disable support for non-solid fill modes
22190 features.fillModeNonSolid = false;
22191 // The sacrificial device object
22192 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22193
22194 VkRenderpassObj render_pass(&test_device);
22195
22196 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22197 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22198 pipeline_layout_ci.setLayoutCount = 0;
22199 pipeline_layout_ci.pSetLayouts = NULL;
22200
22201 VkPipelineLayout pipeline_layout;
22202 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22203 ASSERT_VK_SUCCESS(err);
22204
22205 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22206 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22207 rs_ci.pNext = nullptr;
22208 rs_ci.lineWidth = 1.0f;
22209 rs_ci.rasterizerDiscardEnable = true;
22210
22211 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22212 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22213
22214 // Set polygonMode=FILL. No error is expected
22215 m_errorMonitor->ExpectSuccess();
22216 {
22217 VkPipelineObj pipe(&test_device);
22218 pipe.AddShader(&vs);
22219 pipe.AddShader(&fs);
22220 pipe.AddColorAttachment();
22221 // Set polygonMode to a good value
22222 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22223 pipe.SetRasterization(&rs_ci);
22224 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22225 }
22226 m_errorMonitor->VerifyNotFound();
22227
22228 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22229}
22230
22231TEST_F(VkPositiveLayerTest, ValidPushConstants) {
22232 VkResult err;
22233 ASSERT_NO_FATAL_FAILURE(InitState());
22234 ASSERT_NO_FATAL_FAILURE(InitViewport());
22235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22236
22237 VkPipelineLayout pipeline_layout;
22238 VkPushConstantRange pc_range = {};
22239 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22240 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22241 pipeline_layout_ci.pushConstantRangeCount = 1;
22242 pipeline_layout_ci.pPushConstantRanges = &pc_range;
22243
22244 //
22245 // Check for invalid push constant ranges in pipeline layouts.
22246 //
22247 struct PipelineLayoutTestCase {
22248 VkPushConstantRange const range;
22249 char const *msg;
22250 };
22251
22252 // Check for overlapping ranges
22253 const uint32_t ranges_per_test = 5;
22254 struct OverlappingRangeTestCase {
22255 VkPushConstantRange const ranges[ranges_per_test];
22256 char const *msg;
22257 };
22258
22259 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022260 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
22261 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
22262 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
22263 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
22264 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
22265 ""},
22266 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
22267 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
22268 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
22269 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
22270 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
22271 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022272 for (const auto &iter : overlapping_range_tests_pos) {
22273 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
22274 m_errorMonitor->ExpectSuccess();
22275 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22276 m_errorMonitor->VerifyNotFound();
22277 if (VK_SUCCESS == err) {
22278 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22279 }
22280 }
22281
22282 //
22283 // CmdPushConstants tests
22284 //
22285 const uint8_t dummy_values[100] = {};
22286
Tony Barbour552f6c02016-12-21 14:34:07 -070022287 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022288
22289 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022290 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
22291 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
22292 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
22293 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
22294 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
22295 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022296
22297 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
22298 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022299 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
22300 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 24},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022301 };
22302
22303 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
22304 pipeline_layout_ci.pPushConstantRanges = pc_range4;
22305 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22306 ASSERT_VK_SUCCESS(err);
22307 for (const auto &iter : cmd_overlap_tests_pos) {
22308 m_errorMonitor->ExpectSuccess();
22309 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022310 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022311 m_errorMonitor->VerifyNotFound();
22312 }
22313 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22314
Tony Barbour552f6c02016-12-21 14:34:07 -070022315 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022316}
22317
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022318#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022319TEST_F(VkPositiveLayerTest, LongFenceChain)
22320{
22321 m_errorMonitor->ExpectSuccess();
22322
22323 ASSERT_NO_FATAL_FAILURE(InitState());
22324 VkResult err;
22325
22326 std::vector<VkFence> fences;
22327
22328 const int chainLength = 32768;
22329
22330 for (int i = 0; i < chainLength; i++) {
22331 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22332 VkFence fence;
22333 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22334 ASSERT_VK_SUCCESS(err);
22335
22336 fences.push_back(fence);
22337
22338 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22339 0, nullptr, 0, nullptr };
22340 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22341 ASSERT_VK_SUCCESS(err);
22342
22343 }
22344
22345 // BOOM, stack overflow.
22346 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22347
22348 for (auto fence : fences)
22349 vkDestroyFence(m_device->device(), fence, nullptr);
22350
22351 m_errorMonitor->VerifyNotFound();
22352}
22353#endif
22354
Cody Northrop1242dfd2016-07-13 17:24:59 -060022355#if defined(ANDROID) && defined(VALIDATION_APK)
22356static bool initialized = false;
22357static bool active = false;
22358
22359// Convert Intents to argv
22360// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022361std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022362 std::vector<std::string> args;
22363 JavaVM &vm = *app.activity->vm;
22364 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022365 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022366
22367 JNIEnv &env = *p_env;
22368 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022369 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022370 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022371 jmethodID get_string_extra_method =
22372 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022373 jvalue get_string_extra_args;
22374 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022375 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022376
22377 std::string args_str;
22378 if (extra_str) {
22379 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22380 args_str = extra_utf;
22381 env.ReleaseStringUTFChars(extra_str, extra_utf);
22382 env.DeleteLocalRef(extra_str);
22383 }
22384
22385 env.DeleteLocalRef(get_string_extra_args.l);
22386 env.DeleteLocalRef(intent);
22387 vm.DetachCurrentThread();
22388
22389 // split args_str
22390 std::stringstream ss(args_str);
22391 std::string arg;
22392 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022393 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022394 }
22395
22396 return args;
22397}
22398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022399static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022401static void processCommand(struct android_app *app, int32_t cmd) {
22402 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022403 case APP_CMD_INIT_WINDOW: {
22404 if (app->window) {
22405 initialized = true;
22406 }
22407 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022408 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022409 case APP_CMD_GAINED_FOCUS: {
22410 active = true;
22411 break;
22412 }
22413 case APP_CMD_LOST_FOCUS: {
22414 active = false;
22415 break;
22416 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022417 }
22418}
22419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022420void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022421 app_dummy();
22422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022423 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022424
22425 int vulkanSupport = InitVulkan();
22426 if (vulkanSupport == 0) {
22427 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22428 return;
22429 }
22430
22431 app->onAppCmd = processCommand;
22432 app->onInputEvent = processInput;
22433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022434 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022435 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022436 struct android_poll_source *source;
22437 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022438 if (source) {
22439 source->process(app, source);
22440 }
22441
22442 if (app->destroyRequested != 0) {
22443 VkTestFramework::Finish();
22444 return;
22445 }
22446 }
22447
22448 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022449 // Use the following key to send arguments to gtest, i.e.
22450 // --es args "--gtest_filter=-VkLayerTest.foo"
22451 const char key[] = "args";
22452 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022453
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022454 std::string filter = "";
22455 if (args.size() > 0) {
22456 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22457 filter += args[0];
22458 } else {
22459 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22460 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022461
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022462 int argc = 2;
22463 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22464 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022466 // Route output to files until we can override the gtest output
22467 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22468 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022470 ::testing::InitGoogleTest(&argc, argv);
22471 VkTestFramework::InitArgs(&argc, argv);
22472 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022474 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022476 if (result != 0) {
22477 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22478 } else {
22479 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22480 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022481
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022482 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022484 fclose(stdout);
22485 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022486
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022487 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022488 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022489 }
22490 }
22491}
22492#endif
22493
Tony Barbour300a6082015-04-07 13:44:53 -060022494int main(int argc, char **argv) {
22495 int result;
22496
Cody Northrop8e54a402016-03-08 22:25:52 -070022497#ifdef ANDROID
22498 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022499 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022500#endif
22501
Tony Barbour300a6082015-04-07 13:44:53 -060022502 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022503 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022504
22505 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22506
22507 result = RUN_ALL_TESTS();
22508
Tony Barbour6918cd52015-04-09 12:58:51 -060022509 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022510 return result;
22511}