blob: 9ee87bbf0bd767ac1b8017c57c755da53a408ecb [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
Karl Schultz6addd812016-02-02 17:17:23 -07002392TEST_F(VkLayerTest, PipelineNotBound) {
2393 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002395 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002396
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002398
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002399 ASSERT_NO_FATAL_FAILURE(InitState());
2400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002401
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002402 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002403 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2404 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002405
2406 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002407 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2408 ds_pool_ci.pNext = NULL;
2409 ds_pool_ci.maxSets = 1;
2410 ds_pool_ci.poolSizeCount = 1;
2411 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002412
2413 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002414 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002415 ASSERT_VK_SUCCESS(err);
2416
2417 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002418 dsl_binding.binding = 0;
2419 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2420 dsl_binding.descriptorCount = 1;
2421 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2422 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002423
2424 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002425 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2426 ds_layout_ci.pNext = NULL;
2427 ds_layout_ci.bindingCount = 1;
2428 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002429
2430 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002431 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002432 ASSERT_VK_SUCCESS(err);
2433
2434 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002435 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002436 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002437 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002438 alloc_info.descriptorPool = ds_pool;
2439 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002440 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002441 ASSERT_VK_SUCCESS(err);
2442
2443 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002444 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2445 pipeline_layout_ci.pNext = NULL;
2446 pipeline_layout_ci.setLayoutCount = 1;
2447 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002448
2449 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002450 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002451 ASSERT_VK_SUCCESS(err);
2452
Mark Youngad779052016-01-06 14:26:04 -07002453 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454
Tony Barbour552f6c02016-12-21 14:34:07 -07002455 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002456 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002458 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002459
Chia-I Wuf7458c52015-10-26 21:10:41 +08002460 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002463}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002464
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002465TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2466 VkResult err;
2467
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002468 TEST_DESCRIPTION(
2469 "Test validation check for an invalid memory type index "
2470 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002471
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002472 ASSERT_NO_FATAL_FAILURE(InitState());
2473
2474 // Create an image, allocate memory, set a bad typeIndex and then try to
2475 // bind it
2476 VkImage image;
2477 VkDeviceMemory mem;
2478 VkMemoryRequirements mem_reqs;
2479 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2480 const int32_t tex_width = 32;
2481 const int32_t tex_height = 32;
2482
2483 VkImageCreateInfo image_create_info = {};
2484 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2485 image_create_info.pNext = NULL;
2486 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2487 image_create_info.format = tex_format;
2488 image_create_info.extent.width = tex_width;
2489 image_create_info.extent.height = tex_height;
2490 image_create_info.extent.depth = 1;
2491 image_create_info.mipLevels = 1;
2492 image_create_info.arrayLayers = 1;
2493 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2494 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2495 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2496 image_create_info.flags = 0;
2497
2498 VkMemoryAllocateInfo mem_alloc = {};
2499 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2500 mem_alloc.pNext = NULL;
2501 mem_alloc.allocationSize = 0;
2502 mem_alloc.memoryTypeIndex = 0;
2503
2504 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2505 ASSERT_VK_SUCCESS(err);
2506
2507 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2508 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002509
2510 // Introduce Failure, select invalid TypeIndex
2511 VkPhysicalDeviceMemoryProperties memory_info;
2512
2513 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2514 unsigned int i;
2515 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2516 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2517 mem_alloc.memoryTypeIndex = i;
2518 break;
2519 }
2520 }
2521 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002522 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002523 vkDestroyImage(m_device->device(), image, NULL);
2524 return;
2525 }
2526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002527 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 -06002528
2529 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2530 ASSERT_VK_SUCCESS(err);
2531
2532 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2533 (void)err;
2534
2535 m_errorMonitor->VerifyFound();
2536
2537 vkDestroyImage(m_device->device(), image, NULL);
2538 vkFreeMemory(m_device->device(), mem, NULL);
2539}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002540
Karl Schultz6addd812016-02-02 17:17:23 -07002541TEST_F(VkLayerTest, BindInvalidMemory) {
2542 VkResult err;
2543 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002544
2545 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002546
Cortf801b982017-01-17 18:10:21 -08002547 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -07002548 const int32_t tex_width = 32;
2549 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002550
2551 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002552 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2553 image_create_info.pNext = NULL;
2554 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2555 image_create_info.format = tex_format;
2556 image_create_info.extent.width = tex_width;
2557 image_create_info.extent.height = tex_height;
2558 image_create_info.extent.depth = 1;
2559 image_create_info.mipLevels = 1;
2560 image_create_info.arrayLayers = 1;
2561 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002562 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002563 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2564 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002565
Cortf801b982017-01-17 18:10:21 -08002566 VkBufferCreateInfo buffer_create_info = {};
2567 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2568 buffer_create_info.pNext = NULL;
2569 buffer_create_info.flags = 0;
2570 buffer_create_info.size = tex_width;
2571 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2572 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002573
Cortf801b982017-01-17 18:10:21 -08002574 // Create an image/buffer, allocate memory, free it, and then try to bind it
2575 {
2576 VkImage image = VK_NULL_HANDLE;
2577 VkBuffer buffer = VK_NULL_HANDLE;
2578 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2579 ASSERT_VK_SUCCESS(err);
2580 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2581 ASSERT_VK_SUCCESS(err);
2582 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2583 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2584 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002585
Cortf801b982017-01-17 18:10:21 -08002586 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2587 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2588 image_mem_alloc.allocationSize = image_mem_reqs.size;
2589 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2590 ASSERT_TRUE(pass);
2591 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2592 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2593 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2594 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002595
Cortf801b982017-01-17 18:10:21 -08002596 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2597 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2598 ASSERT_VK_SUCCESS(err);
2599 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2600 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002601
Cortf801b982017-01-17 18:10:21 -08002602 vkFreeMemory(device(), image_mem, NULL);
2603 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002604
Cortf801b982017-01-17 18:10:21 -08002605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2606 err = vkBindImageMemory(device(), image, image_mem, 0);
2607 (void)err; // This may very well return an error.
2608 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002609
Cortf801b982017-01-17 18:10:21 -08002610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2611 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2612 (void)err; // This may very well return an error.
2613 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002614
Cortf801b982017-01-17 18:10:21 -08002615 vkDestroyImage(m_device->device(), image, NULL);
2616 vkDestroyBuffer(m_device->device(), buffer, NULL);
2617 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002618
2619 // Try to bind memory to an object that already has a memory binding
2620 {
2621 VkImage image = VK_NULL_HANDLE;
2622 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2623 ASSERT_VK_SUCCESS(err);
2624 VkBuffer buffer = VK_NULL_HANDLE;
2625 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2626 ASSERT_VK_SUCCESS(err);
2627 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2628 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2629 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2630 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2631 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2632 image_alloc_info.allocationSize = image_mem_reqs.size;
2633 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2634 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2635 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2636 ASSERT_TRUE(pass);
2637 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2638 ASSERT_TRUE(pass);
2639 VkDeviceMemory image_mem, buffer_mem;
2640 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2641 ASSERT_VK_SUCCESS(err);
2642 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2643 ASSERT_VK_SUCCESS(err);
2644
2645 err = vkBindImageMemory(device(), image, image_mem, 0);
2646 ASSERT_VK_SUCCESS(err);
2647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2648 err = vkBindImageMemory(device(), image, image_mem, 0);
2649 (void)err; // This may very well return an error.
2650 m_errorMonitor->VerifyFound();
2651
2652 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2653 ASSERT_VK_SUCCESS(err);
2654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2655 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2656 (void)err; // This may very well return an error.
2657 m_errorMonitor->VerifyFound();
2658
2659 vkFreeMemory(device(), image_mem, NULL);
2660 vkFreeMemory(device(), buffer_mem, NULL);
2661 vkDestroyImage(device(), image, NULL);
2662 vkDestroyBuffer(device(), buffer, NULL);
2663 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002664
Cort6c7dff72017-01-27 18:34:50 -08002665 // Try to bind memory to an object with an out-of-range memoryOffset
2666 {
2667 VkImage image = VK_NULL_HANDLE;
2668 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2669 ASSERT_VK_SUCCESS(err);
2670 VkBuffer buffer = VK_NULL_HANDLE;
2671 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2672 ASSERT_VK_SUCCESS(err);
2673 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2674 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2675 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2676 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2677 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2678 image_alloc_info.allocationSize = image_mem_reqs.size;
2679 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2680 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2681 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2682 ASSERT_TRUE(pass);
2683 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2684 ASSERT_TRUE(pass);
2685 VkDeviceMemory image_mem, buffer_mem;
2686 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2687 ASSERT_VK_SUCCESS(err);
2688 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2689 ASSERT_VK_SUCCESS(err);
2690
2691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2692 VkDeviceSize image_offset = (image_mem_reqs.size + (image_mem_reqs.alignment - 1)) & ~(image_mem_reqs.alignment - 1);
2693 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2694 (void)err; // This may very well return an error.
2695 m_errorMonitor->VerifyFound();
2696
2697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2698 VkDeviceSize buffer_offset = (buffer_mem_reqs.size + (buffer_mem_reqs.alignment - 1)) & ~(buffer_mem_reqs.alignment - 1);
2699 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2700 (void)err; // This may very well return an error.
2701 m_errorMonitor->VerifyFound();
2702
2703 vkFreeMemory(device(), image_mem, NULL);
2704 vkFreeMemory(device(), buffer_mem, NULL);
2705 vkDestroyImage(device(), image, NULL);
2706 vkDestroyBuffer(device(), buffer, NULL);
2707 }
2708
Cort Stratton4c38bb52017-01-28 13:33:10 -08002709 // Try to bind memory to an object with an invalid memory type
2710 {
2711 VkImage image = VK_NULL_HANDLE;
2712 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2713 ASSERT_VK_SUCCESS(err);
2714 VkBuffer buffer = VK_NULL_HANDLE;
2715 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2716 ASSERT_VK_SUCCESS(err);
2717 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2718 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2719 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2720 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2721 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2722 image_alloc_info.allocationSize = image_mem_reqs.size;
2723 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2724 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002725 // Create a mask of available memory types *not* supported by these resources,
2726 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002727 VkPhysicalDeviceMemoryProperties memory_properties = {};
2728 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002729 VkDeviceMemory image_mem, buffer_mem;
2730
Cort Stratton4c38bb52017-01-28 13:33:10 -08002731 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002732 if (image_unsupported_mem_type_bits != 0) {
2733 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2734 ASSERT_TRUE(pass);
2735 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2736 ASSERT_VK_SUCCESS(err);
2737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2738 err = vkBindImageMemory(device(), image, image_mem, 0);
2739 (void)err; // This may very well return an error.
2740 m_errorMonitor->VerifyFound();
2741 vkFreeMemory(device(), image_mem, NULL);
2742 }
2743
Cort Stratton4c38bb52017-01-28 13:33:10 -08002744 uint32_t buffer_unsupported_mem_type_bits =
2745 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002746 if (buffer_unsupported_mem_type_bits != 0) {
2747 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2748 ASSERT_TRUE(pass);
2749 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2750 ASSERT_VK_SUCCESS(err);
2751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2752 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2753 (void)err; // This may very well return an error.
2754 m_errorMonitor->VerifyFound();
2755 vkFreeMemory(device(), buffer_mem, NULL);
2756 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002757
Cort Stratton4c38bb52017-01-28 13:33:10 -08002758 vkDestroyImage(device(), image, NULL);
2759 vkDestroyBuffer(device(), buffer, NULL);
2760 }
2761
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002762 // Try to bind memory to an image created with sparse memory flags
2763 {
2764 VkImageCreateInfo sparse_image_create_info = image_create_info;
2765 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2766 VkImageFormatProperties image_format_properties = {};
2767 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2768 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2769 sparse_image_create_info.usage, sparse_image_create_info.flags,
2770 &image_format_properties);
2771 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2772 // most likely means sparse formats aren't supported here; skip this test.
2773 } else {
2774 ASSERT_VK_SUCCESS(err);
2775 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002776 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002777 return;
2778 } else {
2779 VkImage sparse_image = VK_NULL_HANDLE;
2780 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2781 ASSERT_VK_SUCCESS(err);
2782 VkMemoryRequirements sparse_mem_reqs = {};
2783 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2784 if (sparse_mem_reqs.memoryTypeBits != 0) {
2785 VkMemoryAllocateInfo sparse_mem_alloc = {};
2786 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2787 sparse_mem_alloc.pNext = NULL;
2788 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2789 sparse_mem_alloc.memoryTypeIndex = 0;
2790 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2791 ASSERT_TRUE(pass);
2792 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2793 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2794 ASSERT_VK_SUCCESS(err);
2795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2796 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2797 // This may very well return an error.
2798 (void)err;
2799 m_errorMonitor->VerifyFound();
2800 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2801 }
2802 vkDestroyImage(m_device->device(), sparse_image, NULL);
2803 }
2804 }
2805 }
2806
2807 // Try to bind memory to a buffer created with sparse memory flags
2808 {
2809 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2810 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2811 if (!m_device->phy().features().sparseResidencyBuffer) {
2812 // most likely means sparse formats aren't supported here; skip this test.
2813 } else {
2814 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2815 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2816 ASSERT_VK_SUCCESS(err);
2817 VkMemoryRequirements sparse_mem_reqs = {};
2818 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2819 if (sparse_mem_reqs.memoryTypeBits != 0) {
2820 VkMemoryAllocateInfo sparse_mem_alloc = {};
2821 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2822 sparse_mem_alloc.pNext = NULL;
2823 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2824 sparse_mem_alloc.memoryTypeIndex = 0;
2825 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2826 ASSERT_TRUE(pass);
2827 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2828 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2829 ASSERT_VK_SUCCESS(err);
2830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2831 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2832 // This may very well return an error.
2833 (void)err;
2834 m_errorMonitor->VerifyFound();
2835 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2836 }
2837 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2838 }
2839 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002840}
2841
Karl Schultz6addd812016-02-02 17:17:23 -07002842TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2843 VkResult err;
2844 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002845
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002847
Tobin Ehlisec598302015-09-15 15:02:17 -06002848 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002849
Karl Schultz6addd812016-02-02 17:17:23 -07002850 // Create an image object, allocate memory, destroy the object and then try
2851 // to bind it
2852 VkImage image;
2853 VkDeviceMemory mem;
2854 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002855
Karl Schultz6addd812016-02-02 17:17:23 -07002856 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2857 const int32_t tex_width = 32;
2858 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002859
2860 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002861 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2862 image_create_info.pNext = NULL;
2863 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2864 image_create_info.format = tex_format;
2865 image_create_info.extent.width = tex_width;
2866 image_create_info.extent.height = tex_height;
2867 image_create_info.extent.depth = 1;
2868 image_create_info.mipLevels = 1;
2869 image_create_info.arrayLayers = 1;
2870 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2871 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2872 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2873 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002874
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002875 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002876 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2877 mem_alloc.pNext = NULL;
2878 mem_alloc.allocationSize = 0;
2879 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002880
Chia-I Wuf7458c52015-10-26 21:10:41 +08002881 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002882 ASSERT_VK_SUCCESS(err);
2883
Karl Schultz6addd812016-02-02 17:17:23 -07002884 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002885
2886 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002887 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002888 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002889
2890 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002891 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002892 ASSERT_VK_SUCCESS(err);
2893
2894 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002895 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002896 ASSERT_VK_SUCCESS(err);
2897
2898 // Now Try to bind memory to this destroyed object
2899 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2900 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002901 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002902
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002903 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002904
Chia-I Wuf7458c52015-10-26 21:10:41 +08002905 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002906}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002907
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002908TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2909 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2910
2911 ASSERT_NO_FATAL_FAILURE(InitState());
2912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2913
2914 VkVertexInputBindingDescription input_binding;
2915 memset(&input_binding, 0, sizeof(input_binding));
2916
2917 VkVertexInputAttributeDescription input_attribs;
2918 memset(&input_attribs, 0, sizeof(input_attribs));
2919
2920 // Pick a really bad format for this purpose and make sure it should fail
2921 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2922 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2923 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002924 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002925 return;
2926 }
2927
2928 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002929 char const *vsSource =
2930 "#version 450\n"
2931 "\n"
2932 "out gl_PerVertex {\n"
2933 " vec4 gl_Position;\n"
2934 "};\n"
2935 "void main(){\n"
2936 " gl_Position = vec4(1);\n"
2937 "}\n";
2938 char const *fsSource =
2939 "#version 450\n"
2940 "\n"
2941 "layout(location=0) out vec4 color;\n"
2942 "void main(){\n"
2943 " color = vec4(1);\n"
2944 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002945
2946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2947 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2948 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2949
2950 VkPipelineObj pipe(m_device);
2951 pipe.AddColorAttachment();
2952 pipe.AddShader(&vs);
2953 pipe.AddShader(&fs);
2954
2955 pipe.AddVertexInputBindings(&input_binding, 1);
2956 pipe.AddVertexInputAttribs(&input_attribs, 1);
2957
2958 VkDescriptorSetObj descriptorSet(m_device);
2959 descriptorSet.AppendDummy();
2960 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2961
2962 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2963
2964 m_errorMonitor->VerifyFound();
2965}
2966
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002967TEST_F(VkLayerTest, ImageSampleCounts) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002968 TEST_DESCRIPTION(
2969 "Use bad sample counts in image transfer calls to trigger "
2970 "validation errors.");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002971 ASSERT_NO_FATAL_FAILURE(InitState());
2972
2973 VkMemoryPropertyFlags reqs = 0;
2974 VkImageCreateInfo image_create_info = {};
2975 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2976 image_create_info.pNext = NULL;
2977 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2978 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2979 image_create_info.extent.width = 256;
2980 image_create_info.extent.height = 256;
2981 image_create_info.extent.depth = 1;
2982 image_create_info.mipLevels = 1;
2983 image_create_info.arrayLayers = 1;
2984 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2985 image_create_info.flags = 0;
2986
2987 VkImageBlit blit_region = {};
2988 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2989 blit_region.srcSubresource.baseArrayLayer = 0;
2990 blit_region.srcSubresource.layerCount = 1;
2991 blit_region.srcSubresource.mipLevel = 0;
2992 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2993 blit_region.dstSubresource.baseArrayLayer = 0;
2994 blit_region.dstSubresource.layerCount = 1;
2995 blit_region.dstSubresource.mipLevel = 0;
2996
2997 // Create two images, the source with sampleCount = 2, and attempt to blit
2998 // between them
2999 {
3000 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003001 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003002 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003003 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003004 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003005 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003006 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003007 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003008 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003009 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3011 "was created with a sample count "
3012 "of VK_SAMPLE_COUNT_2_BIT but "
3013 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003014 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3015 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003016 m_errorMonitor->VerifyFound();
3017 m_commandBuffer->EndCommandBuffer();
3018 }
3019
3020 // Create two images, the dest with sampleCount = 4, and attempt to blit
3021 // between them
3022 {
3023 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003024 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003025 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003026 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003027 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003028 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003029 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003030 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003031 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003032 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3034 "was created with a sample count "
3035 "of VK_SAMPLE_COUNT_4_BIT but "
3036 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003037 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3038 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003039 m_errorMonitor->VerifyFound();
3040 m_commandBuffer->EndCommandBuffer();
3041 }
3042
3043 VkBufferImageCopy copy_region = {};
3044 copy_region.bufferRowLength = 128;
3045 copy_region.bufferImageHeight = 128;
3046 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3047 copy_region.imageSubresource.layerCount = 1;
3048 copy_region.imageExtent.height = 64;
3049 copy_region.imageExtent.width = 64;
3050 copy_region.imageExtent.depth = 1;
3051
3052 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3053 // buffer to image
3054 {
3055 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003056 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3057 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003058 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003059 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003060 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003061 m_errorMonitor->SetUnexpectedError(
3062 "If commandBuffer was allocated from a VkCommandPool which did not have the "
3063 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003064 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3066 "was created with a sample count "
3067 "of VK_SAMPLE_COUNT_8_BIT but "
3068 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003069 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3070 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003071 m_errorMonitor->VerifyFound();
3072 m_commandBuffer->EndCommandBuffer();
3073 }
3074
3075 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3076 // image to buffer
3077 {
3078 vk_testing::Buffer dst_buffer;
3079 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3080 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003082 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003083 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003084 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003085 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3087 "was created with a sample count "
3088 "of VK_SAMPLE_COUNT_2_BIT but "
3089 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003090 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003091 dst_buffer.handle(), 1, &copy_region);
3092 m_errorMonitor->VerifyFound();
3093 m_commandBuffer->EndCommandBuffer();
3094 }
3095}
3096
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003097TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003098 ASSERT_NO_FATAL_FAILURE(InitState());
3099
3100 VkImageObj src_image(m_device);
3101 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3102 VkImageObj dst_image(m_device);
3103 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3104 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003105 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 -06003106
3107 VkImageBlit blitRegion = {};
3108 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3109 blitRegion.srcSubresource.baseArrayLayer = 0;
3110 blitRegion.srcSubresource.layerCount = 1;
3111 blitRegion.srcSubresource.mipLevel = 0;
3112 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3113 blitRegion.dstSubresource.baseArrayLayer = 0;
3114 blitRegion.dstSubresource.layerCount = 1;
3115 blitRegion.dstSubresource.mipLevel = 0;
3116
Dave Houlton34df4cb2016-12-01 16:43:06 -07003117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3118
3119 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3120 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003121
3122 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003123 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003124 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3125 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003126
3127 m_errorMonitor->VerifyFound();
3128
Dave Houlton34df4cb2016-12-01 16:43:06 -07003129 // Test should generate 2 VU failures
3130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003132
3133 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003134 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3135 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003136
Dave Houlton34df4cb2016-12-01 16:43:06 -07003137 // TODO: Note that this only verifies that at least one of the VU enums was found
3138 // 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 -06003139 m_errorMonitor->VerifyFound();
3140
Tony Barbour552f6c02016-12-21 14:34:07 -07003141 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003142}
3143
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003144TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3145 VkResult err;
3146 bool pass;
3147
3148 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3149 ASSERT_NO_FATAL_FAILURE(InitState());
3150
3151 // If w/d/h granularity is 1, test is not meaningful
3152 // TODO: When virtual device limits are available, create a set of limits for this test that
3153 // will always have a granularity of > 1 for w, h, and d
3154 auto index = m_device->graphics_queue_node_index_;
3155 auto queue_family_properties = m_device->phy().queue_properties();
3156
3157 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3158 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3159 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3160 return;
3161 }
3162
3163 // Create two images of different types and try to copy between them
3164 VkImage srcImage;
3165 VkImage dstImage;
3166 VkDeviceMemory srcMem;
3167 VkDeviceMemory destMem;
3168 VkMemoryRequirements memReqs;
3169
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003170 VkImageCreateInfo image_create_info = {};
3171 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3172 image_create_info.pNext = NULL;
3173 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3174 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3175 image_create_info.extent.width = 32;
3176 image_create_info.extent.height = 32;
3177 image_create_info.extent.depth = 1;
3178 image_create_info.mipLevels = 1;
3179 image_create_info.arrayLayers = 4;
3180 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3181 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3182 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3183 image_create_info.flags = 0;
3184
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003185 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003186 ASSERT_VK_SUCCESS(err);
3187
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003188 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003189 ASSERT_VK_SUCCESS(err);
3190
3191 // Allocate memory
3192 VkMemoryAllocateInfo memAlloc = {};
3193 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3194 memAlloc.pNext = NULL;
3195 memAlloc.allocationSize = 0;
3196 memAlloc.memoryTypeIndex = 0;
3197
3198 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3199 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003200 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003201 ASSERT_TRUE(pass);
3202 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3203 ASSERT_VK_SUCCESS(err);
3204
3205 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3206 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003207 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003208 ASSERT_VK_SUCCESS(err);
3209 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3210 ASSERT_VK_SUCCESS(err);
3211
3212 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3213 ASSERT_VK_SUCCESS(err);
3214 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3215 ASSERT_VK_SUCCESS(err);
3216
Tony Barbour552f6c02016-12-21 14:34:07 -07003217 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003218 VkImageCopy copyRegion;
3219 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3220 copyRegion.srcSubresource.mipLevel = 0;
3221 copyRegion.srcSubresource.baseArrayLayer = 0;
3222 copyRegion.srcSubresource.layerCount = 1;
3223 copyRegion.srcOffset.x = 0;
3224 copyRegion.srcOffset.y = 0;
3225 copyRegion.srcOffset.z = 0;
3226 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3227 copyRegion.dstSubresource.mipLevel = 0;
3228 copyRegion.dstSubresource.baseArrayLayer = 0;
3229 copyRegion.dstSubresource.layerCount = 1;
3230 copyRegion.dstOffset.x = 0;
3231 copyRegion.dstOffset.y = 0;
3232 copyRegion.dstOffset.z = 0;
3233 copyRegion.extent.width = 1;
3234 copyRegion.extent.height = 1;
3235 copyRegion.extent.depth = 1;
3236
3237 // Introduce failure by setting srcOffset to a bad granularity value
3238 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3240 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003241 m_errorMonitor->VerifyFound();
3242
3243 // Introduce failure by setting extent to a bad granularity value
3244 copyRegion.srcOffset.y = 0;
3245 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3247 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003248 m_errorMonitor->VerifyFound();
3249
3250 // Now do some buffer/image copies
3251 vk_testing::Buffer buffer;
3252 VkMemoryPropertyFlags reqs = 0;
3253 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3254 VkBufferImageCopy region = {};
3255 region.bufferOffset = 0;
3256 region.bufferRowLength = 3;
3257 region.bufferImageHeight = 128;
3258 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3259 region.imageSubresource.layerCount = 1;
3260 region.imageExtent.height = 16;
3261 region.imageExtent.width = 16;
3262 region.imageExtent.depth = 1;
3263 region.imageOffset.x = 0;
3264 region.imageOffset.y = 0;
3265 region.imageOffset.z = 0;
3266
3267 // Introduce failure by setting bufferRowLength to a bad granularity value
3268 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3270 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3271 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 m_errorMonitor->VerifyFound();
3273 region.bufferRowLength = 128;
3274
3275 // Introduce failure by setting bufferOffset to a bad granularity value
3276 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3278 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3279 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003280 m_errorMonitor->VerifyFound();
3281 region.bufferOffset = 0;
3282
3283 // Introduce failure by setting bufferImageHeight to a bad granularity value
3284 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3286 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3287 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003288 m_errorMonitor->VerifyFound();
3289 region.bufferImageHeight = 128;
3290
3291 // Introduce failure by setting imageExtent to a bad granularity value
3292 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3294 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3295 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003296 m_errorMonitor->VerifyFound();
3297 region.imageExtent.width = 16;
3298
3299 // Introduce failure by setting imageOffset to a bad granularity value
3300 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3302 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3303 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003304 m_errorMonitor->VerifyFound();
3305
Tony Barbour552f6c02016-12-21 14:34:07 -07003306 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003307
3308 vkDestroyImage(m_device->device(), srcImage, NULL);
3309 vkDestroyImage(m_device->device(), dstImage, NULL);
3310 vkFreeMemory(m_device->device(), srcMem, NULL);
3311 vkFreeMemory(m_device->device(), destMem, NULL);
3312}
3313
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003314TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003315 TEST_DESCRIPTION(
3316 "Submit command buffer created using one queue family and "
3317 "attempt to submit them on a queue created in a different "
3318 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003319
Cody Northropc31a84f2016-08-22 10:41:47 -06003320 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003321
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003322 // This test is meaningless unless we have multiple queue families
3323 auto queue_family_properties = m_device->phy().queue_properties();
3324 if (queue_family_properties.size() < 2) {
3325 return;
3326 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003328 // Get safe index of another queue family
3329 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3330 ASSERT_NO_FATAL_FAILURE(InitState());
3331 // Create a second queue using a different queue family
3332 VkQueue other_queue;
3333 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3334
3335 // Record an empty cmd buffer
3336 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3337 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3338 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3339 vkEndCommandBuffer(m_commandBuffer->handle());
3340
3341 // And submit on the wrong queue
3342 VkSubmitInfo submit_info = {};
3343 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3344 submit_info.commandBufferCount = 1;
3345 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003346 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003347
3348 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003349}
3350
Chris Forbes4c24a922016-11-16 08:59:10 +13003351TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3352 ASSERT_NO_FATAL_FAILURE(InitState());
3353
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003354 // There are no attachments, but refer to attachment 0.
3355 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003356 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003357 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003358 };
3359
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003360 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003361 VkRenderPass rp;
3362
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003363 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003365 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3366 m_errorMonitor->VerifyFound();
3367}
3368
Chris Forbesa58c4522016-09-28 15:19:39 +13003369TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3370 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3371 ASSERT_NO_FATAL_FAILURE(InitState());
3372
3373 // A renderpass with two subpasses, both writing the same attachment.
3374 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003375 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3376 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3377 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003378 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003379 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003380 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003381 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3382 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003383 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003384 VkSubpassDependency dep = {0,
3385 1,
3386 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3387 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3388 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3389 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3390 VK_DEPENDENCY_BY_REGION_BIT};
3391 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003392 VkRenderPass rp;
3393 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3394 ASSERT_VK_SUCCESS(err);
3395
3396 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003397 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 +13003398 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3399
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003400 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003401 VkFramebuffer fb;
3402 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3403 ASSERT_VK_SUCCESS(err);
3404
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003405 char const *vsSource =
3406 "#version 450\n"
3407 "void main() { gl_Position = vec4(1); }\n";
3408 char const *fsSource =
3409 "#version 450\n"
3410 "layout(location=0) out vec4 color;\n"
3411 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003412
3413 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3414 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3415 VkPipelineObj pipe(m_device);
3416 pipe.AddColorAttachment();
3417 pipe.AddShader(&vs);
3418 pipe.AddShader(&fs);
3419 VkViewport view_port = {};
3420 m_viewports.push_back(view_port);
3421 pipe.SetViewport(m_viewports);
3422 VkRect2D rect = {};
3423 m_scissors.push_back(rect);
3424 pipe.SetScissor(m_scissors);
3425
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003426 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003427 VkPipelineLayout pl;
3428 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3429 ASSERT_VK_SUCCESS(err);
3430 pipe.CreateVKPipeline(pl, rp);
3431
Tony Barbour552f6c02016-12-21 14:34:07 -07003432 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003433
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003434 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3435 nullptr,
3436 rp,
3437 fb,
3438 {{
3439 0, 0,
3440 },
3441 {32, 32}},
3442 0,
3443 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003444
3445 // subtest 1: bind in the wrong subpass
3446 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3447 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003448 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 +13003449 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3450 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3451 m_errorMonitor->VerifyFound();
3452
3453 vkCmdEndRenderPass(m_commandBuffer->handle());
3454
3455 // subtest 2: bind in correct subpass, then transition to next subpass
3456 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3457 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3458 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003459 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 +13003460 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3461 m_errorMonitor->VerifyFound();
3462
3463 vkCmdEndRenderPass(m_commandBuffer->handle());
3464
Tony Barbour552f6c02016-12-21 14:34:07 -07003465 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003466
3467 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3468 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3469 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3470}
3471
Tony Barbour4e919972016-08-09 13:27:40 -06003472TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003473 TEST_DESCRIPTION(
3474 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3475 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003476 ASSERT_NO_FATAL_FAILURE(InitState());
3477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3480 "Cannot execute a render pass with renderArea "
3481 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003482
3483 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3484 m_renderPassBeginInfo.renderArea.extent.width = 257;
3485 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003486 m_commandBuffer->BeginCommandBuffer();
3487 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003488 m_errorMonitor->VerifyFound();
3489}
3490
3491TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003492 TEST_DESCRIPTION(
3493 "Generate INDEPENDENT_BLEND by disabling independent "
3494 "blend and then specifying different blend states for two "
3495 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003496 VkPhysicalDeviceFeatures features = {};
3497 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003498 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003499
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3501 "Invalid Pipeline CreateInfo: If independent blend feature not "
3502 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003503
Cody Northropc31a84f2016-08-22 10:41:47 -06003504 VkDescriptorSetObj descriptorSet(m_device);
3505 descriptorSet.AppendDummy();
3506 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003507
Cody Northropc31a84f2016-08-22 10:41:47 -06003508 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003509 // Create a renderPass with two color attachments
3510 VkAttachmentReference attachments[2] = {};
3511 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3512 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3513
3514 VkSubpassDescription subpass = {};
3515 subpass.pColorAttachments = attachments;
3516 subpass.colorAttachmentCount = 2;
3517
3518 VkRenderPassCreateInfo rpci = {};
3519 rpci.subpassCount = 1;
3520 rpci.pSubpasses = &subpass;
3521 rpci.attachmentCount = 1;
3522
3523 VkAttachmentDescription attach_desc = {};
3524 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3525 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3526 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3527 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3528
3529 rpci.pAttachments = &attach_desc;
3530 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3531
3532 VkRenderPass renderpass;
3533 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003534 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003535 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003536
Cody Northropc31a84f2016-08-22 10:41:47 -06003537 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3538 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3539 att_state1.blendEnable = VK_TRUE;
3540 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3541 att_state2.blendEnable = VK_FALSE;
3542 pipeline.AddColorAttachment(0, &att_state1);
3543 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003544 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003545 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003546 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003547}
3548
Mike Weiblen40b160e2017-02-06 19:21:52 -07003549// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3550TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3551 TEST_DESCRIPTION(
3552 "Create a graphics pipeline that is incompatible with the requirements "
3553 "of its contained Renderpass/subpasses.");
3554 ASSERT_NO_FATAL_FAILURE(InitState());
3555
3556 VkDescriptorSetObj ds_obj(m_device);
3557 ds_obj.AppendDummy();
3558 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3559
3560 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3561
3562 VkPipelineColorBlendAttachmentState att_state1 = {};
3563 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3564 att_state1.blendEnable = VK_TRUE;
3565
3566 VkRenderpassObj rp_obj(m_device);
3567
3568 {
3569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3570 VkPipelineObj pipeline(m_device);
3571 pipeline.AddShader(&vs_obj);
3572 pipeline.AddColorAttachment(0, &att_state1);
3573
3574 VkGraphicsPipelineCreateInfo info = {};
3575 pipeline.InitGraphicsPipelineCreateInfo(&info);
3576 info.pColorBlendState = nullptr;
3577
3578 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3579 m_errorMonitor->VerifyFound();
3580 }
3581}
3582
Chris Forbes26ec2122016-11-29 08:58:33 +13003583#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003584TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3585 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3586 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003587 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3590 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003591
3592 // Create a renderPass with a single color attachment
3593 VkAttachmentReference attach = {};
3594 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3595 VkSubpassDescription subpass = {};
3596 VkRenderPassCreateInfo rpci = {};
3597 rpci.subpassCount = 1;
3598 rpci.pSubpasses = &subpass;
3599 rpci.attachmentCount = 1;
3600 VkAttachmentDescription attach_desc = {};
3601 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3602 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3603 rpci.pAttachments = &attach_desc;
3604 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3605 VkRenderPass rp;
3606 subpass.pDepthStencilAttachment = &attach;
3607 subpass.pColorAttachments = NULL;
3608 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3609 m_errorMonitor->VerifyFound();
3610}
Chris Forbes26ec2122016-11-29 08:58:33 +13003611#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003612
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003613TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003614 TEST_DESCRIPTION(
3615 "Create a framebuffer where a subpass has a preserve "
3616 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003617
3618 ASSERT_NO_FATAL_FAILURE(InitState());
3619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003622
3623 VkAttachmentReference color_attach = {};
3624 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3625 color_attach.attachment = 0;
3626 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3627 VkSubpassDescription subpass = {};
3628 subpass.colorAttachmentCount = 1;
3629 subpass.pColorAttachments = &color_attach;
3630 subpass.preserveAttachmentCount = 1;
3631 subpass.pPreserveAttachments = &preserve_attachment;
3632
3633 VkRenderPassCreateInfo rpci = {};
3634 rpci.subpassCount = 1;
3635 rpci.pSubpasses = &subpass;
3636 rpci.attachmentCount = 1;
3637 VkAttachmentDescription attach_desc = {};
3638 attach_desc.format = VK_FORMAT_UNDEFINED;
3639 rpci.pAttachments = &attach_desc;
3640 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3641 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003642 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003643
3644 m_errorMonitor->VerifyFound();
3645
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003646 if (result == VK_SUCCESS) {
3647 vkDestroyRenderPass(m_device->device(), rp, NULL);
3648 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003649}
3650
Chris Forbesc5389742016-06-29 11:49:23 +12003651TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003652 TEST_DESCRIPTION(
3653 "Ensure that CreateRenderPass produces a validation error "
3654 "when the source of a subpass multisample resolve "
3655 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003656
Chris Forbesc5389742016-06-29 11:49:23 +12003657 ASSERT_NO_FATAL_FAILURE(InitState());
3658
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3660 "Subpass 0 requests multisample resolve from attachment 0 which has "
3661 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003662
3663 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003664 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3665 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3666 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3667 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3668 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3669 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003670 };
3671
3672 VkAttachmentReference color = {
3673 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3674 };
3675
3676 VkAttachmentReference resolve = {
3677 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3678 };
3679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003681
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003682 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003683
3684 VkRenderPass rp;
3685 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3686
3687 m_errorMonitor->VerifyFound();
3688
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003689 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003690}
3691
3692TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003693 TEST_DESCRIPTION(
3694 "Ensure CreateRenderPass produces a validation error "
3695 "when a subpass multisample resolve operation is "
3696 "requested, and the destination of that resolve has "
3697 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003698
Chris Forbesc5389742016-06-29 11:49:23 +12003699 ASSERT_NO_FATAL_FAILURE(InitState());
3700
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3702 "Subpass 0 requests multisample resolve into attachment 1, which "
3703 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003704
3705 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003706 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3707 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3708 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3709 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3710 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3711 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003712 };
3713
3714 VkAttachmentReference color = {
3715 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3716 };
3717
3718 VkAttachmentReference resolve = {
3719 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3720 };
3721
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003722 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003725
3726 VkRenderPass rp;
3727 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3728
3729 m_errorMonitor->VerifyFound();
3730
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003731 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003732}
3733
Chris Forbes3f128ef2016-06-29 14:58:53 +12003734TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003735 TEST_DESCRIPTION(
3736 "Ensure CreateRenderPass produces a validation error "
3737 "when the color and depth attachments used by a subpass "
3738 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003739
Chris Forbes3f128ef2016-06-29 14:58:53 +12003740 ASSERT_NO_FATAL_FAILURE(InitState());
3741
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3743 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003744
3745 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003746 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3747 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3748 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3749 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3750 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3751 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003752 };
3753
3754 VkAttachmentReference color[] = {
3755 {
3756 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3757 },
3758 {
3759 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3760 },
3761 };
3762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003763 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003764
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003765 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003766
3767 VkRenderPass rp;
3768 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3769
3770 m_errorMonitor->VerifyFound();
3771
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003772 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003773}
3774
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003775TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003776 TEST_DESCRIPTION(
3777 "Hit errors when attempting to create a framebuffer :\n"
3778 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3779 " 2. Use a color image as depthStencil attachment\n"
3780 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3781 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3782 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3783 " 6. Framebuffer attachment where dimensions don't match\n"
3784 " 7. Framebuffer attachment w/o identity swizzle\n"
3785 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003786
3787 ASSERT_NO_FATAL_FAILURE(InitState());
3788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3791 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3792 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003793
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003794 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003795 VkAttachmentReference attach = {};
3796 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3797 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003798 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003799 VkRenderPassCreateInfo rpci = {};
3800 rpci.subpassCount = 1;
3801 rpci.pSubpasses = &subpass;
3802 rpci.attachmentCount = 1;
3803 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003804 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003805 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003806 rpci.pAttachments = &attach_desc;
3807 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3808 VkRenderPass rp;
3809 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3810 ASSERT_VK_SUCCESS(err);
3811
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003812 VkImageView ivs[2];
3813 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3814 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003815 VkFramebufferCreateInfo fb_info = {};
3816 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3817 fb_info.pNext = NULL;
3818 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003819 // Set mis-matching attachmentCount
3820 fb_info.attachmentCount = 2;
3821 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003822 fb_info.width = 100;
3823 fb_info.height = 100;
3824 fb_info.layers = 1;
3825
3826 VkFramebuffer fb;
3827 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3828
3829 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003830 if (err == VK_SUCCESS) {
3831 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3832 }
3833 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003834
3835 // Create a renderPass with a depth-stencil attachment created with
3836 // IMAGE_USAGE_COLOR_ATTACHMENT
3837 // Add our color attachment to pDepthStencilAttachment
3838 subpass.pDepthStencilAttachment = &attach;
3839 subpass.pColorAttachments = NULL;
3840 VkRenderPass rp_ds;
3841 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3842 ASSERT_VK_SUCCESS(err);
3843 // Set correct attachment count, but attachment has COLOR usage bit set
3844 fb_info.attachmentCount = 1;
3845 fb_info.renderPass = rp_ds;
3846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003848 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3849
3850 m_errorMonitor->VerifyFound();
3851 if (err == VK_SUCCESS) {
3852 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3853 }
3854 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003855
3856 // Create new renderpass with alternate attachment format from fb
3857 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3858 subpass.pDepthStencilAttachment = NULL;
3859 subpass.pColorAttachments = &attach;
3860 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3861 ASSERT_VK_SUCCESS(err);
3862
3863 // Cause error due to mis-matched formats between rp & fb
3864 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3865 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3867 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003868 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3869
3870 m_errorMonitor->VerifyFound();
3871 if (err == VK_SUCCESS) {
3872 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3873 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003874 vkDestroyRenderPass(m_device->device(), rp, NULL);
3875
3876 // Create new renderpass with alternate sample count from fb
3877 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3878 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3879 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3880 ASSERT_VK_SUCCESS(err);
3881
3882 // Cause error due to mis-matched sample count between rp & fb
3883 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3885 " has VK_SAMPLE_COUNT_1_BIT samples "
3886 "that do not match the "
3887 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003888 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3889
3890 m_errorMonitor->VerifyFound();
3891 if (err == VK_SUCCESS) {
3892 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3893 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003894
3895 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003896
3897 // Create a custom imageView with non-1 mip levels
3898 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003899 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 -06003900 ASSERT_TRUE(image.initialized());
3901
3902 VkImageView view;
3903 VkImageViewCreateInfo ivci = {};
3904 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3905 ivci.image = image.handle();
3906 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3907 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3908 ivci.subresourceRange.layerCount = 1;
3909 ivci.subresourceRange.baseMipLevel = 0;
3910 // Set level count 2 (only 1 is allowed for FB attachment)
3911 ivci.subresourceRange.levelCount = 2;
3912 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3913 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3914 ASSERT_VK_SUCCESS(err);
3915 // Re-create renderpass to have matching sample count
3916 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3917 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3918 ASSERT_VK_SUCCESS(err);
3919
3920 fb_info.renderPass = rp;
3921 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003923 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3924
3925 m_errorMonitor->VerifyFound();
3926 if (err == VK_SUCCESS) {
3927 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3928 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003929 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003930 // Update view to original color buffer and grow FB dimensions too big
3931 fb_info.pAttachments = ivs;
3932 fb_info.height = 1024;
3933 fb_info.width = 1024;
3934 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3936 " Attachment dimensions must be at "
3937 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003938 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3939
3940 m_errorMonitor->VerifyFound();
3941 if (err == VK_SUCCESS) {
3942 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3943 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003944 // Create view attachment with non-identity swizzle
3945 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3946 ivci.image = image.handle();
3947 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3948 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3949 ivci.subresourceRange.layerCount = 1;
3950 ivci.subresourceRange.baseMipLevel = 0;
3951 ivci.subresourceRange.levelCount = 1;
3952 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3953 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3954 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3955 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3956 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3957 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3958 ASSERT_VK_SUCCESS(err);
3959
3960 fb_info.pAttachments = &view;
3961 fb_info.height = 100;
3962 fb_info.width = 100;
3963 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3965 " has non-identy swizzle. All "
3966 "framebuffer attachments must have "
3967 "been created with the identity "
3968 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003969 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3970
3971 m_errorMonitor->VerifyFound();
3972 if (err == VK_SUCCESS) {
3973 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3974 }
3975 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003976 // reset attachment to color attachment
3977 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003978
3979 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003980 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003981 fb_info.height = 100;
3982 fb_info.layers = 1;
3983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003984 m_errorMonitor->SetUnexpectedError(
3985 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
3986 "Here are the respective dimensions for attachment");
3987
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003988 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3989
3990 m_errorMonitor->VerifyFound();
3991 if (err == VK_SUCCESS) {
3992 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3993 }
3994
3995 // Request fb that exceeds max height
3996 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003997 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003998 fb_info.layers = 1;
3999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004000 m_errorMonitor->SetUnexpectedError(
4001 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4002 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004003 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4004
4005 m_errorMonitor->VerifyFound();
4006 if (err == VK_SUCCESS) {
4007 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4008 }
4009
4010 // Request fb that exceeds max layers
4011 fb_info.width = 100;
4012 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004013 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004015 m_errorMonitor->SetUnexpectedError(
4016 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4017 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004018 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4019
4020 m_errorMonitor->VerifyFound();
4021 if (err == VK_SUCCESS) {
4022 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4023 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004024
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004025 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004026}
4027
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004028TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004029 TEST_DESCRIPTION(
4030 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4031 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004032
Cody Northropc31a84f2016-08-22 10:41:47 -06004033 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004034 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4036 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004037 m_errorMonitor->VerifyFound();
4038}
4039
4040TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004041 TEST_DESCRIPTION(
4042 "Run a simple draw calls to validate failure when Line Width dynamic "
4043 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004044
Cody Northropc31a84f2016-08-22 10:41:47 -06004045 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004046 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4048 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004049 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004050}
4051
4052TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004053 TEST_DESCRIPTION(
4054 "Run a simple draw calls to validate failure when Viewport dynamic "
4055 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004056
Cody Northropc31a84f2016-08-22 10:41:47 -06004057 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004058 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4060 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004061 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004062 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004063}
4064
4065TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004066 TEST_DESCRIPTION(
4067 "Run a simple draw calls to validate failure when Scissor dynamic "
4068 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004069
Cody Northropc31a84f2016-08-22 10:41:47 -06004070 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004071 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4073 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004074 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004075 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004076}
4077
Cortd713fe82016-07-27 09:51:27 -07004078TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004079 TEST_DESCRIPTION(
4080 "Run a simple draw calls to validate failure when Blend Constants "
4081 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004082
4083 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004084 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4086 "Dynamic blend constants state not set for this command buffer");
4087 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004088 m_errorMonitor->VerifyFound();
4089}
4090
4091TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004092 TEST_DESCRIPTION(
4093 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4094 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004095
4096 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004097 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004098 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004099 return;
4100 }
4101 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4103 "Dynamic depth bounds state not set for this command buffer");
4104 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004105 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004106}
4107
4108TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004109 TEST_DESCRIPTION(
4110 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4111 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004112
4113 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004114 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4116 "Dynamic stencil read mask state not set for this command buffer");
4117 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004118 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004119}
4120
4121TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004122 TEST_DESCRIPTION(
4123 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4124 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004125
4126 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004127 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4129 "Dynamic stencil write mask state not set for this command buffer");
4130 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004131 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004132}
4133
4134TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004135 TEST_DESCRIPTION(
4136 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4137 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004138
4139 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004140 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4142 "Dynamic stencil reference state not set for this command buffer");
4143 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004144 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004145}
4146
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004147TEST_F(VkLayerTest, IndexBufferNotBound) {
4148 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004149
4150 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4152 "Index buffer object not bound to this command buffer when Indexed ");
4153 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004154 m_errorMonitor->VerifyFound();
4155}
4156
Karl Schultz6addd812016-02-02 17:17:23 -07004157TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4159 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4160 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004161
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004162 ASSERT_NO_FATAL_FAILURE(InitState());
4163 ASSERT_NO_FATAL_FAILURE(InitViewport());
4164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4165
Karl Schultz6addd812016-02-02 17:17:23 -07004166 // We luck out b/c by default the framework creates CB w/ the
4167 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004168 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004169 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004170 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004171
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004172 // Bypass framework since it does the waits automatically
4173 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004174 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004175 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4176 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004177 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004178 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004179 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004180 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004181 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004182 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004183 submit_info.pSignalSemaphores = NULL;
4184
Chris Forbes40028e22016-06-13 09:59:34 +12004185 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004186 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004187 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004188
Karl Schultz6addd812016-02-02 17:17:23 -07004189 // Cause validation error by re-submitting cmd buffer that should only be
4190 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004191 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004192 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004193
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004194 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004195}
4196
Karl Schultz6addd812016-02-02 17:17:23 -07004197TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004198 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004199 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004200
4201 ASSERT_NO_FATAL_FAILURE(InitState());
4202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004203
Karl Schultz6addd812016-02-02 17:17:23 -07004204 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4205 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004206 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004207 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004208 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004209
4210 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004211 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4212 ds_pool_ci.pNext = NULL;
4213 ds_pool_ci.flags = 0;
4214 ds_pool_ci.maxSets = 1;
4215 ds_pool_ci.poolSizeCount = 1;
4216 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004217
4218 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004219 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004220 ASSERT_VK_SUCCESS(err);
4221
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004222 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4223 dsl_binding_samp.binding = 0;
4224 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4225 dsl_binding_samp.descriptorCount = 1;
4226 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4227 dsl_binding_samp.pImmutableSamplers = NULL;
4228
4229 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4230 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4231 ds_layout_ci.pNext = NULL;
4232 ds_layout_ci.bindingCount = 1;
4233 ds_layout_ci.pBindings = &dsl_binding_samp;
4234
4235 VkDescriptorSetLayout ds_layout_samp;
4236 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4237 ASSERT_VK_SUCCESS(err);
4238
4239 // Try to allocate 2 sets when pool only has 1 set
4240 VkDescriptorSet descriptor_sets[2];
4241 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4242 VkDescriptorSetAllocateInfo alloc_info = {};
4243 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4244 alloc_info.descriptorSetCount = 2;
4245 alloc_info.descriptorPool = ds_pool;
4246 alloc_info.pSetLayouts = set_layouts;
4247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4248 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4249 m_errorMonitor->VerifyFound();
4250
4251 alloc_info.descriptorSetCount = 1;
4252 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004253 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004254 dsl_binding.binding = 0;
4255 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4256 dsl_binding.descriptorCount = 1;
4257 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4258 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004259
Karl Schultz6addd812016-02-02 17:17:23 -07004260 ds_layout_ci.bindingCount = 1;
4261 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004262
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004263 VkDescriptorSetLayout ds_layout_ub;
4264 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004265 ASSERT_VK_SUCCESS(err);
4266
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004267 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004268 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004269 alloc_info.pSetLayouts = &ds_layout_ub;
4270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4271 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004272
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004273 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004274
Karl Schultz2825ab92016-12-02 08:23:14 -07004275 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004276 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004277 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004278}
4279
Karl Schultz6addd812016-02-02 17:17:23 -07004280TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4281 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004282
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004284
Tobin Ehlise735c692015-10-08 13:13:50 -06004285 ASSERT_NO_FATAL_FAILURE(InitState());
4286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004287
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004288 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004289 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4290 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004291
4292 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004293 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4294 ds_pool_ci.pNext = NULL;
4295 ds_pool_ci.maxSets = 1;
4296 ds_pool_ci.poolSizeCount = 1;
4297 ds_pool_ci.flags = 0;
4298 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4299 // app can only call vkResetDescriptorPool on this pool.;
4300 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004301
4302 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004303 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004304 ASSERT_VK_SUCCESS(err);
4305
4306 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004307 dsl_binding.binding = 0;
4308 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4309 dsl_binding.descriptorCount = 1;
4310 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4311 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004312
4313 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004314 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4315 ds_layout_ci.pNext = NULL;
4316 ds_layout_ci.bindingCount = 1;
4317 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004318
4319 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004320 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004321 ASSERT_VK_SUCCESS(err);
4322
4323 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004324 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004325 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004326 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004327 alloc_info.descriptorPool = ds_pool;
4328 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004329 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004330 ASSERT_VK_SUCCESS(err);
4331
4332 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004333 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004334
Chia-I Wuf7458c52015-10-26 21:10:41 +08004335 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4336 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004337}
4338
Karl Schultz6addd812016-02-02 17:17:23 -07004339TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004340 // Attempt to clear Descriptor Pool with bad object.
4341 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004342
4343 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004345 uint64_t fake_pool_handle = 0xbaad6001;
4346 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4347 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004348 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004349}
4350
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004351TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004352 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4353 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004354 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004355 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004356
4357 uint64_t fake_set_handle = 0xbaad6001;
4358 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004359 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004361
4362 ASSERT_NO_FATAL_FAILURE(InitState());
4363
4364 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4365 layout_bindings[0].binding = 0;
4366 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4367 layout_bindings[0].descriptorCount = 1;
4368 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4369 layout_bindings[0].pImmutableSamplers = NULL;
4370
4371 VkDescriptorSetLayout descriptor_set_layout;
4372 VkDescriptorSetLayoutCreateInfo dslci = {};
4373 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4374 dslci.pNext = NULL;
4375 dslci.bindingCount = 1;
4376 dslci.pBindings = layout_bindings;
4377 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004378 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004379
4380 VkPipelineLayout pipeline_layout;
4381 VkPipelineLayoutCreateInfo plci = {};
4382 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4383 plci.pNext = NULL;
4384 plci.setLayoutCount = 1;
4385 plci.pSetLayouts = &descriptor_set_layout;
4386 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004387 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004388
Tony Barbour552f6c02016-12-21 14:34:07 -07004389 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004390 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4391 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004392 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004393 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004394 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4395 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004396}
4397
Karl Schultz6addd812016-02-02 17:17:23 -07004398TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004399 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4400 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004401 uint64_t fake_layout_handle = 0xbaad6001;
4402 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004404 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004405 VkPipelineLayout pipeline_layout;
4406 VkPipelineLayoutCreateInfo plci = {};
4407 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4408 plci.pNext = NULL;
4409 plci.setLayoutCount = 1;
4410 plci.pSetLayouts = &bad_layout;
4411 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4412
4413 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004414}
4415
Mark Muellerd4914412016-06-13 17:52:06 -06004416TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004417 TEST_DESCRIPTION(
4418 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4419 "1) A uniform buffer update must have a valid buffer index."
4420 "2) When using an array of descriptors in a single WriteDescriptor,"
4421 " the descriptor types and stageflags must all be the same."
4422 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004423
Mike Weiblena6666382017-01-05 15:16:11 -07004424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004425
4426 ASSERT_NO_FATAL_FAILURE(InitState());
4427 VkDescriptorPoolSize ds_type_count[4] = {};
4428 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4429 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004430 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004431 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004432 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004433 ds_type_count[2].descriptorCount = 1;
4434 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4435 ds_type_count[3].descriptorCount = 1;
4436
4437 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4438 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4439 ds_pool_ci.maxSets = 1;
4440 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4441 ds_pool_ci.pPoolSizes = ds_type_count;
4442
4443 VkDescriptorPool ds_pool;
4444 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4445 ASSERT_VK_SUCCESS(err);
4446
Mark Muellerb9896722016-06-16 09:54:29 -06004447 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004448 layout_binding[0].binding = 0;
4449 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4450 layout_binding[0].descriptorCount = 1;
4451 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4452 layout_binding[0].pImmutableSamplers = NULL;
4453
4454 layout_binding[1].binding = 1;
4455 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4456 layout_binding[1].descriptorCount = 1;
4457 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4458 layout_binding[1].pImmutableSamplers = NULL;
4459
4460 VkSamplerCreateInfo sampler_ci = {};
4461 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4462 sampler_ci.pNext = NULL;
4463 sampler_ci.magFilter = VK_FILTER_NEAREST;
4464 sampler_ci.minFilter = VK_FILTER_NEAREST;
4465 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4466 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4467 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4468 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4469 sampler_ci.mipLodBias = 1.0;
4470 sampler_ci.anisotropyEnable = VK_FALSE;
4471 sampler_ci.maxAnisotropy = 1;
4472 sampler_ci.compareEnable = VK_FALSE;
4473 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4474 sampler_ci.minLod = 1.0;
4475 sampler_ci.maxLod = 1.0;
4476 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4477 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4478 VkSampler sampler;
4479
4480 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4481 ASSERT_VK_SUCCESS(err);
4482
4483 layout_binding[2].binding = 2;
4484 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4485 layout_binding[2].descriptorCount = 1;
4486 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4487 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4488
Mark Muellerd4914412016-06-13 17:52:06 -06004489 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4490 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4491 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4492 ds_layout_ci.pBindings = layout_binding;
4493 VkDescriptorSetLayout ds_layout;
4494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4495 ASSERT_VK_SUCCESS(err);
4496
4497 VkDescriptorSetAllocateInfo alloc_info = {};
4498 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4499 alloc_info.descriptorSetCount = 1;
4500 alloc_info.descriptorPool = ds_pool;
4501 alloc_info.pSetLayouts = &ds_layout;
4502 VkDescriptorSet descriptorSet;
4503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4504 ASSERT_VK_SUCCESS(err);
4505
4506 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4507 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4508 pipeline_layout_ci.pNext = NULL;
4509 pipeline_layout_ci.setLayoutCount = 1;
4510 pipeline_layout_ci.pSetLayouts = &ds_layout;
4511
4512 VkPipelineLayout pipeline_layout;
4513 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4514 ASSERT_VK_SUCCESS(err);
4515
Mark Mueller5c838ce2016-06-16 09:54:29 -06004516 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004517 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4518 descriptor_write.dstSet = descriptorSet;
4519 descriptor_write.dstBinding = 0;
4520 descriptor_write.descriptorCount = 1;
4521 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4522
Mark Mueller5c838ce2016-06-16 09:54:29 -06004523 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004524 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4525 m_errorMonitor->VerifyFound();
4526
4527 // Create a buffer to update the descriptor with
4528 uint32_t qfi = 0;
4529 VkBufferCreateInfo buffCI = {};
4530 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4531 buffCI.size = 1024;
4532 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4533 buffCI.queueFamilyIndexCount = 1;
4534 buffCI.pQueueFamilyIndices = &qfi;
4535
4536 VkBuffer dyub;
4537 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4538 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004539
Tony Barboure132c5f2016-12-12 11:50:20 -07004540 VkDeviceMemory mem;
4541 VkMemoryRequirements mem_reqs;
4542 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4543
4544 VkMemoryAllocateInfo mem_alloc_info = {};
4545 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4546 mem_alloc_info.allocationSize = mem_reqs.size;
4547 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4548 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4549 ASSERT_VK_SUCCESS(err);
4550
4551 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4552 ASSERT_VK_SUCCESS(err);
4553
4554 VkDescriptorBufferInfo buffInfo[2] = {};
4555 buffInfo[0].buffer = dyub;
4556 buffInfo[0].offset = 0;
4557 buffInfo[0].range = 1024;
4558 buffInfo[1].buffer = dyub;
4559 buffInfo[1].offset = 0;
4560 buffInfo[1].range = 1024;
4561 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004562 descriptor_write.descriptorCount = 2;
4563
Mark Mueller5c838ce2016-06-16 09:54:29 -06004564 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004566 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4567 m_errorMonitor->VerifyFound();
4568
Mark Mueller5c838ce2016-06-16 09:54:29 -06004569 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4570 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004571 descriptor_write.dstBinding = 1;
4572 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004573
Mark Mueller5c838ce2016-06-16 09:54:29 -06004574 // Make pImageInfo index non-null to avoid complaints of it missing
4575 VkDescriptorImageInfo imageInfo = {};
4576 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4577 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004579 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4580 m_errorMonitor->VerifyFound();
4581
Mark Muellerd4914412016-06-13 17:52:06 -06004582 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004583 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004584 vkDestroySampler(m_device->device(), sampler, NULL);
4585 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4586 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4587 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4588}
4589
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004590TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004591 TEST_DESCRIPTION(
4592 "Attempt to draw with a command buffer that is invalid "
4593 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004594 ASSERT_NO_FATAL_FAILURE(InitState());
4595
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004596 VkBuffer buffer;
4597 VkDeviceMemory mem;
4598 VkMemoryRequirements mem_reqs;
4599
4600 VkBufferCreateInfo buf_info = {};
4601 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004602 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004603 buf_info.size = 256;
4604 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4605 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4606 ASSERT_VK_SUCCESS(err);
4607
4608 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4609
4610 VkMemoryAllocateInfo alloc_info = {};
4611 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4612 alloc_info.allocationSize = 256;
4613 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004614 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 -06004615 if (!pass) {
4616 vkDestroyBuffer(m_device->device(), buffer, NULL);
4617 return;
4618 }
4619 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4620 ASSERT_VK_SUCCESS(err);
4621
4622 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4623 ASSERT_VK_SUCCESS(err);
4624
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004625 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004626 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004627 m_commandBuffer->EndCommandBuffer();
4628
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004630 // Destroy buffer dependency prior to submit to cause ERROR
4631 vkDestroyBuffer(m_device->device(), buffer, NULL);
4632
4633 VkSubmitInfo submit_info = {};
4634 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4635 submit_info.commandBufferCount = 1;
4636 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004637 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004638 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4639
4640 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004641 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004642 vkFreeMemory(m_device->handle(), mem, NULL);
4643}
4644
Tobin Ehlisea413442016-09-28 10:23:59 -06004645TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4646 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4647
4648 ASSERT_NO_FATAL_FAILURE(InitState());
4649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4650
4651 VkDescriptorPoolSize ds_type_count;
4652 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4653 ds_type_count.descriptorCount = 1;
4654
4655 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4656 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4657 ds_pool_ci.maxSets = 1;
4658 ds_pool_ci.poolSizeCount = 1;
4659 ds_pool_ci.pPoolSizes = &ds_type_count;
4660
4661 VkDescriptorPool ds_pool;
4662 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4663 ASSERT_VK_SUCCESS(err);
4664
4665 VkDescriptorSetLayoutBinding layout_binding;
4666 layout_binding.binding = 0;
4667 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4668 layout_binding.descriptorCount = 1;
4669 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4670 layout_binding.pImmutableSamplers = NULL;
4671
4672 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4673 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4674 ds_layout_ci.bindingCount = 1;
4675 ds_layout_ci.pBindings = &layout_binding;
4676 VkDescriptorSetLayout ds_layout;
4677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4678 ASSERT_VK_SUCCESS(err);
4679
4680 VkDescriptorSetAllocateInfo alloc_info = {};
4681 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4682 alloc_info.descriptorSetCount = 1;
4683 alloc_info.descriptorPool = ds_pool;
4684 alloc_info.pSetLayouts = &ds_layout;
4685 VkDescriptorSet descriptor_set;
4686 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4687 ASSERT_VK_SUCCESS(err);
4688
4689 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4690 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4691 pipeline_layout_ci.pNext = NULL;
4692 pipeline_layout_ci.setLayoutCount = 1;
4693 pipeline_layout_ci.pSetLayouts = &ds_layout;
4694
4695 VkPipelineLayout pipeline_layout;
4696 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4697 ASSERT_VK_SUCCESS(err);
4698
4699 VkBuffer buffer;
4700 uint32_t queue_family_index = 0;
4701 VkBufferCreateInfo buffer_create_info = {};
4702 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4703 buffer_create_info.size = 1024;
4704 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4705 buffer_create_info.queueFamilyIndexCount = 1;
4706 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4707
4708 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4709 ASSERT_VK_SUCCESS(err);
4710
4711 VkMemoryRequirements memory_reqs;
4712 VkDeviceMemory buffer_memory;
4713
4714 VkMemoryAllocateInfo memory_info = {};
4715 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4716 memory_info.allocationSize = 0;
4717 memory_info.memoryTypeIndex = 0;
4718
4719 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4720 memory_info.allocationSize = memory_reqs.size;
4721 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4722 ASSERT_TRUE(pass);
4723
4724 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4725 ASSERT_VK_SUCCESS(err);
4726 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4727 ASSERT_VK_SUCCESS(err);
4728
4729 VkBufferView view;
4730 VkBufferViewCreateInfo bvci = {};
4731 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4732 bvci.buffer = buffer;
4733 bvci.format = VK_FORMAT_R8_UNORM;
4734 bvci.range = VK_WHOLE_SIZE;
4735
4736 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4737 ASSERT_VK_SUCCESS(err);
4738
4739 VkWriteDescriptorSet descriptor_write = {};
4740 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4741 descriptor_write.dstSet = descriptor_set;
4742 descriptor_write.dstBinding = 0;
4743 descriptor_write.descriptorCount = 1;
4744 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4745 descriptor_write.pTexelBufferView = &view;
4746
4747 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4748
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004749 char const *vsSource =
4750 "#version 450\n"
4751 "\n"
4752 "out gl_PerVertex { \n"
4753 " vec4 gl_Position;\n"
4754 "};\n"
4755 "void main(){\n"
4756 " gl_Position = vec4(1);\n"
4757 "}\n";
4758 char const *fsSource =
4759 "#version 450\n"
4760 "\n"
4761 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4762 "layout(location=0) out vec4 x;\n"
4763 "void main(){\n"
4764 " x = imageLoad(s, 0);\n"
4765 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004766 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4767 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4768 VkPipelineObj pipe(m_device);
4769 pipe.AddShader(&vs);
4770 pipe.AddShader(&fs);
4771 pipe.AddColorAttachment();
4772 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4773
4774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4776
Tony Barbour552f6c02016-12-21 14:34:07 -07004777 m_commandBuffer->BeginCommandBuffer();
4778 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4779
Tobin Ehlisea413442016-09-28 10:23:59 -06004780 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4781 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4782 VkRect2D scissor = {{0, 0}, {16, 16}};
4783 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4784 // Bind pipeline to cmd buffer
4785 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4786 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4787 &descriptor_set, 0, nullptr);
4788 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004789 m_commandBuffer->EndRenderPass();
4790 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004791
4792 // Delete BufferView in order to invalidate cmd buffer
4793 vkDestroyBufferView(m_device->device(), view, NULL);
4794 // Now attempt submit of cmd buffer
4795 VkSubmitInfo submit_info = {};
4796 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4797 submit_info.commandBufferCount = 1;
4798 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4799 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4800 m_errorMonitor->VerifyFound();
4801
4802 // Clean-up
4803 vkDestroyBuffer(m_device->device(), buffer, NULL);
4804 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4805 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4806 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4807 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4808}
4809
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004810TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004811 TEST_DESCRIPTION(
4812 "Attempt to draw with a command buffer that is invalid "
4813 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004814 ASSERT_NO_FATAL_FAILURE(InitState());
4815
4816 VkImage image;
4817 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4818 VkImageCreateInfo image_create_info = {};
4819 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4820 image_create_info.pNext = NULL;
4821 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4822 image_create_info.format = tex_format;
4823 image_create_info.extent.width = 32;
4824 image_create_info.extent.height = 32;
4825 image_create_info.extent.depth = 1;
4826 image_create_info.mipLevels = 1;
4827 image_create_info.arrayLayers = 1;
4828 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4829 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004830 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004831 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004832 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004833 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004834 // Have to bind memory to image before recording cmd in cmd buffer using it
4835 VkMemoryRequirements mem_reqs;
4836 VkDeviceMemory image_mem;
4837 bool pass;
4838 VkMemoryAllocateInfo mem_alloc = {};
4839 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4840 mem_alloc.pNext = NULL;
4841 mem_alloc.memoryTypeIndex = 0;
4842 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4843 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004844 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004845 ASSERT_TRUE(pass);
4846 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4847 ASSERT_VK_SUCCESS(err);
4848 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4849 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004850
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004851 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004852 VkClearColorValue ccv;
4853 ccv.float32[0] = 1.0f;
4854 ccv.float32[1] = 1.0f;
4855 ccv.float32[2] = 1.0f;
4856 ccv.float32[3] = 1.0f;
4857 VkImageSubresourceRange isr = {};
4858 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004859 isr.baseArrayLayer = 0;
4860 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004861 isr.layerCount = 1;
4862 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004864 m_commandBuffer->EndCommandBuffer();
4865
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004867 // Destroy image dependency prior to submit to cause ERROR
4868 vkDestroyImage(m_device->device(), image, NULL);
4869
4870 VkSubmitInfo submit_info = {};
4871 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4872 submit_info.commandBufferCount = 1;
4873 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004874 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004875 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4876
4877 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004878 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004879}
4880
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004881TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004882 TEST_DESCRIPTION(
4883 "Attempt to draw with a command buffer that is invalid "
4884 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004885 VkFormatProperties format_properties;
4886 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4888 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004889 return;
4890 }
4891
4892 ASSERT_NO_FATAL_FAILURE(InitState());
4893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4894
4895 VkImageCreateInfo image_ci = {};
4896 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4897 image_ci.pNext = NULL;
4898 image_ci.imageType = VK_IMAGE_TYPE_2D;
4899 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4900 image_ci.extent.width = 32;
4901 image_ci.extent.height = 32;
4902 image_ci.extent.depth = 1;
4903 image_ci.mipLevels = 1;
4904 image_ci.arrayLayers = 1;
4905 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4906 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004907 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004908 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4909 image_ci.flags = 0;
4910 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004912
4913 VkMemoryRequirements memory_reqs;
4914 VkDeviceMemory image_memory;
4915 bool pass;
4916 VkMemoryAllocateInfo memory_info = {};
4917 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4918 memory_info.pNext = NULL;
4919 memory_info.allocationSize = 0;
4920 memory_info.memoryTypeIndex = 0;
4921 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4922 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004923 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004924 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004925 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004926 ASSERT_VK_SUCCESS(err);
4927 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4928 ASSERT_VK_SUCCESS(err);
4929
4930 VkImageViewCreateInfo ivci = {
4931 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4932 nullptr,
4933 0,
4934 image,
4935 VK_IMAGE_VIEW_TYPE_2D,
4936 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004937 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004938 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4939 };
4940 VkImageView view;
4941 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4942 ASSERT_VK_SUCCESS(err);
4943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004944 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004945 VkFramebuffer fb;
4946 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4947 ASSERT_VK_SUCCESS(err);
4948
4949 // Just use default renderpass with our framebuffer
4950 m_renderPassBeginInfo.framebuffer = fb;
4951 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004952 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004953 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07004954 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4955 m_commandBuffer->EndRenderPass();
4956 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004957 // Destroy image attached to framebuffer to invalidate cmd buffer
4958 vkDestroyImage(m_device->device(), image, NULL);
4959 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004961 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004962 QueueCommandBuffer(false);
4963 m_errorMonitor->VerifyFound();
4964
4965 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4966 vkDestroyImageView(m_device->device(), view, nullptr);
4967 vkFreeMemory(m_device->device(), image_memory, nullptr);
4968}
4969
Tobin Ehlisb329f992016-10-12 13:20:29 -06004970TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4971 TEST_DESCRIPTION("Delete in-use framebuffer.");
4972 VkFormatProperties format_properties;
4973 VkResult err = VK_SUCCESS;
4974 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4975
4976 ASSERT_NO_FATAL_FAILURE(InitState());
4977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4978
4979 VkImageObj image(m_device);
4980 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4981 ASSERT_TRUE(image.initialized());
4982 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4983
4984 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4985 VkFramebuffer fb;
4986 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4987 ASSERT_VK_SUCCESS(err);
4988
4989 // Just use default renderpass with our framebuffer
4990 m_renderPassBeginInfo.framebuffer = fb;
4991 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004992 m_commandBuffer->BeginCommandBuffer();
4993 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4994 m_commandBuffer->EndRenderPass();
4995 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004996 // Submit cmd buffer to put it in-flight
4997 VkSubmitInfo submit_info = {};
4998 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4999 submit_info.commandBufferCount = 1;
5000 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5001 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5002 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005004 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5005 m_errorMonitor->VerifyFound();
5006 // Wait for queue to complete so we can safely destroy everything
5007 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005008 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5009 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005010 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5011}
5012
Tobin Ehlis88becd72016-09-21 14:33:41 -06005013TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5014 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5015 VkFormatProperties format_properties;
5016 VkResult err = VK_SUCCESS;
5017 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005018
5019 ASSERT_NO_FATAL_FAILURE(InitState());
5020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5021
5022 VkImageCreateInfo image_ci = {};
5023 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5024 image_ci.pNext = NULL;
5025 image_ci.imageType = VK_IMAGE_TYPE_2D;
5026 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5027 image_ci.extent.width = 256;
5028 image_ci.extent.height = 256;
5029 image_ci.extent.depth = 1;
5030 image_ci.mipLevels = 1;
5031 image_ci.arrayLayers = 1;
5032 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5033 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005034 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005035 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5036 image_ci.flags = 0;
5037 VkImage image;
5038 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5039
5040 VkMemoryRequirements memory_reqs;
5041 VkDeviceMemory image_memory;
5042 bool pass;
5043 VkMemoryAllocateInfo memory_info = {};
5044 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5045 memory_info.pNext = NULL;
5046 memory_info.allocationSize = 0;
5047 memory_info.memoryTypeIndex = 0;
5048 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5049 memory_info.allocationSize = memory_reqs.size;
5050 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5051 ASSERT_TRUE(pass);
5052 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5053 ASSERT_VK_SUCCESS(err);
5054 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5055 ASSERT_VK_SUCCESS(err);
5056
5057 VkImageViewCreateInfo ivci = {
5058 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5059 nullptr,
5060 0,
5061 image,
5062 VK_IMAGE_VIEW_TYPE_2D,
5063 VK_FORMAT_B8G8R8A8_UNORM,
5064 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5065 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5066 };
5067 VkImageView view;
5068 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5069 ASSERT_VK_SUCCESS(err);
5070
5071 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5072 VkFramebuffer fb;
5073 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5074 ASSERT_VK_SUCCESS(err);
5075
5076 // Just use default renderpass with our framebuffer
5077 m_renderPassBeginInfo.framebuffer = fb;
5078 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005079 m_commandBuffer->BeginCommandBuffer();
5080 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5081 m_commandBuffer->EndRenderPass();
5082 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005083 // Submit cmd buffer to put it (and attached imageView) in-flight
5084 VkSubmitInfo submit_info = {};
5085 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5086 submit_info.commandBufferCount = 1;
5087 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5088 // Submit cmd buffer to put framebuffer and children in-flight
5089 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5090 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005092 vkDestroyImage(m_device->device(), image, NULL);
5093 m_errorMonitor->VerifyFound();
5094 // Wait for queue to complete so we can safely destroy image and other objects
5095 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005096 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5097 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005098 vkDestroyImage(m_device->device(), image, NULL);
5099 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5100 vkDestroyImageView(m_device->device(), view, nullptr);
5101 vkFreeMemory(m_device->device(), image_memory, nullptr);
5102}
5103
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005104TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5105 TEST_DESCRIPTION("Delete in-use renderPass.");
5106
5107 ASSERT_NO_FATAL_FAILURE(InitState());
5108 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5109
5110 // Create simple renderpass
5111 VkAttachmentReference attach = {};
5112 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5113 VkSubpassDescription subpass = {};
5114 subpass.pColorAttachments = &attach;
5115 VkRenderPassCreateInfo rpci = {};
5116 rpci.subpassCount = 1;
5117 rpci.pSubpasses = &subpass;
5118 rpci.attachmentCount = 1;
5119 VkAttachmentDescription attach_desc = {};
5120 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5121 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5122 rpci.pAttachments = &attach_desc;
5123 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5124 VkRenderPass rp;
5125 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5126 ASSERT_VK_SUCCESS(err);
5127
5128 // Create a pipeline that uses the given renderpass
5129 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5130 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5131
5132 VkPipelineLayout pipeline_layout;
5133 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5134 ASSERT_VK_SUCCESS(err);
5135
5136 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5137 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5138 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005139 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005140 vp_state_ci.pViewports = &vp;
5141 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005142 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005143 vp_state_ci.pScissors = &scissors;
5144
5145 VkPipelineShaderStageCreateInfo shaderStages[2];
5146 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5147
5148 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005149 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 -06005150 // but add it to be able to run on more devices
5151 shaderStages[0] = vs.GetStageCreateInfo();
5152 shaderStages[1] = fs.GetStageCreateInfo();
5153
5154 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5155 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5156
5157 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5158 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5159 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5160
5161 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5162 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5163 rs_ci.rasterizerDiscardEnable = true;
5164 rs_ci.lineWidth = 1.0f;
5165
5166 VkPipelineColorBlendAttachmentState att = {};
5167 att.blendEnable = VK_FALSE;
5168 att.colorWriteMask = 0xf;
5169
5170 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5171 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5172 cb_ci.attachmentCount = 1;
5173 cb_ci.pAttachments = &att;
5174
5175 VkGraphicsPipelineCreateInfo gp_ci = {};
5176 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5177 gp_ci.stageCount = 2;
5178 gp_ci.pStages = shaderStages;
5179 gp_ci.pVertexInputState = &vi_ci;
5180 gp_ci.pInputAssemblyState = &ia_ci;
5181 gp_ci.pViewportState = &vp_state_ci;
5182 gp_ci.pRasterizationState = &rs_ci;
5183 gp_ci.pColorBlendState = &cb_ci;
5184 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5185 gp_ci.layout = pipeline_layout;
5186 gp_ci.renderPass = rp;
5187
5188 VkPipelineCacheCreateInfo pc_ci = {};
5189 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5190
5191 VkPipeline pipeline;
5192 VkPipelineCache pipe_cache;
5193 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5194 ASSERT_VK_SUCCESS(err);
5195
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005196 m_errorMonitor->SetUnexpectedError(
5197 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5198 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005199 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5200 ASSERT_VK_SUCCESS(err);
5201 // Bind pipeline to cmd buffer, will also bind renderpass
5202 m_commandBuffer->BeginCommandBuffer();
5203 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5204 m_commandBuffer->EndCommandBuffer();
5205
5206 VkSubmitInfo submit_info = {};
5207 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5208 submit_info.commandBufferCount = 1;
5209 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5210 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5211
5212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5213 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5214 m_errorMonitor->VerifyFound();
5215
5216 // Wait for queue to complete so we can safely destroy everything
5217 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005218 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5219 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005220 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5221 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5222 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5223 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5224}
5225
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005226TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005227 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005228 ASSERT_NO_FATAL_FAILURE(InitState());
5229
5230 VkImage image;
5231 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5232 VkImageCreateInfo image_create_info = {};
5233 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5234 image_create_info.pNext = NULL;
5235 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5236 image_create_info.format = tex_format;
5237 image_create_info.extent.width = 32;
5238 image_create_info.extent.height = 32;
5239 image_create_info.extent.depth = 1;
5240 image_create_info.mipLevels = 1;
5241 image_create_info.arrayLayers = 1;
5242 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5243 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005244 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005245 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005246 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005247 ASSERT_VK_SUCCESS(err);
5248 // Have to bind memory to image before recording cmd in cmd buffer using it
5249 VkMemoryRequirements mem_reqs;
5250 VkDeviceMemory image_mem;
5251 bool pass;
5252 VkMemoryAllocateInfo mem_alloc = {};
5253 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5254 mem_alloc.pNext = NULL;
5255 mem_alloc.memoryTypeIndex = 0;
5256 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5257 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005258 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005259 ASSERT_TRUE(pass);
5260 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5261 ASSERT_VK_SUCCESS(err);
5262
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005263 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005265 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005266
5267 m_commandBuffer->BeginCommandBuffer();
5268 VkClearColorValue ccv;
5269 ccv.float32[0] = 1.0f;
5270 ccv.float32[1] = 1.0f;
5271 ccv.float32[2] = 1.0f;
5272 ccv.float32[3] = 1.0f;
5273 VkImageSubresourceRange isr = {};
5274 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5275 isr.baseArrayLayer = 0;
5276 isr.baseMipLevel = 0;
5277 isr.layerCount = 1;
5278 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005279 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005280 m_commandBuffer->EndCommandBuffer();
5281
5282 m_errorMonitor->VerifyFound();
5283 vkDestroyImage(m_device->device(), image, NULL);
5284 vkFreeMemory(m_device->device(), image_mem, nullptr);
5285}
5286
5287TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005288 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005289 ASSERT_NO_FATAL_FAILURE(InitState());
5290
5291 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005292 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 -06005293 VK_IMAGE_TILING_OPTIMAL, 0);
5294 ASSERT_TRUE(image.initialized());
5295
5296 VkBuffer buffer;
5297 VkDeviceMemory mem;
5298 VkMemoryRequirements mem_reqs;
5299
5300 VkBufferCreateInfo buf_info = {};
5301 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005302 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005303 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005304 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5305 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5306 ASSERT_VK_SUCCESS(err);
5307
5308 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5309
5310 VkMemoryAllocateInfo alloc_info = {};
5311 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005312 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005313 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005314 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 -06005315 if (!pass) {
5316 vkDestroyBuffer(m_device->device(), buffer, NULL);
5317 return;
5318 }
5319 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5320 ASSERT_VK_SUCCESS(err);
5321
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005322 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005324 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005325 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005326 region.bufferRowLength = 16;
5327 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005328 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5329
5330 region.imageSubresource.layerCount = 1;
5331 region.imageExtent.height = 4;
5332 region.imageExtent.width = 4;
5333 region.imageExtent.depth = 1;
5334 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005335 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5336 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005337 m_commandBuffer->EndCommandBuffer();
5338
5339 m_errorMonitor->VerifyFound();
5340
5341 vkDestroyBuffer(m_device->device(), buffer, NULL);
5342 vkFreeMemory(m_device->handle(), mem, NULL);
5343}
5344
Tobin Ehlis85940f52016-07-07 16:57:21 -06005345TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005346 TEST_DESCRIPTION(
5347 "Attempt to draw with a command buffer that is invalid "
5348 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005349 ASSERT_NO_FATAL_FAILURE(InitState());
5350
5351 VkEvent event;
5352 VkEventCreateInfo evci = {};
5353 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5354 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5355 ASSERT_VK_SUCCESS(result);
5356
5357 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005358 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005359 m_commandBuffer->EndCommandBuffer();
5360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005362 // Destroy event dependency prior to submit to cause ERROR
5363 vkDestroyEvent(m_device->device(), event, NULL);
5364
5365 VkSubmitInfo submit_info = {};
5366 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5367 submit_info.commandBufferCount = 1;
5368 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005369 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted event");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005370 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5371
5372 m_errorMonitor->VerifyFound();
5373}
5374
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005375TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005376 TEST_DESCRIPTION(
5377 "Attempt to draw with a command buffer that is invalid "
5378 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005379 ASSERT_NO_FATAL_FAILURE(InitState());
5380
5381 VkQueryPool query_pool;
5382 VkQueryPoolCreateInfo qpci{};
5383 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5384 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5385 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005386 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005387 ASSERT_VK_SUCCESS(result);
5388
5389 m_commandBuffer->BeginCommandBuffer();
5390 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5391 m_commandBuffer->EndCommandBuffer();
5392
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005394 // Destroy query pool dependency prior to submit to cause ERROR
5395 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5396
5397 VkSubmitInfo submit_info = {};
5398 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5399 submit_info.commandBufferCount = 1;
5400 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005401 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted query pool");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005402 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5403
5404 m_errorMonitor->VerifyFound();
5405}
5406
Tobin Ehlis24130d92016-07-08 15:50:53 -06005407TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005408 TEST_DESCRIPTION(
5409 "Attempt to draw with a command buffer that is invalid "
5410 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005411 ASSERT_NO_FATAL_FAILURE(InitState());
5412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5413
5414 VkResult err;
5415
5416 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5417 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5418
5419 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005421 ASSERT_VK_SUCCESS(err);
5422
5423 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5424 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5425 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005426 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005427 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005428 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005429 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005430 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005431
5432 VkPipelineShaderStageCreateInfo shaderStages[2];
5433 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005435 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005436 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 -06005437 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005438 shaderStages[0] = vs.GetStageCreateInfo();
5439 shaderStages[1] = fs.GetStageCreateInfo();
5440
5441 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5442 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5443
5444 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5445 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5446 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5447
5448 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5449 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005450 rs_ci.rasterizerDiscardEnable = true;
5451 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005452
5453 VkPipelineColorBlendAttachmentState att = {};
5454 att.blendEnable = VK_FALSE;
5455 att.colorWriteMask = 0xf;
5456
5457 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5458 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5459 cb_ci.attachmentCount = 1;
5460 cb_ci.pAttachments = &att;
5461
5462 VkGraphicsPipelineCreateInfo gp_ci = {};
5463 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5464 gp_ci.stageCount = 2;
5465 gp_ci.pStages = shaderStages;
5466 gp_ci.pVertexInputState = &vi_ci;
5467 gp_ci.pInputAssemblyState = &ia_ci;
5468 gp_ci.pViewportState = &vp_state_ci;
5469 gp_ci.pRasterizationState = &rs_ci;
5470 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005471 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5472 gp_ci.layout = pipeline_layout;
5473 gp_ci.renderPass = renderPass();
5474
5475 VkPipelineCacheCreateInfo pc_ci = {};
5476 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5477
5478 VkPipeline pipeline;
5479 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005480 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005481 ASSERT_VK_SUCCESS(err);
5482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005483 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005484 ASSERT_VK_SUCCESS(err);
5485
5486 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005487 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005488 m_commandBuffer->EndCommandBuffer();
5489 // Now destroy pipeline in order to cause error when submitting
5490 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5491
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005493
5494 VkSubmitInfo submit_info = {};
5495 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5496 submit_info.commandBufferCount = 1;
5497 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005498 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted pipeline");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005499 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5500
5501 m_errorMonitor->VerifyFound();
5502 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5504}
5505
Tobin Ehlis31289162016-08-17 14:57:58 -06005506TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005507 TEST_DESCRIPTION(
5508 "Attempt to draw with a command buffer that is invalid "
5509 "due to a bound descriptor set with a buffer dependency "
5510 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005511 ASSERT_NO_FATAL_FAILURE(InitState());
5512 ASSERT_NO_FATAL_FAILURE(InitViewport());
5513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5514
5515 VkDescriptorPoolSize ds_type_count = {};
5516 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5517 ds_type_count.descriptorCount = 1;
5518
5519 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5520 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5521 ds_pool_ci.pNext = NULL;
5522 ds_pool_ci.maxSets = 1;
5523 ds_pool_ci.poolSizeCount = 1;
5524 ds_pool_ci.pPoolSizes = &ds_type_count;
5525
5526 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005527 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005528 ASSERT_VK_SUCCESS(err);
5529
5530 VkDescriptorSetLayoutBinding dsl_binding = {};
5531 dsl_binding.binding = 0;
5532 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5533 dsl_binding.descriptorCount = 1;
5534 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5535 dsl_binding.pImmutableSamplers = NULL;
5536
5537 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5538 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5539 ds_layout_ci.pNext = NULL;
5540 ds_layout_ci.bindingCount = 1;
5541 ds_layout_ci.pBindings = &dsl_binding;
5542 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005543 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005544 ASSERT_VK_SUCCESS(err);
5545
5546 VkDescriptorSet descriptorSet;
5547 VkDescriptorSetAllocateInfo alloc_info = {};
5548 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5549 alloc_info.descriptorSetCount = 1;
5550 alloc_info.descriptorPool = ds_pool;
5551 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005552 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005553 ASSERT_VK_SUCCESS(err);
5554
5555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5557 pipeline_layout_ci.pNext = NULL;
5558 pipeline_layout_ci.setLayoutCount = 1;
5559 pipeline_layout_ci.pSetLayouts = &ds_layout;
5560
5561 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005563 ASSERT_VK_SUCCESS(err);
5564
5565 // Create a buffer to update the descriptor with
5566 uint32_t qfi = 0;
5567 VkBufferCreateInfo buffCI = {};
5568 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5569 buffCI.size = 1024;
5570 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5571 buffCI.queueFamilyIndexCount = 1;
5572 buffCI.pQueueFamilyIndices = &qfi;
5573
5574 VkBuffer buffer;
5575 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5576 ASSERT_VK_SUCCESS(err);
5577 // Allocate memory and bind to buffer so we can make it to the appropriate
5578 // error
5579 VkMemoryAllocateInfo mem_alloc = {};
5580 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5581 mem_alloc.pNext = NULL;
5582 mem_alloc.allocationSize = 1024;
5583 mem_alloc.memoryTypeIndex = 0;
5584
5585 VkMemoryRequirements memReqs;
5586 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005587 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005588 if (!pass) {
5589 vkDestroyBuffer(m_device->device(), buffer, NULL);
5590 return;
5591 }
5592
5593 VkDeviceMemory mem;
5594 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5595 ASSERT_VK_SUCCESS(err);
5596 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5597 ASSERT_VK_SUCCESS(err);
5598 // Correctly update descriptor to avoid "NOT_UPDATED" error
5599 VkDescriptorBufferInfo buffInfo = {};
5600 buffInfo.buffer = buffer;
5601 buffInfo.offset = 0;
5602 buffInfo.range = 1024;
5603
5604 VkWriteDescriptorSet descriptor_write;
5605 memset(&descriptor_write, 0, sizeof(descriptor_write));
5606 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5607 descriptor_write.dstSet = descriptorSet;
5608 descriptor_write.dstBinding = 0;
5609 descriptor_write.descriptorCount = 1;
5610 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5611 descriptor_write.pBufferInfo = &buffInfo;
5612
5613 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5614
5615 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005616 char const *vsSource =
5617 "#version 450\n"
5618 "\n"
5619 "out gl_PerVertex { \n"
5620 " vec4 gl_Position;\n"
5621 "};\n"
5622 "void main(){\n"
5623 " gl_Position = vec4(1);\n"
5624 "}\n";
5625 char const *fsSource =
5626 "#version 450\n"
5627 "\n"
5628 "layout(location=0) out vec4 x;\n"
5629 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5630 "void main(){\n"
5631 " x = vec4(bar.y);\n"
5632 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005633 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5634 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5635 VkPipelineObj pipe(m_device);
5636 pipe.AddShader(&vs);
5637 pipe.AddShader(&fs);
5638 pipe.AddColorAttachment();
5639 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5640
Tony Barbour552f6c02016-12-21 14:34:07 -07005641 m_commandBuffer->BeginCommandBuffer();
5642 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005643 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5644 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5645 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005646
5647 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5648 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5649
Tobin Ehlis31289162016-08-17 14:57:58 -06005650 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005651 m_commandBuffer->EndRenderPass();
5652 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005654 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5655 vkDestroyBuffer(m_device->device(), buffer, NULL);
5656 // Attempt to submit cmd buffer
5657 VkSubmitInfo submit_info = {};
5658 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5659 submit_info.commandBufferCount = 1;
5660 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005661 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis31289162016-08-17 14:57:58 -06005662 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5663 m_errorMonitor->VerifyFound();
5664 // Cleanup
5665 vkFreeMemory(m_device->device(), mem, NULL);
5666
5667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5669 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5670}
5671
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005672TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005673 TEST_DESCRIPTION(
5674 "Attempt to draw with a command buffer that is invalid "
5675 "due to a bound descriptor sets with a combined image "
5676 "sampler having their image, sampler, and descriptor set "
5677 "each respectively destroyed and then attempting to "
5678 "submit associated cmd buffers. Attempt to destroy a "
5679 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005680 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005681 ASSERT_NO_FATAL_FAILURE(InitViewport());
5682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5683
5684 VkDescriptorPoolSize ds_type_count = {};
5685 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5686 ds_type_count.descriptorCount = 1;
5687
5688 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5689 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5690 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005691 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005692 ds_pool_ci.maxSets = 1;
5693 ds_pool_ci.poolSizeCount = 1;
5694 ds_pool_ci.pPoolSizes = &ds_type_count;
5695
5696 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005697 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005698 ASSERT_VK_SUCCESS(err);
5699
5700 VkDescriptorSetLayoutBinding dsl_binding = {};
5701 dsl_binding.binding = 0;
5702 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5703 dsl_binding.descriptorCount = 1;
5704 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5705 dsl_binding.pImmutableSamplers = NULL;
5706
5707 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5708 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5709 ds_layout_ci.pNext = NULL;
5710 ds_layout_ci.bindingCount = 1;
5711 ds_layout_ci.pBindings = &dsl_binding;
5712 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005714 ASSERT_VK_SUCCESS(err);
5715
5716 VkDescriptorSet descriptorSet;
5717 VkDescriptorSetAllocateInfo alloc_info = {};
5718 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5719 alloc_info.descriptorSetCount = 1;
5720 alloc_info.descriptorPool = ds_pool;
5721 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005722 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005723 ASSERT_VK_SUCCESS(err);
5724
5725 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5726 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5727 pipeline_layout_ci.pNext = NULL;
5728 pipeline_layout_ci.setLayoutCount = 1;
5729 pipeline_layout_ci.pSetLayouts = &ds_layout;
5730
5731 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005732 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005733 ASSERT_VK_SUCCESS(err);
5734
5735 // Create images to update the descriptor with
5736 VkImage image;
5737 VkImage image2;
5738 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5739 const int32_t tex_width = 32;
5740 const int32_t tex_height = 32;
5741 VkImageCreateInfo image_create_info = {};
5742 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5743 image_create_info.pNext = NULL;
5744 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5745 image_create_info.format = tex_format;
5746 image_create_info.extent.width = tex_width;
5747 image_create_info.extent.height = tex_height;
5748 image_create_info.extent.depth = 1;
5749 image_create_info.mipLevels = 1;
5750 image_create_info.arrayLayers = 1;
5751 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5752 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5753 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5754 image_create_info.flags = 0;
5755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5756 ASSERT_VK_SUCCESS(err);
5757 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5758 ASSERT_VK_SUCCESS(err);
5759
5760 VkMemoryRequirements memory_reqs;
5761 VkDeviceMemory image_memory;
5762 bool pass;
5763 VkMemoryAllocateInfo memory_info = {};
5764 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5765 memory_info.pNext = NULL;
5766 memory_info.allocationSize = 0;
5767 memory_info.memoryTypeIndex = 0;
5768 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5769 // Allocate enough memory for both images
5770 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005771 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005772 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005773 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005774 ASSERT_VK_SUCCESS(err);
5775 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5776 ASSERT_VK_SUCCESS(err);
5777 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkImageViewCreateInfo image_view_create_info = {};
5782 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5783 image_view_create_info.image = image;
5784 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5785 image_view_create_info.format = tex_format;
5786 image_view_create_info.subresourceRange.layerCount = 1;
5787 image_view_create_info.subresourceRange.baseMipLevel = 0;
5788 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005790
5791 VkImageView view;
5792 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005794 ASSERT_VK_SUCCESS(err);
5795 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005796 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005797 ASSERT_VK_SUCCESS(err);
5798 // Create Samplers
5799 VkSamplerCreateInfo sampler_ci = {};
5800 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5801 sampler_ci.pNext = NULL;
5802 sampler_ci.magFilter = VK_FILTER_NEAREST;
5803 sampler_ci.minFilter = VK_FILTER_NEAREST;
5804 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5805 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5806 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5807 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5808 sampler_ci.mipLodBias = 1.0;
5809 sampler_ci.anisotropyEnable = VK_FALSE;
5810 sampler_ci.maxAnisotropy = 1;
5811 sampler_ci.compareEnable = VK_FALSE;
5812 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5813 sampler_ci.minLod = 1.0;
5814 sampler_ci.maxLod = 1.0;
5815 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5816 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5817 VkSampler sampler;
5818 VkSampler sampler2;
5819 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5820 ASSERT_VK_SUCCESS(err);
5821 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5822 ASSERT_VK_SUCCESS(err);
5823 // Update descriptor with image and sampler
5824 VkDescriptorImageInfo img_info = {};
5825 img_info.sampler = sampler;
5826 img_info.imageView = view;
5827 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5828
5829 VkWriteDescriptorSet descriptor_write;
5830 memset(&descriptor_write, 0, sizeof(descriptor_write));
5831 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5832 descriptor_write.dstSet = descriptorSet;
5833 descriptor_write.dstBinding = 0;
5834 descriptor_write.descriptorCount = 1;
5835 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5836 descriptor_write.pImageInfo = &img_info;
5837
5838 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5839
5840 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005841 char const *vsSource =
5842 "#version 450\n"
5843 "\n"
5844 "out gl_PerVertex { \n"
5845 " vec4 gl_Position;\n"
5846 "};\n"
5847 "void main(){\n"
5848 " gl_Position = vec4(1);\n"
5849 "}\n";
5850 char const *fsSource =
5851 "#version 450\n"
5852 "\n"
5853 "layout(set=0, binding=0) uniform sampler2D s;\n"
5854 "layout(location=0) out vec4 x;\n"
5855 "void main(){\n"
5856 " x = texture(s, vec2(1));\n"
5857 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005858 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5859 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5860 VkPipelineObj pipe(m_device);
5861 pipe.AddShader(&vs);
5862 pipe.AddShader(&fs);
5863 pipe.AddColorAttachment();
5864 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5865
5866 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005868 m_commandBuffer->BeginCommandBuffer();
5869 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005870 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5871 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5872 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005873 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5874 VkRect2D scissor = {{0, 0}, {16, 16}};
5875 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5876 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005877 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005878 m_commandBuffer->EndRenderPass();
5879 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005880 // Destroy sampler invalidates the cmd buffer, causing error on submit
5881 vkDestroySampler(m_device->device(), sampler, NULL);
5882 // Attempt to submit cmd buffer
5883 VkSubmitInfo submit_info = {};
5884 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5885 submit_info.commandBufferCount = 1;
5886 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005887 m_errorMonitor->SetUnexpectedError("that is invalid because bound sampler");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005888 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5889 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005890
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005891 // Now re-update descriptor with valid sampler and delete image
5892 img_info.sampler = sampler2;
5893 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005894
5895 VkCommandBufferBeginInfo info = {};
5896 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5897 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5898
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005900 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005901 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005902 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5903 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5904 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005905 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5906 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005907 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005908 m_commandBuffer->EndRenderPass();
5909 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005910 // Destroy image invalidates the cmd buffer, causing error on submit
5911 vkDestroyImage(m_device->device(), image, NULL);
5912 // Attempt to submit cmd buffer
5913 submit_info = {};
5914 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5915 submit_info.commandBufferCount = 1;
5916 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005917 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005918 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5919 m_errorMonitor->VerifyFound();
5920 // Now update descriptor to be valid, but then free descriptor
5921 img_info.imageView = view2;
5922 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005923 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005924 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005925 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5926 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5927 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005928 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5929 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005930 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005931 m_commandBuffer->EndRenderPass();
5932 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005933 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005934
5935 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005937 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005938 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005939
5940 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005941 // 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 -07005942 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005943 m_errorMonitor->SetUnexpectedError(
5944 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
5945 "either be a valid handle or VK_NULL_HANDLE");
5946 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07005947 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5948
5949 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005950 submit_info = {};
5951 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5952 submit_info.commandBufferCount = 1;
5953 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005955 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted descriptor set");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005956 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5957 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005958
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005959 // Cleanup
5960 vkFreeMemory(m_device->device(), image_memory, NULL);
5961 vkDestroySampler(m_device->device(), sampler2, NULL);
5962 vkDestroyImage(m_device->device(), image2, NULL);
5963 vkDestroyImageView(m_device->device(), view, NULL);
5964 vkDestroyImageView(m_device->device(), view2, NULL);
5965 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5966 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5967 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5968}
5969
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005970TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5971 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5972 ASSERT_NO_FATAL_FAILURE(InitState());
5973 ASSERT_NO_FATAL_FAILURE(InitViewport());
5974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5975
5976 VkDescriptorPoolSize ds_type_count = {};
5977 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5978 ds_type_count.descriptorCount = 1;
5979
5980 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5981 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5982 ds_pool_ci.pNext = NULL;
5983 ds_pool_ci.maxSets = 1;
5984 ds_pool_ci.poolSizeCount = 1;
5985 ds_pool_ci.pPoolSizes = &ds_type_count;
5986
5987 VkDescriptorPool ds_pool;
5988 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5989 ASSERT_VK_SUCCESS(err);
5990
5991 VkDescriptorSetLayoutBinding dsl_binding = {};
5992 dsl_binding.binding = 0;
5993 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5994 dsl_binding.descriptorCount = 1;
5995 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5996 dsl_binding.pImmutableSamplers = NULL;
5997
5998 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5999 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6000 ds_layout_ci.pNext = NULL;
6001 ds_layout_ci.bindingCount = 1;
6002 ds_layout_ci.pBindings = &dsl_binding;
6003 VkDescriptorSetLayout ds_layout;
6004 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6005 ASSERT_VK_SUCCESS(err);
6006
6007 VkDescriptorSet descriptor_set;
6008 VkDescriptorSetAllocateInfo alloc_info = {};
6009 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6010 alloc_info.descriptorSetCount = 1;
6011 alloc_info.descriptorPool = ds_pool;
6012 alloc_info.pSetLayouts = &ds_layout;
6013 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6014 ASSERT_VK_SUCCESS(err);
6015
6016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6017 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6018 pipeline_layout_ci.pNext = NULL;
6019 pipeline_layout_ci.setLayoutCount = 1;
6020 pipeline_layout_ci.pSetLayouts = &ds_layout;
6021
6022 VkPipelineLayout pipeline_layout;
6023 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6024 ASSERT_VK_SUCCESS(err);
6025
6026 // Create image to update the descriptor with
6027 VkImageObj image(m_device);
6028 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6029 ASSERT_TRUE(image.initialized());
6030
6031 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6032 // Create Sampler
6033 VkSamplerCreateInfo sampler_ci = {};
6034 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6035 sampler_ci.pNext = NULL;
6036 sampler_ci.magFilter = VK_FILTER_NEAREST;
6037 sampler_ci.minFilter = VK_FILTER_NEAREST;
6038 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6039 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6040 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6041 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6042 sampler_ci.mipLodBias = 1.0;
6043 sampler_ci.anisotropyEnable = VK_FALSE;
6044 sampler_ci.maxAnisotropy = 1;
6045 sampler_ci.compareEnable = VK_FALSE;
6046 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6047 sampler_ci.minLod = 1.0;
6048 sampler_ci.maxLod = 1.0;
6049 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6050 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6051 VkSampler sampler;
6052 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6053 ASSERT_VK_SUCCESS(err);
6054 // Update descriptor with image and sampler
6055 VkDescriptorImageInfo img_info = {};
6056 img_info.sampler = sampler;
6057 img_info.imageView = view;
6058 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6059
6060 VkWriteDescriptorSet descriptor_write;
6061 memset(&descriptor_write, 0, sizeof(descriptor_write));
6062 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6063 descriptor_write.dstSet = descriptor_set;
6064 descriptor_write.dstBinding = 0;
6065 descriptor_write.descriptorCount = 1;
6066 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6067 descriptor_write.pImageInfo = &img_info;
6068
6069 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6070
6071 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006072 char const *vsSource =
6073 "#version 450\n"
6074 "\n"
6075 "out gl_PerVertex { \n"
6076 " vec4 gl_Position;\n"
6077 "};\n"
6078 "void main(){\n"
6079 " gl_Position = vec4(1);\n"
6080 "}\n";
6081 char const *fsSource =
6082 "#version 450\n"
6083 "\n"
6084 "layout(set=0, binding=0) uniform sampler2D s;\n"
6085 "layout(location=0) out vec4 x;\n"
6086 "void main(){\n"
6087 " x = texture(s, vec2(1));\n"
6088 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006089 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6090 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6091 VkPipelineObj pipe(m_device);
6092 pipe.AddShader(&vs);
6093 pipe.AddShader(&fs);
6094 pipe.AddColorAttachment();
6095 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6096
Tony Barbour552f6c02016-12-21 14:34:07 -07006097 m_commandBuffer->BeginCommandBuffer();
6098 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006099 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6100 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6101 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006102
6103 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6104 VkRect2D scissor = {{0, 0}, {16, 16}};
6105 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6106 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6107
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006108 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006109 m_commandBuffer->EndRenderPass();
6110 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006111 // Submit cmd buffer to put pool in-flight
6112 VkSubmitInfo submit_info = {};
6113 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6114 submit_info.commandBufferCount = 1;
6115 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6116 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6117 // Destroy pool while in-flight, causing error
6118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6119 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6120 m_errorMonitor->VerifyFound();
6121 vkQueueWaitIdle(m_device->m_queue);
6122 // Cleanup
6123 vkDestroySampler(m_device->device(), sampler, NULL);
6124 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6125 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006126 m_errorMonitor->SetUnexpectedError(
6127 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6128 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006129 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006130 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006131}
6132
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006133TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6134 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6135 ASSERT_NO_FATAL_FAILURE(InitState());
6136 ASSERT_NO_FATAL_FAILURE(InitViewport());
6137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6138
6139 VkDescriptorPoolSize ds_type_count = {};
6140 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6141 ds_type_count.descriptorCount = 1;
6142
6143 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6144 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6145 ds_pool_ci.pNext = NULL;
6146 ds_pool_ci.maxSets = 1;
6147 ds_pool_ci.poolSizeCount = 1;
6148 ds_pool_ci.pPoolSizes = &ds_type_count;
6149
6150 VkDescriptorPool ds_pool;
6151 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6152 ASSERT_VK_SUCCESS(err);
6153
6154 VkDescriptorSetLayoutBinding dsl_binding = {};
6155 dsl_binding.binding = 0;
6156 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6157 dsl_binding.descriptorCount = 1;
6158 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6159 dsl_binding.pImmutableSamplers = NULL;
6160
6161 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6162 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6163 ds_layout_ci.pNext = NULL;
6164 ds_layout_ci.bindingCount = 1;
6165 ds_layout_ci.pBindings = &dsl_binding;
6166 VkDescriptorSetLayout ds_layout;
6167 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6168 ASSERT_VK_SUCCESS(err);
6169
6170 VkDescriptorSet descriptorSet;
6171 VkDescriptorSetAllocateInfo alloc_info = {};
6172 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6173 alloc_info.descriptorSetCount = 1;
6174 alloc_info.descriptorPool = ds_pool;
6175 alloc_info.pSetLayouts = &ds_layout;
6176 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6177 ASSERT_VK_SUCCESS(err);
6178
6179 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6180 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6181 pipeline_layout_ci.pNext = NULL;
6182 pipeline_layout_ci.setLayoutCount = 1;
6183 pipeline_layout_ci.pSetLayouts = &ds_layout;
6184
6185 VkPipelineLayout pipeline_layout;
6186 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6187 ASSERT_VK_SUCCESS(err);
6188
6189 // Create images to update the descriptor with
6190 VkImage image;
6191 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6192 const int32_t tex_width = 32;
6193 const int32_t tex_height = 32;
6194 VkImageCreateInfo image_create_info = {};
6195 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6196 image_create_info.pNext = NULL;
6197 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6198 image_create_info.format = tex_format;
6199 image_create_info.extent.width = tex_width;
6200 image_create_info.extent.height = tex_height;
6201 image_create_info.extent.depth = 1;
6202 image_create_info.mipLevels = 1;
6203 image_create_info.arrayLayers = 1;
6204 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6205 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6206 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6207 image_create_info.flags = 0;
6208 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6209 ASSERT_VK_SUCCESS(err);
6210 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6211 VkMemoryRequirements memory_reqs;
6212 VkDeviceMemory image_memory;
6213 bool pass;
6214 VkMemoryAllocateInfo memory_info = {};
6215 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6216 memory_info.pNext = NULL;
6217 memory_info.allocationSize = 0;
6218 memory_info.memoryTypeIndex = 0;
6219 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6220 // Allocate enough memory for image
6221 memory_info.allocationSize = memory_reqs.size;
6222 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6223 ASSERT_TRUE(pass);
6224 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6225 ASSERT_VK_SUCCESS(err);
6226 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6227 ASSERT_VK_SUCCESS(err);
6228
6229 VkImageViewCreateInfo image_view_create_info = {};
6230 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6231 image_view_create_info.image = image;
6232 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6233 image_view_create_info.format = tex_format;
6234 image_view_create_info.subresourceRange.layerCount = 1;
6235 image_view_create_info.subresourceRange.baseMipLevel = 0;
6236 image_view_create_info.subresourceRange.levelCount = 1;
6237 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6238
6239 VkImageView view;
6240 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6241 ASSERT_VK_SUCCESS(err);
6242 // Create Samplers
6243 VkSamplerCreateInfo sampler_ci = {};
6244 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6245 sampler_ci.pNext = NULL;
6246 sampler_ci.magFilter = VK_FILTER_NEAREST;
6247 sampler_ci.minFilter = VK_FILTER_NEAREST;
6248 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6249 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6250 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6251 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6252 sampler_ci.mipLodBias = 1.0;
6253 sampler_ci.anisotropyEnable = VK_FALSE;
6254 sampler_ci.maxAnisotropy = 1;
6255 sampler_ci.compareEnable = VK_FALSE;
6256 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6257 sampler_ci.minLod = 1.0;
6258 sampler_ci.maxLod = 1.0;
6259 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6260 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6261 VkSampler sampler;
6262 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6263 ASSERT_VK_SUCCESS(err);
6264 // Update descriptor with image and sampler
6265 VkDescriptorImageInfo img_info = {};
6266 img_info.sampler = sampler;
6267 img_info.imageView = view;
6268 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6269
6270 VkWriteDescriptorSet descriptor_write;
6271 memset(&descriptor_write, 0, sizeof(descriptor_write));
6272 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6273 descriptor_write.dstSet = descriptorSet;
6274 descriptor_write.dstBinding = 0;
6275 descriptor_write.descriptorCount = 1;
6276 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6277 descriptor_write.pImageInfo = &img_info;
6278 // Break memory binding and attempt update
6279 vkFreeMemory(m_device->device(), image_memory, nullptr);
6280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006281 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6283 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6284 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6285 m_errorMonitor->VerifyFound();
6286 // Cleanup
6287 vkDestroyImage(m_device->device(), image, NULL);
6288 vkDestroySampler(m_device->device(), sampler, NULL);
6289 vkDestroyImageView(m_device->device(), view, NULL);
6290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6293}
6294
Karl Schultz6addd812016-02-02 17:17:23 -07006295TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006296 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6297 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006298 // Create a valid cmd buffer
6299 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006300 uint64_t fake_pipeline_handle = 0xbaad6001;
6301 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006302 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6304
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006306 m_commandBuffer->BeginCommandBuffer();
6307 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006308 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006309 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006310
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006311 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006312 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 -06006313 Draw(1, 0, 0, 0);
6314 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006315
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006316 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006317 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 -07006318 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006319 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6320 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006321}
6322
Karl Schultz6addd812016-02-02 17:17:23 -07006323TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006324 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006325 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006326
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006328
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006329 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006330 ASSERT_NO_FATAL_FAILURE(InitViewport());
6331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006332 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006333 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6334 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006335
6336 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006337 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6338 ds_pool_ci.pNext = NULL;
6339 ds_pool_ci.maxSets = 1;
6340 ds_pool_ci.poolSizeCount = 1;
6341 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006342
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006343 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006345 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006346
Tony Barboureb254902015-07-15 12:50:33 -06006347 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006348 dsl_binding.binding = 0;
6349 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6350 dsl_binding.descriptorCount = 1;
6351 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6352 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006353
Tony Barboureb254902015-07-15 12:50:33 -06006354 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006355 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6356 ds_layout_ci.pNext = NULL;
6357 ds_layout_ci.bindingCount = 1;
6358 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006359 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006360 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006361 ASSERT_VK_SUCCESS(err);
6362
6363 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006364 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006365 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006366 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006367 alloc_info.descriptorPool = ds_pool;
6368 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006369 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006370 ASSERT_VK_SUCCESS(err);
6371
Tony Barboureb254902015-07-15 12:50:33 -06006372 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006373 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6374 pipeline_layout_ci.pNext = NULL;
6375 pipeline_layout_ci.setLayoutCount = 1;
6376 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006377
6378 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006379 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006380 ASSERT_VK_SUCCESS(err);
6381
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006382 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006383 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006384 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006386
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006387 VkPipelineObj pipe(m_device);
6388 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006389 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006390 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006391 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006392
Tony Barbour552f6c02016-12-21 14:34:07 -07006393 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006394 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6395 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6396 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006397
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006398 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006399
Chia-I Wuf7458c52015-10-26 21:10:41 +08006400 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6401 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6402 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006403}
6404
Karl Schultz6addd812016-02-02 17:17:23 -07006405TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006406 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006407 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006408
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006410
6411 ASSERT_NO_FATAL_FAILURE(InitState());
6412 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006413 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6414 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006415
6416 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006417 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6418 ds_pool_ci.pNext = NULL;
6419 ds_pool_ci.maxSets = 1;
6420 ds_pool_ci.poolSizeCount = 1;
6421 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006422
6423 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006424 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006425 ASSERT_VK_SUCCESS(err);
6426
6427 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006428 dsl_binding.binding = 0;
6429 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6430 dsl_binding.descriptorCount = 1;
6431 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6432 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006433
6434 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006435 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6436 ds_layout_ci.pNext = NULL;
6437 ds_layout_ci.bindingCount = 1;
6438 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006439 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006441 ASSERT_VK_SUCCESS(err);
6442
6443 VkDescriptorSet descriptorSet;
6444 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006445 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006446 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006447 alloc_info.descriptorPool = ds_pool;
6448 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006449 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006450 ASSERT_VK_SUCCESS(err);
6451
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006452 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006453 VkWriteDescriptorSet descriptor_write;
6454 memset(&descriptor_write, 0, sizeof(descriptor_write));
6455 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6456 descriptor_write.dstSet = descriptorSet;
6457 descriptor_write.dstBinding = 0;
6458 descriptor_write.descriptorCount = 1;
6459 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6460 descriptor_write.pTexelBufferView = &view;
6461
6462 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6463
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006464 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006465
6466 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6467 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6468}
6469
Mark Youngd339ba32016-05-30 13:28:35 -06006470TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006471 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 -06006472
6473 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006475 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006476
6477 ASSERT_NO_FATAL_FAILURE(InitState());
6478
6479 // Create a buffer with no bound memory and then attempt to create
6480 // a buffer view.
6481 VkBufferCreateInfo buff_ci = {};
6482 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006483 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006484 buff_ci.size = 256;
6485 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6486 VkBuffer buffer;
6487 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6488 ASSERT_VK_SUCCESS(err);
6489
6490 VkBufferViewCreateInfo buff_view_ci = {};
6491 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6492 buff_view_ci.buffer = buffer;
6493 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6494 buff_view_ci.range = VK_WHOLE_SIZE;
6495 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006496 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006497
6498 m_errorMonitor->VerifyFound();
6499 vkDestroyBuffer(m_device->device(), buffer, NULL);
6500 // If last error is success, it still created the view, so delete it.
6501 if (err == VK_SUCCESS) {
6502 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6503 }
6504}
6505
Karl Schultz6addd812016-02-02 17:17:23 -07006506TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6507 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6508 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006509 // 1. No dynamicOffset supplied
6510 // 2. Too many dynamicOffsets supplied
6511 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006512 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6514 " requires 1 dynamicOffsets, but only "
6515 "0 dynamicOffsets are left in "
6516 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006517
6518 ASSERT_NO_FATAL_FAILURE(InitState());
6519 ASSERT_NO_FATAL_FAILURE(InitViewport());
6520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6521
6522 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006523 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6524 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006525
6526 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006527 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6528 ds_pool_ci.pNext = NULL;
6529 ds_pool_ci.maxSets = 1;
6530 ds_pool_ci.poolSizeCount = 1;
6531 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006532
6533 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006534 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006535 ASSERT_VK_SUCCESS(err);
6536
6537 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006538 dsl_binding.binding = 0;
6539 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6540 dsl_binding.descriptorCount = 1;
6541 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6542 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006543
6544 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006545 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6546 ds_layout_ci.pNext = NULL;
6547 ds_layout_ci.bindingCount = 1;
6548 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006549 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006550 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006551 ASSERT_VK_SUCCESS(err);
6552
6553 VkDescriptorSet descriptorSet;
6554 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006555 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006556 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006557 alloc_info.descriptorPool = ds_pool;
6558 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006559 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006560 ASSERT_VK_SUCCESS(err);
6561
6562 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006563 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6564 pipeline_layout_ci.pNext = NULL;
6565 pipeline_layout_ci.setLayoutCount = 1;
6566 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006567
6568 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006569 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006570 ASSERT_VK_SUCCESS(err);
6571
6572 // Create a buffer to update the descriptor with
6573 uint32_t qfi = 0;
6574 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006575 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6576 buffCI.size = 1024;
6577 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6578 buffCI.queueFamilyIndexCount = 1;
6579 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006580
6581 VkBuffer dyub;
6582 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6583 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006584 // Allocate memory and bind to buffer so we can make it to the appropriate
6585 // error
6586 VkMemoryAllocateInfo mem_alloc = {};
6587 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6588 mem_alloc.pNext = NULL;
6589 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006590 mem_alloc.memoryTypeIndex = 0;
6591
6592 VkMemoryRequirements memReqs;
6593 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006595 if (!pass) {
6596 vkDestroyBuffer(m_device->device(), dyub, NULL);
6597 return;
6598 }
6599
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006600 VkDeviceMemory mem;
6601 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6602 ASSERT_VK_SUCCESS(err);
6603 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6604 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006605 // Correctly update descriptor to avoid "NOT_UPDATED" error
6606 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006607 buffInfo.buffer = dyub;
6608 buffInfo.offset = 0;
6609 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006610
6611 VkWriteDescriptorSet descriptor_write;
6612 memset(&descriptor_write, 0, sizeof(descriptor_write));
6613 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6614 descriptor_write.dstSet = descriptorSet;
6615 descriptor_write.dstBinding = 0;
6616 descriptor_write.descriptorCount = 1;
6617 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6618 descriptor_write.pBufferInfo = &buffInfo;
6619
6620 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6621
Tony Barbour552f6c02016-12-21 14:34:07 -07006622 m_commandBuffer->BeginCommandBuffer();
6623 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006624 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6625 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006626 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006627 uint32_t pDynOff[2] = {512, 756};
6628 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6630 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6631 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6632 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006633 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006634 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6636 " dynamic offset 512 combined with "
6637 "offset 0 and range 1024 that "
6638 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006639 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006640 char const *vsSource =
6641 "#version 450\n"
6642 "\n"
6643 "out gl_PerVertex { \n"
6644 " vec4 gl_Position;\n"
6645 "};\n"
6646 "void main(){\n"
6647 " gl_Position = vec4(1);\n"
6648 "}\n";
6649 char const *fsSource =
6650 "#version 450\n"
6651 "\n"
6652 "layout(location=0) out vec4 x;\n"
6653 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6654 "void main(){\n"
6655 " x = vec4(bar.y);\n"
6656 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006657 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6658 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6659 VkPipelineObj pipe(m_device);
6660 pipe.AddShader(&vs);
6661 pipe.AddShader(&fs);
6662 pipe.AddColorAttachment();
6663 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6664
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006665 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6666 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6667 VkRect2D scissor = {{0, 0}, {16, 16}};
6668 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006670 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006671 // This update should succeed, but offset size of 512 will overstep buffer
6672 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006673 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6674 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006675 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006676 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006677
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006678 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006679 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006680
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006681 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006682 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006683 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6684}
6685
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006686TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006687 TEST_DESCRIPTION(
6688 "Attempt to update a descriptor with a non-sparse buffer "
6689 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006690 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006692 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6694 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006695
6696 ASSERT_NO_FATAL_FAILURE(InitState());
6697 ASSERT_NO_FATAL_FAILURE(InitViewport());
6698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6699
6700 VkDescriptorPoolSize ds_type_count = {};
6701 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6702 ds_type_count.descriptorCount = 1;
6703
6704 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6705 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6706 ds_pool_ci.pNext = NULL;
6707 ds_pool_ci.maxSets = 1;
6708 ds_pool_ci.poolSizeCount = 1;
6709 ds_pool_ci.pPoolSizes = &ds_type_count;
6710
6711 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006712 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006713 ASSERT_VK_SUCCESS(err);
6714
6715 VkDescriptorSetLayoutBinding dsl_binding = {};
6716 dsl_binding.binding = 0;
6717 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6718 dsl_binding.descriptorCount = 1;
6719 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6720 dsl_binding.pImmutableSamplers = NULL;
6721
6722 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6723 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6724 ds_layout_ci.pNext = NULL;
6725 ds_layout_ci.bindingCount = 1;
6726 ds_layout_ci.pBindings = &dsl_binding;
6727 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006728 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006729 ASSERT_VK_SUCCESS(err);
6730
6731 VkDescriptorSet descriptorSet;
6732 VkDescriptorSetAllocateInfo alloc_info = {};
6733 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6734 alloc_info.descriptorSetCount = 1;
6735 alloc_info.descriptorPool = ds_pool;
6736 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006737 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006738 ASSERT_VK_SUCCESS(err);
6739
6740 // Create a buffer to update the descriptor with
6741 uint32_t qfi = 0;
6742 VkBufferCreateInfo buffCI = {};
6743 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6744 buffCI.size = 1024;
6745 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6746 buffCI.queueFamilyIndexCount = 1;
6747 buffCI.pQueueFamilyIndices = &qfi;
6748
6749 VkBuffer dyub;
6750 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6751 ASSERT_VK_SUCCESS(err);
6752
6753 // Attempt to update descriptor without binding memory to it
6754 VkDescriptorBufferInfo buffInfo = {};
6755 buffInfo.buffer = dyub;
6756 buffInfo.offset = 0;
6757 buffInfo.range = 1024;
6758
6759 VkWriteDescriptorSet descriptor_write;
6760 memset(&descriptor_write, 0, sizeof(descriptor_write));
6761 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6762 descriptor_write.dstSet = descriptorSet;
6763 descriptor_write.dstBinding = 0;
6764 descriptor_write.descriptorCount = 1;
6765 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6766 descriptor_write.pBufferInfo = &buffInfo;
6767
6768 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6769 m_errorMonitor->VerifyFound();
6770
6771 vkDestroyBuffer(m_device->device(), dyub, NULL);
6772 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6773 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6774}
6775
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006776TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006777 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006778 ASSERT_NO_FATAL_FAILURE(InitState());
6779 ASSERT_NO_FATAL_FAILURE(InitViewport());
6780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6781
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006782 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006783 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006784 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6785 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6786 pipeline_layout_ci.pushConstantRangeCount = 1;
6787 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6788
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006789 //
6790 // Check for invalid push constant ranges in pipeline layouts.
6791 //
6792 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006793 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006794 char const *msg;
6795 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006796
Karl Schultzc81037d2016-05-12 08:11:23 -06006797 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6798 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6799 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6800 "vkCreatePipelineLayout() call has push constants index 0 with "
6801 "size 0."},
6802 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6803 "vkCreatePipelineLayout() call has push constants index 0 with "
6804 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006805 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006806 "vkCreatePipelineLayout() call has push constants index 0 with "
6807 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006808 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006809 "vkCreatePipelineLayout() call has push constants index 0 with "
6810 "size 0."},
6811 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6812 "vkCreatePipelineLayout() call has push constants index 0 with "
6813 "offset 1. Offset must"},
6814 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6815 "vkCreatePipelineLayout() call has push constants index 0 "
6816 "with offset "},
6817 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6818 "vkCreatePipelineLayout() call has push constants "
6819 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006820 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006821 "vkCreatePipelineLayout() call has push constants index 0 "
6822 "with offset "},
6823 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6824 "vkCreatePipelineLayout() call has push "
6825 "constants index 0 with offset "},
6826 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6827 "vkCreatePipelineLayout() call has push "
6828 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006829 }};
6830
6831 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006832 for (const auto &iter : range_tests) {
6833 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6835 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006836 m_errorMonitor->VerifyFound();
6837 if (VK_SUCCESS == err) {
6838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6839 }
6840 }
6841
6842 // Check for invalid stage flag
6843 pc_range.offset = 0;
6844 pc_range.size = 16;
6845 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006846 m_errorMonitor->SetDesiredFailureMsg(
6847 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6848 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006849 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006850 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006851 if (VK_SUCCESS == err) {
6852 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6853 }
6854
6855 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006856 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006857 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006858 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006859 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006860 };
6861
Karl Schultzc81037d2016-05-12 08:11:23 -06006862 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006863 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6864 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6865 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6866 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6867 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006868 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6869 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6870 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6871 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6872 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6873 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6874 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6875 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6876 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6877 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006878 {
6879 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6880 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6881 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6882 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6883 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006884 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006885 },
6886 {
6887 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6888 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6889 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6890 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6891 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006892 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006893 },
6894 {
6895 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6896 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6897 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6898 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6899 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006900 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006901 },
6902 {
6903 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6904 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6905 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6906 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6907 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006908 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6909 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6910 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6911 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006912 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006913
Karl Schultzc81037d2016-05-12 08:11:23 -06006914 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006915 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006916 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006918 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006919 m_errorMonitor->VerifyFound();
6920 if (VK_SUCCESS == err) {
6921 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6922 }
6923 }
6924
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006925 //
6926 // CmdPushConstants tests
6927 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006928 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006929
6930 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006931 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6932 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006933 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006934 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6935 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006936 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006937 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6938 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006939 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006940 "vkCmdPushConstants() call has push constants with offset 1. "
6941 "Offset must be a multiple of 4."},
6942 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6943 "vkCmdPushConstants() call has push constants with offset 1. "
6944 "Offset must be a multiple of 4."},
6945 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6946 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6947 "0x1 not within flag-matching ranges in pipeline layout"},
6948 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6949 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6950 "0x1 not within flag-matching ranges in pipeline layout"},
6951 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6952 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6953 "0x1 not within flag-matching ranges in pipeline layout"},
6954 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6955 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6956 "0x1 not within flag-matching ranges in pipeline layout"},
6957 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6958 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6959 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006960 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006961 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6962 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006963 }};
6964
Tony Barbour552f6c02016-12-21 14:34:07 -07006965 m_commandBuffer->BeginCommandBuffer();
6966 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006967
6968 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006969 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006970 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006971 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006972 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006973 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006974 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006975 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006976 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6978 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006979 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006980 m_errorMonitor->VerifyFound();
6981 }
6982
6983 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006985 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006986 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006987 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006988
Karl Schultzc81037d2016-05-12 08:11:23 -06006989 // overlapping range tests with cmd
6990 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6991 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6992 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6993 "0x1 not within flag-matching ranges in pipeline layout"},
6994 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6995 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6996 "0x1 not within flag-matching ranges in pipeline layout"},
6997 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6998 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6999 "0x1 not within flag-matching ranges in pipeline layout"},
7000 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007001 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06007002 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007003 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
7004 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06007005 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007006 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06007007 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007008 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06007009 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007010 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7012 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007013 iter.range.size, dummy_values);
7014 m_errorMonitor->VerifyFound();
7015 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007016 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7017
Tony Barbour552f6c02016-12-21 14:34:07 -07007018 m_commandBuffer->EndRenderPass();
7019 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007020}
7021
Karl Schultz6addd812016-02-02 17:17:23 -07007022TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007023 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007024 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007025
7026 ASSERT_NO_FATAL_FAILURE(InitState());
7027 ASSERT_NO_FATAL_FAILURE(InitViewport());
7028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7029
7030 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7031 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007032 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7033 ds_type_count[0].descriptorCount = 10;
7034 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7035 ds_type_count[1].descriptorCount = 2;
7036 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7037 ds_type_count[2].descriptorCount = 2;
7038 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7039 ds_type_count[3].descriptorCount = 5;
7040 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7041 // type
7042 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7043 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7044 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007045
7046 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007047 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7048 ds_pool_ci.pNext = NULL;
7049 ds_pool_ci.maxSets = 5;
7050 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7051 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007052
7053 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007054 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007055 ASSERT_VK_SUCCESS(err);
7056
7057 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7058 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007059 dsl_binding[0].binding = 0;
7060 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7061 dsl_binding[0].descriptorCount = 5;
7062 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7063 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007064
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007065 // Create layout identical to set0 layout but w/ different stageFlags
7066 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007067 dsl_fs_stage_only.binding = 0;
7068 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7069 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007070 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7071 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007072 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007073 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007074 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7075 ds_layout_ci.pNext = NULL;
7076 ds_layout_ci.bindingCount = 1;
7077 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007078 static const uint32_t NUM_LAYOUTS = 4;
7079 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007080 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007081 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7082 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007084 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007085 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007086 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007087 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007088 dsl_binding[0].binding = 0;
7089 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007090 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007091 dsl_binding[1].binding = 1;
7092 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7093 dsl_binding[1].descriptorCount = 2;
7094 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7095 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007096 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007097 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007098 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007099 ASSERT_VK_SUCCESS(err);
7100 dsl_binding[0].binding = 0;
7101 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007102 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007103 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007104 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007105 ASSERT_VK_SUCCESS(err);
7106 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007107 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007108 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007109 ASSERT_VK_SUCCESS(err);
7110
7111 static const uint32_t NUM_SETS = 4;
7112 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7113 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007114 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007115 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007116 alloc_info.descriptorPool = ds_pool;
7117 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007118 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007119 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007120 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007121 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007122 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007123 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007124 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007125
7126 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007127 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7128 pipeline_layout_ci.pNext = NULL;
7129 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7130 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007131
7132 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007133 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007134 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007135 // Create pipelineLayout with only one setLayout
7136 pipeline_layout_ci.setLayoutCount = 1;
7137 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007138 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007139 ASSERT_VK_SUCCESS(err);
7140 // Create pipelineLayout with 2 descriptor setLayout at index 0
7141 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7142 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007143 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007144 ASSERT_VK_SUCCESS(err);
7145 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7146 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7147 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007148 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007149 ASSERT_VK_SUCCESS(err);
7150 // Create pipelineLayout with UB type, but stageFlags for FS only
7151 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7152 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007153 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007154 ASSERT_VK_SUCCESS(err);
7155 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7156 VkDescriptorSetLayout pl_bad_s0[2] = {};
7157 pl_bad_s0[0] = ds_layout_fs_only;
7158 pl_bad_s0[1] = ds_layout[1];
7159 pipeline_layout_ci.setLayoutCount = 2;
7160 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7161 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007163 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007164
Tobin Ehlis88452832015-12-03 09:40:56 -07007165 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007166 char const *vsSource =
7167 "#version 450\n"
7168 "\n"
7169 "out gl_PerVertex {\n"
7170 " vec4 gl_Position;\n"
7171 "};\n"
7172 "void main(){\n"
7173 " gl_Position = vec4(1);\n"
7174 "}\n";
7175 char const *fsSource =
7176 "#version 450\n"
7177 "\n"
7178 "layout(location=0) out vec4 x;\n"
7179 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7180 "void main(){\n"
7181 " x = vec4(bar.y);\n"
7182 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007183 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7184 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007185 VkPipelineObj pipe(m_device);
7186 pipe.AddShader(&vs);
7187 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007188 pipe.AddColorAttachment();
7189 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007190
Tony Barbour552f6c02016-12-21 14:34:07 -07007191 m_commandBuffer->BeginCommandBuffer();
7192 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007193
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007194 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007195 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7196 // of PSO
7197 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7198 // cmd_pipeline.c
7199 // due to the fact that cmd_alloc_dset_data() has not been called in
7200 // cmd_bind_graphics_pipeline()
7201 // TODO : Want to cause various binding incompatibility issues here to test
7202 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007203 // First cause various verify_layout_compatibility() fails
7204 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007205 // verify_set_layout_compatibility fail cases:
7206 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007208 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7209 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007210 m_errorMonitor->VerifyFound();
7211
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007212 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7214 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7215 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007216 m_errorMonitor->VerifyFound();
7217
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007218 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007219 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7220 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7222 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7223 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007224 m_errorMonitor->VerifyFound();
7225
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007226 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7227 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7229 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7230 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007231 m_errorMonitor->VerifyFound();
7232
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007233 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7234 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7236 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7237 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7238 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007239 m_errorMonitor->VerifyFound();
7240
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007241 // Cause INFO messages due to disturbing previously bound Sets
7242 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007243 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7244 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007245 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7247 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7248 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007249 m_errorMonitor->VerifyFound();
7250
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007251 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7252 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007253 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7255 " newly bound as set #0 so set #1 and "
7256 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7258 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007259 m_errorMonitor->VerifyFound();
7260
Tobin Ehlis10fad692016-07-07 12:00:36 -06007261 // Now that we're done actively using the pipelineLayout that gfx pipeline
7262 // was created with, we should be able to delete it. Do that now to verify
7263 // that validation obeys pipelineLayout lifetime
7264 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7265
Tobin Ehlis88452832015-12-03 09:40:56 -07007266 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007267 // 1. Error due to not binding required set (we actually use same code as
7268 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7270 &descriptorSet[0], 0, NULL);
7271 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7272 &descriptorSet[1], 0, NULL);
7273 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 -07007274
7275 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7276 VkRect2D scissor = {{0, 0}, {16, 16}};
7277 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7278 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7279
Tobin Ehlis88452832015-12-03 09:40:56 -07007280 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007281 m_errorMonitor->VerifyFound();
7282
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007283 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007284 // 2. Error due to bound set not being compatible with PSO's
7285 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007286 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7287 &descriptorSet[0], 0, NULL);
7288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007289 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007290 m_errorMonitor->VerifyFound();
7291
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007292 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007293 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007294 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7295 }
7296 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007297 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7298 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7299}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007300
Karl Schultz6addd812016-02-02 17:17:23 -07007301TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7303 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007304
7305 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007306 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007307 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007308 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007309
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007310 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007311}
7312
Karl Schultz6addd812016-02-02 17:17:23 -07007313TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7314 VkResult err;
7315 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007316
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007318
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007319 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007320
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007321 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007322 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007323 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007324 cmd.commandPool = m_commandPool;
7325 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007326 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007327
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007328 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007329 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007330
7331 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007332 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007333 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7334
7335 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007336 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007337 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007338 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 -07007339 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007340
7341 // The error should be caught by validation of the BeginCommandBuffer call
7342 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7343
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007344 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007345 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007346}
7347
Karl Schultz6addd812016-02-02 17:17:23 -07007348TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007349 // Cause error due to Begin while recording CB
7350 // Then cause 2 errors for attempting to reset CB w/o having
7351 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7352 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007354
7355 ASSERT_NO_FATAL_FAILURE(InitState());
7356
7357 // Calls AllocateCommandBuffers
7358 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7359
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007360 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007361 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007362 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7363 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007364 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7365 cmd_buf_info.pNext = NULL;
7366 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007367 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007368
7369 // Begin CB to transition to recording state
7370 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7371 // Can't re-begin. This should trigger error
7372 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007373 m_errorMonitor->VerifyFound();
7374
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007376 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007377 // Reset attempt will trigger error due to incorrect CommandPool state
7378 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007379 m_errorMonitor->VerifyFound();
7380
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007382 // Transition CB to RECORDED state
7383 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7384 // Now attempting to Begin will implicitly reset, which triggers error
7385 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007386 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007387}
7388
Karl Schultz6addd812016-02-02 17:17:23 -07007389TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007390 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007391 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007392
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7394 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007395
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007396 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007398
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007399 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007400 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7401 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007402
7403 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007404 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7405 ds_pool_ci.pNext = NULL;
7406 ds_pool_ci.maxSets = 1;
7407 ds_pool_ci.poolSizeCount = 1;
7408 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007409
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007410 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007411 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007412 ASSERT_VK_SUCCESS(err);
7413
Tony Barboureb254902015-07-15 12:50:33 -06007414 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007415 dsl_binding.binding = 0;
7416 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7417 dsl_binding.descriptorCount = 1;
7418 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7419 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007420
Tony Barboureb254902015-07-15 12:50:33 -06007421 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7423 ds_layout_ci.pNext = NULL;
7424 ds_layout_ci.bindingCount = 1;
7425 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007426
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007427 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007429 ASSERT_VK_SUCCESS(err);
7430
7431 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007432 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007434 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007435 alloc_info.descriptorPool = ds_pool;
7436 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007438 ASSERT_VK_SUCCESS(err);
7439
Tony Barboureb254902015-07-15 12:50:33 -06007440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7442 pipeline_layout_ci.setLayoutCount = 1;
7443 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007444
7445 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007447 ASSERT_VK_SUCCESS(err);
7448
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007449 VkViewport vp = {}; // Just need dummy vp to point to
7450 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007451
7452 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007453 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7454 vp_state_ci.scissorCount = 1;
7455 vp_state_ci.pScissors = &sc;
7456 vp_state_ci.viewportCount = 1;
7457 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007458
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007459 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7460 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7461 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7462 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7463 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7464 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007465 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007466 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007467 rs_state_ci.lineWidth = 1.0f;
7468
7469 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7470 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7471 vi_ci.pNext = nullptr;
7472 vi_ci.vertexBindingDescriptionCount = 0;
7473 vi_ci.pVertexBindingDescriptions = nullptr;
7474 vi_ci.vertexAttributeDescriptionCount = 0;
7475 vi_ci.pVertexAttributeDescriptions = nullptr;
7476
7477 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7478 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7479 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7480
7481 VkPipelineShaderStageCreateInfo shaderStages[2];
7482 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7483
7484 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7485 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007486 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007487 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007488
Tony Barboureb254902015-07-15 12:50:33 -06007489 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007490 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7491 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007492 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007493 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7494 gp_ci.layout = pipeline_layout;
7495 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007496 gp_ci.pVertexInputState = &vi_ci;
7497 gp_ci.pInputAssemblyState = &ia_ci;
7498
7499 gp_ci.stageCount = 1;
7500 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007501
7502 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007503 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7504 pc_ci.initialDataSize = 0;
7505 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007506
7507 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007508 VkPipelineCache pipelineCache;
7509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007510 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007511 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007512 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007513 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007514
Chia-I Wuf7458c52015-10-26 21:10:41 +08007515 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7516 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7517 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7518 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007519}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007520
Tobin Ehlis912df022015-09-17 08:46:18 -06007521/*// TODO : This test should be good, but needs Tess support in compiler to run
7522TEST_F(VkLayerTest, InvalidPatchControlPoints)
7523{
7524 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007525 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007526
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007528 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7529primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007530
Tobin Ehlis912df022015-09-17 08:46:18 -06007531 ASSERT_NO_FATAL_FAILURE(InitState());
7532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007533
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007534 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007535 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007536 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007537
7538 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7539 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7540 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007541 ds_pool_ci.poolSizeCount = 1;
7542 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007543
7544 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007545 err = vkCreateDescriptorPool(m_device->device(),
7546VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007547 ASSERT_VK_SUCCESS(err);
7548
7549 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007550 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007551 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007552 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007553 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7554 dsl_binding.pImmutableSamplers = NULL;
7555
7556 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007557 ds_layout_ci.sType =
7558VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007559 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007560 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007561 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007562
7563 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007564 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7565&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007566 ASSERT_VK_SUCCESS(err);
7567
7568 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007569 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7570VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007571 ASSERT_VK_SUCCESS(err);
7572
7573 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007574 pipeline_layout_ci.sType =
7575VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007576 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007577 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007578 pipeline_layout_ci.pSetLayouts = &ds_layout;
7579
7580 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007581 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7582&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007583 ASSERT_VK_SUCCESS(err);
7584
7585 VkPipelineShaderStageCreateInfo shaderStages[3];
7586 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7587
Karl Schultz6addd812016-02-02 17:17:23 -07007588 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7589this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007590 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007591 VkShaderObj
7592tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7593this);
7594 VkShaderObj
7595te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7596this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007597
Karl Schultz6addd812016-02-02 17:17:23 -07007598 shaderStages[0].sType =
7599VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007600 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007601 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007602 shaderStages[1].sType =
7603VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007604 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007606 shaderStages[2].sType =
7607VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007608 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007609 shaderStages[2].shader = te.handle();
7610
7611 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007612 iaCI.sType =
7613VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007614 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007615
7616 VkPipelineTessellationStateCreateInfo tsCI = {};
7617 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7618 tsCI.patchControlPoints = 0; // This will cause an error
7619
7620 VkGraphicsPipelineCreateInfo gp_ci = {};
7621 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7622 gp_ci.pNext = NULL;
7623 gp_ci.stageCount = 3;
7624 gp_ci.pStages = shaderStages;
7625 gp_ci.pVertexInputState = NULL;
7626 gp_ci.pInputAssemblyState = &iaCI;
7627 gp_ci.pTessellationState = &tsCI;
7628 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007629 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007630 gp_ci.pMultisampleState = NULL;
7631 gp_ci.pDepthStencilState = NULL;
7632 gp_ci.pColorBlendState = NULL;
7633 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7634 gp_ci.layout = pipeline_layout;
7635 gp_ci.renderPass = renderPass();
7636
7637 VkPipelineCacheCreateInfo pc_ci = {};
7638 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7639 pc_ci.pNext = NULL;
7640 pc_ci.initialSize = 0;
7641 pc_ci.initialData = 0;
7642 pc_ci.maxSize = 0;
7643
7644 VkPipeline pipeline;
7645 VkPipelineCache pipelineCache;
7646
Karl Schultz6addd812016-02-02 17:17:23 -07007647 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7648&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007649 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007650 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7651&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007652
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007653 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007654
Chia-I Wuf7458c52015-10-26 21:10:41 +08007655 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7656 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7657 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7658 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007659}
7660*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007661
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007662TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007663 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007664
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007665 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007666
Tobin Ehlise68360f2015-10-01 11:15:13 -06007667 ASSERT_NO_FATAL_FAILURE(InitState());
7668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007669
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007670 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007671 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7672 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007673
7674 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007675 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7676 ds_pool_ci.maxSets = 1;
7677 ds_pool_ci.poolSizeCount = 1;
7678 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007679
7680 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007681 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007682 ASSERT_VK_SUCCESS(err);
7683
7684 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007685 dsl_binding.binding = 0;
7686 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7687 dsl_binding.descriptorCount = 1;
7688 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007689
7690 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007691 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7692 ds_layout_ci.bindingCount = 1;
7693 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007694
7695 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007697 ASSERT_VK_SUCCESS(err);
7698
7699 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007700 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007702 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007703 alloc_info.descriptorPool = ds_pool;
7704 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007706 ASSERT_VK_SUCCESS(err);
7707
7708 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007709 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7710 pipeline_layout_ci.setLayoutCount = 1;
7711 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007712
7713 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007714 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007715 ASSERT_VK_SUCCESS(err);
7716
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007717 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007718 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007719 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007720 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007721 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007722 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007723
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007724 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7725 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7726 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7727 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7728 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7729 rs_state_ci.depthClampEnable = VK_FALSE;
7730 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7731 rs_state_ci.depthBiasEnable = VK_FALSE;
7732
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007733 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7734 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7735 vi_ci.pNext = nullptr;
7736 vi_ci.vertexBindingDescriptionCount = 0;
7737 vi_ci.pVertexBindingDescriptions = nullptr;
7738 vi_ci.vertexAttributeDescriptionCount = 0;
7739 vi_ci.pVertexAttributeDescriptions = nullptr;
7740
7741 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7742 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7743 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7744
7745 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7746 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7747 pipe_ms_state_ci.pNext = NULL;
7748 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7749 pipe_ms_state_ci.sampleShadingEnable = 0;
7750 pipe_ms_state_ci.minSampleShading = 1.0;
7751 pipe_ms_state_ci.pSampleMask = NULL;
7752
Cody Northropeb3a6c12015-10-05 14:44:45 -06007753 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007754 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007756 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007757 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007758 shaderStages[0] = vs.GetStageCreateInfo();
7759 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007760
7761 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007762 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7763 gp_ci.stageCount = 2;
7764 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007765 gp_ci.pVertexInputState = &vi_ci;
7766 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007767 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007768 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007769 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007770 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7771 gp_ci.layout = pipeline_layout;
7772 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007773
7774 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007775 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007776
7777 VkPipeline pipeline;
7778 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007779 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007780 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007781
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007782 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007783 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007784
7785 // Check case where multiViewport is disabled and viewport count is not 1
7786 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7789 vp_state_ci.scissorCount = 0;
7790 vp_state_ci.viewportCount = 0;
7791 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7792 m_errorMonitor->VerifyFound();
7793 } else {
7794 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007795 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007796 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007797 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007798
7799 // Check is that viewportcount and scissorcount match
7800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7801 vp_state_ci.scissorCount = 1;
7802 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7803 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7804 m_errorMonitor->VerifyFound();
7805
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007806 // Check case where multiViewport is enabled and viewport count is greater than max
7807 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7810 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7811 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7812 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7813 m_errorMonitor->VerifyFound();
7814 }
7815 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007816
Chia-I Wuf7458c52015-10-26 21:10:41 +08007817 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7818 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7819 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7820 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007821}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007822
7823// 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
7824// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007825TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007826 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007827
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007828 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7829
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007831
Tobin Ehlise68360f2015-10-01 11:15:13 -06007832 ASSERT_NO_FATAL_FAILURE(InitState());
7833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007834
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007835 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007836 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7837 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007838
7839 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007840 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7841 ds_pool_ci.maxSets = 1;
7842 ds_pool_ci.poolSizeCount = 1;
7843 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007844
7845 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007846 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007847 ASSERT_VK_SUCCESS(err);
7848
7849 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007850 dsl_binding.binding = 0;
7851 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7852 dsl_binding.descriptorCount = 1;
7853 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007854
7855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7857 ds_layout_ci.bindingCount = 1;
7858 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007859
7860 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007862 ASSERT_VK_SUCCESS(err);
7863
7864 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007865 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007867 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007868 alloc_info.descriptorPool = ds_pool;
7869 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007871 ASSERT_VK_SUCCESS(err);
7872
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007873 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7874 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7875 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7876
7877 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7878 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7879 vi_ci.pNext = nullptr;
7880 vi_ci.vertexBindingDescriptionCount = 0;
7881 vi_ci.pVertexBindingDescriptions = nullptr;
7882 vi_ci.vertexAttributeDescriptionCount = 0;
7883 vi_ci.pVertexAttributeDescriptions = nullptr;
7884
7885 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7886 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7887 pipe_ms_state_ci.pNext = NULL;
7888 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7889 pipe_ms_state_ci.sampleShadingEnable = 0;
7890 pipe_ms_state_ci.minSampleShading = 1.0;
7891 pipe_ms_state_ci.pSampleMask = NULL;
7892
Tobin Ehlise68360f2015-10-01 11:15:13 -06007893 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007894 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7895 pipeline_layout_ci.setLayoutCount = 1;
7896 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007897
7898 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007899 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007900 ASSERT_VK_SUCCESS(err);
7901
7902 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7903 // Set scissor as dynamic to avoid second error
7904 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007905 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7906 dyn_state_ci.dynamicStateCount = 1;
7907 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007908
Cody Northropeb3a6c12015-10-05 14:44:45 -06007909 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007910 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007913 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7914 // 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 +08007915 shaderStages[0] = vs.GetStageCreateInfo();
7916 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007917
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007918 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7919 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7920 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7921 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7922 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7923 rs_state_ci.depthClampEnable = VK_FALSE;
7924 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7925 rs_state_ci.depthBiasEnable = VK_FALSE;
7926
Tobin Ehlise68360f2015-10-01 11:15:13 -06007927 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007928 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7929 gp_ci.stageCount = 2;
7930 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007931 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007932 // Not setting VP state w/o dynamic vp state should cause validation error
7933 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007934 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007935 gp_ci.pVertexInputState = &vi_ci;
7936 gp_ci.pInputAssemblyState = &ia_ci;
7937 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007938 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7939 gp_ci.layout = pipeline_layout;
7940 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007941
7942 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007943 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007944
7945 VkPipeline pipeline;
7946 VkPipelineCache pipelineCache;
7947
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007948 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007949 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007950 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007952 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007953
Chia-I Wuf7458c52015-10-26 21:10:41 +08007954 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7955 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7956 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7957 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007958}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007959
7960// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7961// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007962TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7963 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007964
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007966
Tobin Ehlise68360f2015-10-01 11:15:13 -06007967 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007968
7969 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007970 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007971 return;
7972 }
7973
Tobin Ehlise68360f2015-10-01 11:15:13 -06007974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007976 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007977 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7978 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007979
7980 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007981 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7982 ds_pool_ci.maxSets = 1;
7983 ds_pool_ci.poolSizeCount = 1;
7984 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007985
7986 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007987 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007988 ASSERT_VK_SUCCESS(err);
7989
7990 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007991 dsl_binding.binding = 0;
7992 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7993 dsl_binding.descriptorCount = 1;
7994 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007995
7996 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007997 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7998 ds_layout_ci.bindingCount = 1;
7999 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008000
8001 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008003 ASSERT_VK_SUCCESS(err);
8004
8005 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008006 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008007 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008008 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008009 alloc_info.descriptorPool = ds_pool;
8010 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008012 ASSERT_VK_SUCCESS(err);
8013
8014 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008015 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8016 pipeline_layout_ci.setLayoutCount = 1;
8017 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008018
8019 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008020 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008021 ASSERT_VK_SUCCESS(err);
8022
8023 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008024 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8025 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008026 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008027 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008028 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008029
8030 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8031 // Set scissor as dynamic to avoid that error
8032 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008033 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8034 dyn_state_ci.dynamicStateCount = 1;
8035 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008036
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008037 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8038 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8039 pipe_ms_state_ci.pNext = NULL;
8040 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8041 pipe_ms_state_ci.sampleShadingEnable = 0;
8042 pipe_ms_state_ci.minSampleShading = 1.0;
8043 pipe_ms_state_ci.pSampleMask = NULL;
8044
Cody Northropeb3a6c12015-10-05 14:44:45 -06008045 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008046 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008048 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008049 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8050 // 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 +08008051 shaderStages[0] = vs.GetStageCreateInfo();
8052 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008053
Cody Northropf6622dc2015-10-06 10:33:21 -06008054 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8055 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8056 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008057 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008058 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008059 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008060 vi_ci.pVertexAttributeDescriptions = nullptr;
8061
8062 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8063 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8064 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8065
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008066 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008067 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008068 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008069 rs_ci.pNext = nullptr;
8070
Mark Youngc89c6312016-03-31 16:03:20 -06008071 VkPipelineColorBlendAttachmentState att = {};
8072 att.blendEnable = VK_FALSE;
8073 att.colorWriteMask = 0xf;
8074
Cody Northropf6622dc2015-10-06 10:33:21 -06008075 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8076 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8077 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008078 cb_ci.attachmentCount = 1;
8079 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008080
Tobin Ehlise68360f2015-10-01 11:15:13 -06008081 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008082 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8083 gp_ci.stageCount = 2;
8084 gp_ci.pStages = shaderStages;
8085 gp_ci.pVertexInputState = &vi_ci;
8086 gp_ci.pInputAssemblyState = &ia_ci;
8087 gp_ci.pViewportState = &vp_state_ci;
8088 gp_ci.pRasterizationState = &rs_ci;
8089 gp_ci.pColorBlendState = &cb_ci;
8090 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008091 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008092 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8093 gp_ci.layout = pipeline_layout;
8094 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008095
8096 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008097 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008098
8099 VkPipeline pipeline;
8100 VkPipelineCache pipelineCache;
8101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008102 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008103 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008104 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008105
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008106 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008107
Tobin Ehlisd332f282015-10-02 11:00:56 -06008108 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008109 // First need to successfully create the PSO from above by setting
8110 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008111 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 -07008112
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008113 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008114 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008115 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008116 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008117 m_commandBuffer->BeginCommandBuffer();
8118 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008120 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008121 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008122 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008123 Draw(1, 0, 0, 0);
8124
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008125 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008126
8127 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8128 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8129 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8130 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008131 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008132}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008133
8134// 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 -07008135// viewportCount
8136TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8137 VkResult err;
8138
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008140
8141 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008142
8143 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008144 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008145 return;
8146 }
8147
Karl Schultz6addd812016-02-02 17:17:23 -07008148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8149
8150 VkDescriptorPoolSize ds_type_count = {};
8151 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8152 ds_type_count.descriptorCount = 1;
8153
8154 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8155 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8156 ds_pool_ci.maxSets = 1;
8157 ds_pool_ci.poolSizeCount = 1;
8158 ds_pool_ci.pPoolSizes = &ds_type_count;
8159
8160 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008161 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008162 ASSERT_VK_SUCCESS(err);
8163
8164 VkDescriptorSetLayoutBinding dsl_binding = {};
8165 dsl_binding.binding = 0;
8166 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8167 dsl_binding.descriptorCount = 1;
8168 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8169
8170 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8171 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8172 ds_layout_ci.bindingCount = 1;
8173 ds_layout_ci.pBindings = &dsl_binding;
8174
8175 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008177 ASSERT_VK_SUCCESS(err);
8178
8179 VkDescriptorSet descriptorSet;
8180 VkDescriptorSetAllocateInfo alloc_info = {};
8181 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8182 alloc_info.descriptorSetCount = 1;
8183 alloc_info.descriptorPool = ds_pool;
8184 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008186 ASSERT_VK_SUCCESS(err);
8187
8188 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8189 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8190 pipeline_layout_ci.setLayoutCount = 1;
8191 pipeline_layout_ci.pSetLayouts = &ds_layout;
8192
8193 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008195 ASSERT_VK_SUCCESS(err);
8196
8197 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8198 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8199 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008200 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008201 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008202 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008203
8204 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8205 // Set scissor as dynamic to avoid that error
8206 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8207 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8208 dyn_state_ci.dynamicStateCount = 1;
8209 dyn_state_ci.pDynamicStates = &vp_state;
8210
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008211 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8212 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8213 pipe_ms_state_ci.pNext = NULL;
8214 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8215 pipe_ms_state_ci.sampleShadingEnable = 0;
8216 pipe_ms_state_ci.minSampleShading = 1.0;
8217 pipe_ms_state_ci.pSampleMask = NULL;
8218
Karl Schultz6addd812016-02-02 17:17:23 -07008219 VkPipelineShaderStageCreateInfo shaderStages[2];
8220 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008222 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008223 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8224 // 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 -07008225 shaderStages[0] = vs.GetStageCreateInfo();
8226 shaderStages[1] = fs.GetStageCreateInfo();
8227
8228 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8229 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8230 vi_ci.pNext = nullptr;
8231 vi_ci.vertexBindingDescriptionCount = 0;
8232 vi_ci.pVertexBindingDescriptions = nullptr;
8233 vi_ci.vertexAttributeDescriptionCount = 0;
8234 vi_ci.pVertexAttributeDescriptions = nullptr;
8235
8236 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8237 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8238 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8239
8240 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8241 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008242 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008243 rs_ci.pNext = nullptr;
8244
Mark Youngc89c6312016-03-31 16:03:20 -06008245 VkPipelineColorBlendAttachmentState att = {};
8246 att.blendEnable = VK_FALSE;
8247 att.colorWriteMask = 0xf;
8248
Karl Schultz6addd812016-02-02 17:17:23 -07008249 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8250 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8251 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008252 cb_ci.attachmentCount = 1;
8253 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008254
8255 VkGraphicsPipelineCreateInfo gp_ci = {};
8256 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8257 gp_ci.stageCount = 2;
8258 gp_ci.pStages = shaderStages;
8259 gp_ci.pVertexInputState = &vi_ci;
8260 gp_ci.pInputAssemblyState = &ia_ci;
8261 gp_ci.pViewportState = &vp_state_ci;
8262 gp_ci.pRasterizationState = &rs_ci;
8263 gp_ci.pColorBlendState = &cb_ci;
8264 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008265 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008266 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8267 gp_ci.layout = pipeline_layout;
8268 gp_ci.renderPass = renderPass();
8269
8270 VkPipelineCacheCreateInfo pc_ci = {};
8271 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8272
8273 VkPipeline pipeline;
8274 VkPipelineCache pipelineCache;
8275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008276 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008277 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008279
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008280 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008281
8282 // Now hit second fail case where we set scissor w/ different count than PSO
8283 // First need to successfully create the PSO from above by setting
8284 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8286 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008287
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008288 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008289 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008290 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008291 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008292 m_commandBuffer->BeginCommandBuffer();
8293 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008294 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008295 VkViewport viewports[1] = {};
8296 viewports[0].width = 8;
8297 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008298 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008299 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008300 Draw(1, 0, 0, 0);
8301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008302 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008303
Chia-I Wuf7458c52015-10-26 21:10:41 +08008304 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8305 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8306 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8307 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008308 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008309}
8310
Mark Young7394fdd2016-03-31 14:56:43 -06008311TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8312 VkResult err;
8313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008315
8316 ASSERT_NO_FATAL_FAILURE(InitState());
8317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8318
8319 VkDescriptorPoolSize ds_type_count = {};
8320 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8321 ds_type_count.descriptorCount = 1;
8322
8323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8325 ds_pool_ci.maxSets = 1;
8326 ds_pool_ci.poolSizeCount = 1;
8327 ds_pool_ci.pPoolSizes = &ds_type_count;
8328
8329 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008330 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008331 ASSERT_VK_SUCCESS(err);
8332
8333 VkDescriptorSetLayoutBinding dsl_binding = {};
8334 dsl_binding.binding = 0;
8335 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8336 dsl_binding.descriptorCount = 1;
8337 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8338
8339 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8340 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8341 ds_layout_ci.bindingCount = 1;
8342 ds_layout_ci.pBindings = &dsl_binding;
8343
8344 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008345 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008346 ASSERT_VK_SUCCESS(err);
8347
8348 VkDescriptorSet descriptorSet;
8349 VkDescriptorSetAllocateInfo alloc_info = {};
8350 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8351 alloc_info.descriptorSetCount = 1;
8352 alloc_info.descriptorPool = ds_pool;
8353 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008355 ASSERT_VK_SUCCESS(err);
8356
8357 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8358 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8359 pipeline_layout_ci.setLayoutCount = 1;
8360 pipeline_layout_ci.pSetLayouts = &ds_layout;
8361
8362 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008364 ASSERT_VK_SUCCESS(err);
8365
8366 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8367 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8368 vp_state_ci.scissorCount = 1;
8369 vp_state_ci.pScissors = NULL;
8370 vp_state_ci.viewportCount = 1;
8371 vp_state_ci.pViewports = NULL;
8372
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008373 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008374 // Set scissor as dynamic to avoid that error
8375 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8376 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8377 dyn_state_ci.dynamicStateCount = 2;
8378 dyn_state_ci.pDynamicStates = dynamic_states;
8379
8380 VkPipelineShaderStageCreateInfo shaderStages[2];
8381 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8382
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008383 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8384 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008385 this); // TODO - We shouldn't need a fragment shader
8386 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008387 shaderStages[0] = vs.GetStageCreateInfo();
8388 shaderStages[1] = fs.GetStageCreateInfo();
8389
8390 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8391 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8392 vi_ci.pNext = nullptr;
8393 vi_ci.vertexBindingDescriptionCount = 0;
8394 vi_ci.pVertexBindingDescriptions = nullptr;
8395 vi_ci.vertexAttributeDescriptionCount = 0;
8396 vi_ci.pVertexAttributeDescriptions = nullptr;
8397
8398 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8399 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8400 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8401
8402 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8403 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8404 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008405 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008406
Mark Young47107952016-05-02 15:59:55 -06008407 // Check too low (line width of -1.0f).
8408 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008409
8410 VkPipelineColorBlendAttachmentState att = {};
8411 att.blendEnable = VK_FALSE;
8412 att.colorWriteMask = 0xf;
8413
8414 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8415 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8416 cb_ci.pNext = nullptr;
8417 cb_ci.attachmentCount = 1;
8418 cb_ci.pAttachments = &att;
8419
8420 VkGraphicsPipelineCreateInfo gp_ci = {};
8421 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8422 gp_ci.stageCount = 2;
8423 gp_ci.pStages = shaderStages;
8424 gp_ci.pVertexInputState = &vi_ci;
8425 gp_ci.pInputAssemblyState = &ia_ci;
8426 gp_ci.pViewportState = &vp_state_ci;
8427 gp_ci.pRasterizationState = &rs_ci;
8428 gp_ci.pColorBlendState = &cb_ci;
8429 gp_ci.pDynamicState = &dyn_state_ci;
8430 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8431 gp_ci.layout = pipeline_layout;
8432 gp_ci.renderPass = renderPass();
8433
8434 VkPipelineCacheCreateInfo pc_ci = {};
8435 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8436
8437 VkPipeline pipeline;
8438 VkPipelineCache pipelineCache;
8439
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008440 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008441 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008442 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008443
8444 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008445 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008446
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008448
8449 // Check too high (line width of 65536.0f).
8450 rs_ci.lineWidth = 65536.0f;
8451
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008452 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008453 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008455
8456 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008457 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008460
8461 dyn_state_ci.dynamicStateCount = 3;
8462
8463 rs_ci.lineWidth = 1.0f;
8464
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008465 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008466 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008467 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008468 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008470
8471 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008472 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008473 m_errorMonitor->VerifyFound();
8474
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008476
8477 // Check too high with dynamic setting.
8478 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8479 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008480 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008481
8482 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8483 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8484 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8485 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008486 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008487}
8488
Karl Schultz6addd812016-02-02 17:17:23 -07008489TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008490 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008492 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008493
8494 ASSERT_NO_FATAL_FAILURE(InitState());
8495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008496
Tony Barbour552f6c02016-12-21 14:34:07 -07008497 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008498 // Don't care about RenderPass handle b/c error should be flagged before
8499 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008500 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008501
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008502 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008503}
8504
Karl Schultz6addd812016-02-02 17:17:23 -07008505TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008506 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8508 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008509
8510 ASSERT_NO_FATAL_FAILURE(InitState());
8511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008512
Tony Barbour552f6c02016-12-21 14:34:07 -07008513 m_commandBuffer->BeginCommandBuffer();
8514 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008515 // Just create a dummy Renderpass that's non-NULL so we can get to the
8516 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008517 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008518
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008519 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008520}
8521
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008522TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008523 TEST_DESCRIPTION(
8524 "Begin a renderPass where clearValueCount is less than"
8525 "the number of renderPass attachments that use loadOp"
8526 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008527
8528 ASSERT_NO_FATAL_FAILURE(InitState());
8529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8530
8531 // Create a renderPass with a single attachment that uses loadOp CLEAR
8532 VkAttachmentReference attach = {};
8533 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8534 VkSubpassDescription subpass = {};
8535 subpass.inputAttachmentCount = 1;
8536 subpass.pInputAttachments = &attach;
8537 VkRenderPassCreateInfo rpci = {};
8538 rpci.subpassCount = 1;
8539 rpci.pSubpasses = &subpass;
8540 rpci.attachmentCount = 1;
8541 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008542 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008543 // Set loadOp to CLEAR
8544 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8545 rpci.pAttachments = &attach_desc;
8546 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8547 VkRenderPass rp;
8548 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8549
8550 VkCommandBufferInheritanceInfo hinfo = {};
8551 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8552 hinfo.renderPass = VK_NULL_HANDLE;
8553 hinfo.subpass = 0;
8554 hinfo.framebuffer = VK_NULL_HANDLE;
8555 hinfo.occlusionQueryEnable = VK_FALSE;
8556 hinfo.queryFlags = 0;
8557 hinfo.pipelineStatistics = 0;
8558 VkCommandBufferBeginInfo info = {};
8559 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8560 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8561 info.pInheritanceInfo = &hinfo;
8562
8563 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8564 VkRenderPassBeginInfo rp_begin = {};
8565 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8566 rp_begin.pNext = NULL;
8567 rp_begin.renderPass = renderPass();
8568 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008569 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008570
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008574
8575 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008576
8577 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008578}
8579
Slawomir Cygan0808f392016-11-28 17:53:23 +01008580TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008581 TEST_DESCRIPTION(
8582 "Begin a renderPass where clearValueCount is greater than"
8583 "the number of renderPass attachments that use loadOp"
8584 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008585
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 = {};
8600 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8601 // 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 VkCommandBufferBeginInfo info = {};
8609 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8610 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8611
8612 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8613 VkRenderPassBeginInfo rp_begin = {};
8614 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8615 rp_begin.pNext = NULL;
8616 rp_begin.renderPass = renderPass();
8617 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008618 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008619
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8621 " has a clearValueCount of"
8622 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008623
8624 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8625
8626 m_errorMonitor->VerifyFound();
8627
8628 vkDestroyRenderPass(m_device->device(), rp, NULL);
8629}
8630
Cody Northrop3bb4d962016-05-09 16:15:57 -06008631TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008632 TEST_DESCRIPTION("End a command buffer with an active render pass");
8633
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8635 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008636
8637 ASSERT_NO_FATAL_FAILURE(InitState());
8638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8639
Tony Barbour552f6c02016-12-21 14:34:07 -07008640 m_commandBuffer->BeginCommandBuffer();
8641 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8642 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008643
8644 m_errorMonitor->VerifyFound();
8645
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008646 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8647 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008648}
8649
Karl Schultz6addd812016-02-02 17:17:23 -07008650TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008651 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8653 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008654
8655 ASSERT_NO_FATAL_FAILURE(InitState());
8656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008657
Tony Barbour552f6c02016-12-21 14:34:07 -07008658 m_commandBuffer->BeginCommandBuffer();
8659 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008660
8661 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008662 vk_testing::Buffer dstBuffer;
8663 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008664
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008665 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008666
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008667 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008668}
8669
Karl Schultz6addd812016-02-02 17:17:23 -07008670TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008671 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8673 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008674
8675 ASSERT_NO_FATAL_FAILURE(InitState());
8676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008677
Tony Barbour552f6c02016-12-21 14:34:07 -07008678 m_commandBuffer->BeginCommandBuffer();
8679 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008680
8681 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008682 vk_testing::Buffer dstBuffer;
8683 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008684
Karl Schultz6addd812016-02-02 17:17:23 -07008685 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008686 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8687 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8688 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008689
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008690 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008691}
8692
Karl Schultz6addd812016-02-02 17:17:23 -07008693TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008694 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8696 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008697
8698 ASSERT_NO_FATAL_FAILURE(InitState());
8699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008700
Tony Barbour552f6c02016-12-21 14:34:07 -07008701 m_commandBuffer->BeginCommandBuffer();
8702 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008703
Michael Lentine0a369f62016-02-03 16:51:46 -06008704 VkClearColorValue clear_color;
8705 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008706 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8707 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8708 const int32_t tex_width = 32;
8709 const int32_t tex_height = 32;
8710 VkImageCreateInfo image_create_info = {};
8711 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8712 image_create_info.pNext = NULL;
8713 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8714 image_create_info.format = tex_format;
8715 image_create_info.extent.width = tex_width;
8716 image_create_info.extent.height = tex_height;
8717 image_create_info.extent.depth = 1;
8718 image_create_info.mipLevels = 1;
8719 image_create_info.arrayLayers = 1;
8720 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8721 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8722 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008723
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008724 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008725 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008727 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008728
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008729 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008730 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008731
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008732 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008733}
8734
Karl Schultz6addd812016-02-02 17:17:23 -07008735TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008736 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8738 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008739
8740 ASSERT_NO_FATAL_FAILURE(InitState());
8741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008742
Tony Barbour552f6c02016-12-21 14:34:07 -07008743 m_commandBuffer->BeginCommandBuffer();
8744 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008745
8746 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008747 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008748 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8749 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8750 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8751 image_create_info.extent.width = 64;
8752 image_create_info.extent.height = 64;
8753 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8754 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008755
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008756 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008757 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008759 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008761 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8762 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008763
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008764 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008765}
8766
Karl Schultz6addd812016-02-02 17:17:23 -07008767TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008768 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008769 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008770
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8772 "vkCmdClearAttachments(): This call "
8773 "must be issued inside an active "
8774 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008775
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008776 ASSERT_NO_FATAL_FAILURE(InitState());
8777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008778
8779 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008780 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008781 ASSERT_VK_SUCCESS(err);
8782
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008783 VkClearAttachment color_attachment;
8784 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8785 color_attachment.clearValue.color.float32[0] = 0;
8786 color_attachment.clearValue.color.float32[1] = 0;
8787 color_attachment.clearValue.color.float32[2] = 0;
8788 color_attachment.clearValue.color.float32[3] = 0;
8789 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008790 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008792
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008793 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008794}
8795
Chris Forbes3b97e932016-09-07 11:29:24 +12008796TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008797 TEST_DESCRIPTION(
8798 "Test that an error is produced when CmdNextSubpass is "
8799 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008800
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8802 "vkCmdNextSubpass(): Attempted to advance "
8803 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008804
8805 ASSERT_NO_FATAL_FAILURE(InitState());
8806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8807
Tony Barbour552f6c02016-12-21 14:34:07 -07008808 m_commandBuffer->BeginCommandBuffer();
8809 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008810
8811 // error here.
8812 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8813 m_errorMonitor->VerifyFound();
8814
Tony Barbour552f6c02016-12-21 14:34:07 -07008815 m_commandBuffer->EndRenderPass();
8816 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008817}
8818
Chris Forbes6d624702016-09-07 13:57:05 +12008819TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008820 TEST_DESCRIPTION(
8821 "Test that an error is produced when CmdEndRenderPass is "
8822 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008823
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8825 "vkCmdEndRenderPass(): Called before reaching "
8826 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008827
8828 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008829 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8830 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008831
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008832 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008833
8834 VkRenderPass rp;
8835 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8836 ASSERT_VK_SUCCESS(err);
8837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008838 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008839
8840 VkFramebuffer fb;
8841 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8842 ASSERT_VK_SUCCESS(err);
8843
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008844 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008845
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 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 +12008847
8848 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8849
8850 // Error here.
8851 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8852 m_errorMonitor->VerifyFound();
8853
8854 // Clean up.
8855 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8856 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8857}
8858
Karl Schultz9e66a292016-04-21 15:57:51 -06008859TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8860 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8862 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008863
8864 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008865 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008866
8867 VkBufferMemoryBarrier buf_barrier = {};
8868 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8869 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8870 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8871 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8872 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8873 buf_barrier.buffer = VK_NULL_HANDLE;
8874 buf_barrier.offset = 0;
8875 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008876 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8877 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008878
8879 m_errorMonitor->VerifyFound();
8880}
8881
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008882TEST_F(VkLayerTest, InvalidBarriers) {
8883 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008886
8887 ASSERT_NO_FATAL_FAILURE(InitState());
8888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8889
8890 VkMemoryBarrier mem_barrier = {};
8891 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8892 mem_barrier.pNext = NULL;
8893 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8894 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008895 m_commandBuffer->BeginCommandBuffer();
8896 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008897 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008898 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008899 &mem_barrier, 0, nullptr, 0, nullptr);
8900 m_errorMonitor->VerifyFound();
8901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008903 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008904 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 -06008905 ASSERT_TRUE(image.initialized());
8906 VkImageMemoryBarrier img_barrier = {};
8907 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8908 img_barrier.pNext = NULL;
8909 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8910 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8911 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8912 // New layout can't be UNDEFINED
8913 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8914 img_barrier.image = image.handle();
8915 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8916 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8917 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8918 img_barrier.subresourceRange.baseArrayLayer = 0;
8919 img_barrier.subresourceRange.baseMipLevel = 0;
8920 img_barrier.subresourceRange.layerCount = 1;
8921 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008922 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8923 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008924 m_errorMonitor->VerifyFound();
8925 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8926
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8928 "Subresource must have the sum of the "
8929 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008930 // baseArrayLayer + layerCount must be <= image's arrayLayers
8931 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008932 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8933 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008934 m_errorMonitor->VerifyFound();
8935 img_barrier.subresourceRange.baseArrayLayer = 0;
8936
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008938 // baseMipLevel + levelCount must be <= image's mipLevels
8939 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008940 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8941 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008942 m_errorMonitor->VerifyFound();
8943 img_barrier.subresourceRange.baseMipLevel = 0;
8944
Mike Weiblen7053aa32017-01-25 15:21:10 -07008945 // levelCount must be non-zero.
8946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8947 img_barrier.subresourceRange.levelCount = 0;
8948 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8949 nullptr, 0, nullptr, 1, &img_barrier);
8950 m_errorMonitor->VerifyFound();
8951 img_barrier.subresourceRange.levelCount = 1;
8952
8953 // layerCount must be non-zero.
8954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8955 img_barrier.subresourceRange.layerCount = 0;
8956 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8957 nullptr, 0, nullptr, 1, &img_barrier);
8958 m_errorMonitor->VerifyFound();
8959 img_barrier.subresourceRange.layerCount = 1;
8960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008961 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 -06008962 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008963 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8964 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008965 VkBufferMemoryBarrier buf_barrier = {};
8966 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8967 buf_barrier.pNext = NULL;
8968 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8969 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8970 buf_barrier.buffer = buffer.handle();
8971 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8972 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8973 buf_barrier.offset = 0;
8974 buf_barrier.size = VK_WHOLE_SIZE;
8975 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008976 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8977 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008978 m_errorMonitor->VerifyFound();
8979 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008982 buf_barrier.offset = 257;
8983 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008984 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8985 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008986 m_errorMonitor->VerifyFound();
8987 buf_barrier.offset = 0;
8988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008990 buf_barrier.size = 257;
8991 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008992 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8993 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008994 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008995
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008996 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008997 m_errorMonitor->SetDesiredFailureMsg(
8998 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008999 "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 -06009000 VkDepthStencilObj ds_image(m_device);
9001 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9002 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009003 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9004 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009005 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009006
9007 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009008 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009009 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9010 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009011 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009012
9013 // Having anything other than DEPTH or STENCIL is an error
9014 m_errorMonitor->SetDesiredFailureMsg(
9015 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9016 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9017 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9018 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9019 nullptr, 0, nullptr, 1, &img_barrier);
9020 m_errorMonitor->VerifyFound();
9021
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009022 // Now test depth-only
9023 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009024 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9025 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009026 VkDepthStencilObj d_image(m_device);
9027 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9028 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009029 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009030 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009031 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009032
9033 // DEPTH bit must be set
9034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9035 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009036 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009037 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9038 0, nullptr, 0, nullptr, 1, &img_barrier);
9039 m_errorMonitor->VerifyFound();
9040
9041 // No bits other than DEPTH may be set
9042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9043 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9044 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009045 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9046 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009047 m_errorMonitor->VerifyFound();
9048 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009049
9050 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009051 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9052 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9054 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009055 VkDepthStencilObj s_image(m_device);
9056 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9057 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009058 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009059 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009060 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009061 // Use of COLOR aspect on depth image is error
9062 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009063 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9064 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009065 m_errorMonitor->VerifyFound();
9066 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009067
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009068 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009069 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009070 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 -06009071 ASSERT_TRUE(c_image.initialized());
9072 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9073 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9074 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009075
9076 // COLOR bit must be set
9077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9078 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009079 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009080 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9081 nullptr, 0, nullptr, 1, &img_barrier);
9082 m_errorMonitor->VerifyFound();
9083
9084 // No bits other than COLOR may be set
9085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9086 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9087 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009088 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9089 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009090 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009091
9092 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9093
9094 // Create command pool with incompatible queueflags
9095 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9096 uint32_t queue_family_index = UINT32_MAX;
9097 for (uint32_t i = 0; i < queue_props.size(); i++) {
9098 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9099 queue_family_index = i;
9100 break;
9101 }
9102 }
9103 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009104 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009105 return;
9106 }
9107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9108
9109 VkCommandPool command_pool;
9110 VkCommandPoolCreateInfo pool_create_info{};
9111 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9112 pool_create_info.queueFamilyIndex = queue_family_index;
9113 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9114 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9115
9116 // Allocate a command buffer
9117 VkCommandBuffer bad_command_buffer;
9118 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9119 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9120 command_buffer_allocate_info.commandPool = command_pool;
9121 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9122 command_buffer_allocate_info.commandBufferCount = 1;
9123 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9124
9125 VkCommandBufferBeginInfo cbbi = {};
9126 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9127 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9128 buf_barrier.offset = 0;
9129 buf_barrier.size = VK_WHOLE_SIZE;
9130 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9131 &buf_barrier, 0, nullptr);
9132 m_errorMonitor->VerifyFound();
9133
9134 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9135 vkEndCommandBuffer(bad_command_buffer);
9136 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009137 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009138 return;
9139 }
9140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9141 VkEvent event;
9142 VkEventCreateInfo event_create_info{};
9143 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9144 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9145 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9146 nullptr, 0, nullptr);
9147 m_errorMonitor->VerifyFound();
9148
9149 vkEndCommandBuffer(bad_command_buffer);
9150 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009151}
9152
Tony Barbour18ba25c2016-09-29 13:42:40 -06009153TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9154 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9155
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009157 ASSERT_NO_FATAL_FAILURE(InitState());
9158 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009159 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 -06009160 ASSERT_TRUE(image.initialized());
9161
9162 VkImageMemoryBarrier barrier = {};
9163 VkImageSubresourceRange range;
9164 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9165 barrier.srcAccessMask = 0;
9166 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9167 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9168 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9169 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9170 barrier.image = image.handle();
9171 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9172 range.baseMipLevel = 0;
9173 range.levelCount = 1;
9174 range.baseArrayLayer = 0;
9175 range.layerCount = 1;
9176 barrier.subresourceRange = range;
9177 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9178 cmdbuf.BeginCommandBuffer();
9179 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9180 &barrier);
9181 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9182 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9183 barrier.srcAccessMask = 0;
9184 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9185 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9186 &barrier);
9187
9188 m_errorMonitor->VerifyFound();
9189}
9190
Karl Schultz6addd812016-02-02 17:17:23 -07009191TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009192 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009193 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009196
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009197 ASSERT_NO_FATAL_FAILURE(InitState());
9198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009199 uint32_t qfi = 0;
9200 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009201 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9202 buffCI.size = 1024;
9203 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9204 buffCI.queueFamilyIndexCount = 1;
9205 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009206
9207 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009208 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009209 ASSERT_VK_SUCCESS(err);
9210
Tony Barbour552f6c02016-12-21 14:34:07 -07009211 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009212 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009213 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9214 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009215 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009216 m_errorMonitor->SetUnexpectedError(
9217 "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 -06009218 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009219
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009220 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009221
Chia-I Wuf7458c52015-10-26 21:10:41 +08009222 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009223}
9224
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009225TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9226 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9228 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9229 "of the indices specified when the device was created, via the "
9230 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009231
9232 ASSERT_NO_FATAL_FAILURE(InitState());
9233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9234 VkBufferCreateInfo buffCI = {};
9235 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9236 buffCI.size = 1024;
9237 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9238 buffCI.queueFamilyIndexCount = 1;
9239 // Introduce failure by specifying invalid queue_family_index
9240 uint32_t qfi = 777;
9241 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009242 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009243
9244 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009245 m_errorMonitor->SetUnexpectedError(
9246 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009247 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9248
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009249 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009250 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009251}
9252
Karl Schultz6addd812016-02-02 17:17:23 -07009253TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009254 TEST_DESCRIPTION(
9255 "Attempt vkCmdExecuteCommands with a primary command buffer"
9256 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009257
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009258 ASSERT_NO_FATAL_FAILURE(InitState());
9259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009260
Chris Forbesf29a84f2016-10-06 18:39:28 +13009261 // An empty primary command buffer
9262 VkCommandBufferObj cb(m_device, m_commandPool);
9263 cb.BeginCommandBuffer();
9264 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009265
Chris Forbesf29a84f2016-10-06 18:39:28 +13009266 m_commandBuffer->BeginCommandBuffer();
9267 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9268 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009269
Chris Forbesf29a84f2016-10-06 18:39:28 +13009270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9271 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009272 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009273
9274 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009275}
9276
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009277TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009278 TEST_DESCRIPTION(
9279 "Attempt to update descriptor sets for images and buffers "
9280 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009281 VkResult err;
9282
9283 ASSERT_NO_FATAL_FAILURE(InitState());
9284 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9285 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9286 ds_type_count[i].type = VkDescriptorType(i);
9287 ds_type_count[i].descriptorCount = 1;
9288 }
9289 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9290 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9291 ds_pool_ci.pNext = NULL;
9292 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9293 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9294 ds_pool_ci.pPoolSizes = ds_type_count;
9295
9296 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009297 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009298 ASSERT_VK_SUCCESS(err);
9299
9300 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009301 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009302 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9303 dsl_binding[i].binding = 0;
9304 dsl_binding[i].descriptorType = VkDescriptorType(i);
9305 dsl_binding[i].descriptorCount = 1;
9306 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9307 dsl_binding[i].pImmutableSamplers = NULL;
9308 }
9309
9310 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9311 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9312 ds_layout_ci.pNext = NULL;
9313 ds_layout_ci.bindingCount = 1;
9314 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9315 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9316 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009317 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009318 ASSERT_VK_SUCCESS(err);
9319 }
9320 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9321 VkDescriptorSetAllocateInfo alloc_info = {};
9322 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9323 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9324 alloc_info.descriptorPool = ds_pool;
9325 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009326 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009327 ASSERT_VK_SUCCESS(err);
9328
9329 // Create a buffer & bufferView to be used for invalid updates
9330 VkBufferCreateInfo buff_ci = {};
9331 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009332 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009333 buff_ci.size = 256;
9334 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009335 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009336 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9337 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009338
9339 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9340 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9341 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9342 ASSERT_VK_SUCCESS(err);
9343
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009344 VkMemoryRequirements mem_reqs;
9345 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9346 VkMemoryAllocateInfo mem_alloc_info = {};
9347 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9348 mem_alloc_info.pNext = NULL;
9349 mem_alloc_info.memoryTypeIndex = 0;
9350 mem_alloc_info.allocationSize = mem_reqs.size;
9351 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9352 if (!pass) {
9353 vkDestroyBuffer(m_device->device(), buffer, NULL);
9354 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9355 return;
9356 }
9357 VkDeviceMemory mem;
9358 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9359 ASSERT_VK_SUCCESS(err);
9360 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9361 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009362
9363 VkBufferViewCreateInfo buff_view_ci = {};
9364 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9365 buff_view_ci.buffer = buffer;
9366 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9367 buff_view_ci.range = VK_WHOLE_SIZE;
9368 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009369 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009370 ASSERT_VK_SUCCESS(err);
9371
Tony Barbour415497c2017-01-24 10:06:09 -07009372 // Now get resources / view for storage_texel_buffer
9373 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9374 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9375 if (!pass) {
9376 vkDestroyBuffer(m_device->device(), buffer, NULL);
9377 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9378 vkFreeMemory(m_device->device(), mem, NULL);
9379 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9381 return;
9382 }
9383 VkDeviceMemory storage_texel_buffer_mem;
9384 VkBufferView storage_texel_buffer_view;
9385 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9386 ASSERT_VK_SUCCESS(err);
9387 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9388 ASSERT_VK_SUCCESS(err);
9389 buff_view_ci.buffer = storage_texel_buffer;
9390 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9391 ASSERT_VK_SUCCESS(err);
9392
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009393 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009394 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009395 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009396 image_ci.format = VK_FORMAT_UNDEFINED;
9397 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9398 VkFormat format = static_cast<VkFormat>(f);
9399 VkFormatProperties fProps = m_device->format_properties(format);
9400 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9401 image_ci.format = format;
9402 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9403 break;
9404 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9405 image_ci.format = format;
9406 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9407 break;
9408 }
9409 }
9410 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9411 return;
9412 }
9413
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009414 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9415 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009416 image_ci.extent.width = 64;
9417 image_ci.extent.height = 64;
9418 image_ci.extent.depth = 1;
9419 image_ci.mipLevels = 1;
9420 image_ci.arrayLayers = 1;
9421 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009422 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009423 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009424 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9425 VkImage image;
9426 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9427 ASSERT_VK_SUCCESS(err);
9428 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009429 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009430
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009431 VkMemoryAllocateInfo mem_alloc = {};
9432 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9433 mem_alloc.pNext = NULL;
9434 mem_alloc.allocationSize = 0;
9435 mem_alloc.memoryTypeIndex = 0;
9436 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9437 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009438 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009439 ASSERT_TRUE(pass);
9440 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9441 ASSERT_VK_SUCCESS(err);
9442 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9443 ASSERT_VK_SUCCESS(err);
9444 // Now create view for image
9445 VkImageViewCreateInfo image_view_ci = {};
9446 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9447 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009448 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009449 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9450 image_view_ci.subresourceRange.layerCount = 1;
9451 image_view_ci.subresourceRange.baseArrayLayer = 0;
9452 image_view_ci.subresourceRange.levelCount = 1;
9453 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9454 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009455 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009456 ASSERT_VK_SUCCESS(err);
9457
9458 VkDescriptorBufferInfo buff_info = {};
9459 buff_info.buffer = buffer;
9460 VkDescriptorImageInfo img_info = {};
9461 img_info.imageView = image_view;
9462 VkWriteDescriptorSet descriptor_write = {};
9463 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9464 descriptor_write.dstBinding = 0;
9465 descriptor_write.descriptorCount = 1;
9466 descriptor_write.pTexelBufferView = &buff_view;
9467 descriptor_write.pBufferInfo = &buff_info;
9468 descriptor_write.pImageInfo = &img_info;
9469
9470 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009471 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009472 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9473 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9474 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9475 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9476 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9477 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9478 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9479 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9480 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9481 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9482 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009483 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009484 // Start loop at 1 as SAMPLER desc type has no usage bit error
9485 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009486 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9487 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9488 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9489 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009490 descriptor_write.descriptorType = VkDescriptorType(i);
9491 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009493
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009495
9496 m_errorMonitor->VerifyFound();
9497 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009498 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9499 descriptor_write.pTexelBufferView = &buff_view;
9500 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009501 }
Tony Barbour415497c2017-01-24 10:06:09 -07009502
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009503 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9504 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009505 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009506 vkDestroyImageView(m_device->device(), image_view, NULL);
9507 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009508 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009509 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009510 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009511 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009512 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009513 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9514}
9515
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009516TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009517 TEST_DESCRIPTION(
9518 "Attempt to update buffer descriptor set that has incorrect "
9519 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9520 "1. offset value greater than buffer size\n"
9521 "2. range value of 0\n"
9522 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009523 VkResult err;
9524
9525 ASSERT_NO_FATAL_FAILURE(InitState());
9526 VkDescriptorPoolSize ds_type_count = {};
9527 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9528 ds_type_count.descriptorCount = 1;
9529
9530 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9531 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9532 ds_pool_ci.pNext = NULL;
9533 ds_pool_ci.maxSets = 1;
9534 ds_pool_ci.poolSizeCount = 1;
9535 ds_pool_ci.pPoolSizes = &ds_type_count;
9536
9537 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009538 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009539 ASSERT_VK_SUCCESS(err);
9540
9541 // Create layout with single uniform buffer descriptor
9542 VkDescriptorSetLayoutBinding dsl_binding = {};
9543 dsl_binding.binding = 0;
9544 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9545 dsl_binding.descriptorCount = 1;
9546 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9547 dsl_binding.pImmutableSamplers = NULL;
9548
9549 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9550 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9551 ds_layout_ci.pNext = NULL;
9552 ds_layout_ci.bindingCount = 1;
9553 ds_layout_ci.pBindings = &dsl_binding;
9554 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009555 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009556 ASSERT_VK_SUCCESS(err);
9557
9558 VkDescriptorSet descriptor_set = {};
9559 VkDescriptorSetAllocateInfo alloc_info = {};
9560 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9561 alloc_info.descriptorSetCount = 1;
9562 alloc_info.descriptorPool = ds_pool;
9563 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009565 ASSERT_VK_SUCCESS(err);
9566
9567 // Create a buffer to be used for invalid updates
9568 VkBufferCreateInfo buff_ci = {};
9569 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9570 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9571 buff_ci.size = 256;
9572 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9573 VkBuffer buffer;
9574 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9575 ASSERT_VK_SUCCESS(err);
9576 // Have to bind memory to buffer before descriptor update
9577 VkMemoryAllocateInfo mem_alloc = {};
9578 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9579 mem_alloc.pNext = NULL;
9580 mem_alloc.allocationSize = 256;
9581 mem_alloc.memoryTypeIndex = 0;
9582
9583 VkMemoryRequirements mem_reqs;
9584 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009586 if (!pass) {
9587 vkDestroyBuffer(m_device->device(), buffer, NULL);
9588 return;
9589 }
9590
9591 VkDeviceMemory mem;
9592 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9593 ASSERT_VK_SUCCESS(err);
9594 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9595 ASSERT_VK_SUCCESS(err);
9596
9597 VkDescriptorBufferInfo buff_info = {};
9598 buff_info.buffer = buffer;
9599 // First make offset 1 larger than buffer size
9600 buff_info.offset = 257;
9601 buff_info.range = VK_WHOLE_SIZE;
9602 VkWriteDescriptorSet descriptor_write = {};
9603 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9604 descriptor_write.dstBinding = 0;
9605 descriptor_write.descriptorCount = 1;
9606 descriptor_write.pTexelBufferView = nullptr;
9607 descriptor_write.pBufferInfo = &buff_info;
9608 descriptor_write.pImageInfo = nullptr;
9609
9610 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9611 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009613
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009614 m_errorMonitor->SetUnexpectedError(
9615 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9616 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009617 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9618
9619 m_errorMonitor->VerifyFound();
9620 // Now cause error due to range of 0
9621 buff_info.offset = 0;
9622 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009624
9625 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9626
9627 m_errorMonitor->VerifyFound();
9628 // Now cause error due to range exceeding buffer size - offset
9629 buff_info.offset = 128;
9630 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009632
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009633 m_errorMonitor->SetUnexpectedError(
9634 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9635 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009636 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9637
9638 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009639 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009640 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9641 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009642 m_errorMonitor->SetUnexpectedError(
9643 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009644 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9645 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9646}
9647
Tobin Ehlis845887e2017-02-02 19:01:44 -07009648TEST_F(VkLayerTest, DSBufferLimitErrors) {
9649 TEST_DESCRIPTION(
9650 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9651 "Test cases include:\n"
9652 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9653 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9654 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9655 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9656 VkResult err;
9657
9658 ASSERT_NO_FATAL_FAILURE(InitState());
9659 VkDescriptorPoolSize ds_type_count[2] = {};
9660 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9661 ds_type_count[0].descriptorCount = 1;
9662 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9663 ds_type_count[1].descriptorCount = 1;
9664
9665 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9666 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9667 ds_pool_ci.pNext = NULL;
9668 ds_pool_ci.maxSets = 1;
9669 ds_pool_ci.poolSizeCount = 2;
9670 ds_pool_ci.pPoolSizes = ds_type_count;
9671
9672 VkDescriptorPool ds_pool;
9673 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9674 ASSERT_VK_SUCCESS(err);
9675
9676 // Create layout with single uniform buffer & single storage buffer descriptor
9677 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9678 dsl_binding[0].binding = 0;
9679 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9680 dsl_binding[0].descriptorCount = 1;
9681 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9682 dsl_binding[0].pImmutableSamplers = NULL;
9683 dsl_binding[1].binding = 1;
9684 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9685 dsl_binding[1].descriptorCount = 1;
9686 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9687 dsl_binding[1].pImmutableSamplers = NULL;
9688
9689 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9690 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9691 ds_layout_ci.pNext = NULL;
9692 ds_layout_ci.bindingCount = 2;
9693 ds_layout_ci.pBindings = dsl_binding;
9694 VkDescriptorSetLayout ds_layout;
9695 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9696 ASSERT_VK_SUCCESS(err);
9697
9698 VkDescriptorSet descriptor_set = {};
9699 VkDescriptorSetAllocateInfo alloc_info = {};
9700 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9701 alloc_info.descriptorSetCount = 1;
9702 alloc_info.descriptorPool = ds_pool;
9703 alloc_info.pSetLayouts = &ds_layout;
9704 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9705 ASSERT_VK_SUCCESS(err);
9706
9707 // Create a buffer to be used for invalid updates
9708 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9709 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9710 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9711 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9712 VkBufferCreateInfo ub_ci = {};
9713 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9714 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9715 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9716 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9717 VkBuffer uniform_buffer;
9718 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9719 ASSERT_VK_SUCCESS(err);
9720 VkBufferCreateInfo sb_ci = {};
9721 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9722 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9723 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9724 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9725 VkBuffer storage_buffer;
9726 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9727 ASSERT_VK_SUCCESS(err);
9728 // Have to bind memory to buffer before descriptor update
9729 VkMemoryAllocateInfo mem_alloc = {};
9730 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9731 mem_alloc.pNext = NULL;
9732 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9733 mem_alloc.memoryTypeIndex = 0;
9734
9735 VkMemoryRequirements mem_reqs;
9736 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9737 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9738 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9739 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9740 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009741 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009742 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009743 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9744 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009745 return;
9746 }
9747
9748 VkDeviceMemory mem;
9749 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009750 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009751 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009752 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9753 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9754 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9755 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9756 return;
9757 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009758 ASSERT_VK_SUCCESS(err);
9759 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9760 ASSERT_VK_SUCCESS(err);
9761 auto sb_offset = ub_ci.size + 1024;
9762 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9763 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9764 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9765 ASSERT_VK_SUCCESS(err);
9766
9767 VkDescriptorBufferInfo buff_info = {};
9768 buff_info.buffer = uniform_buffer;
9769 buff_info.range = ub_ci.size; // This will exceed limit
9770 VkWriteDescriptorSet descriptor_write = {};
9771 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9772 descriptor_write.dstBinding = 0;
9773 descriptor_write.descriptorCount = 1;
9774 descriptor_write.pTexelBufferView = nullptr;
9775 descriptor_write.pBufferInfo = &buff_info;
9776 descriptor_write.pImageInfo = nullptr;
9777
9778 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9779 descriptor_write.dstSet = descriptor_set;
9780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9781 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9782 m_errorMonitor->VerifyFound();
9783
9784 // Reduce size of range to acceptable limit & cause offset error
9785 buff_info.range = max_ub_range;
9786 buff_info.offset = min_ub_align - 1;
9787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9788 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9789 m_errorMonitor->VerifyFound();
9790
9791 // Now break storage updates
9792 buff_info.buffer = storage_buffer;
9793 buff_info.range = sb_ci.size; // This will exceed limit
9794 buff_info.offset = 0; // Reset offset for this update
9795
9796 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9797 descriptor_write.dstBinding = 1;
9798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9799 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9800 m_errorMonitor->VerifyFound();
9801
9802 // Reduce size of range to acceptable limit & cause offset error
9803 buff_info.range = max_sb_range;
9804 buff_info.offset = min_sb_align - 1;
9805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9806 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9807 m_errorMonitor->VerifyFound();
9808
9809 vkFreeMemory(m_device->device(), mem, NULL);
9810 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9811 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9812 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9813 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9814}
9815
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009816TEST_F(VkLayerTest, DSAspectBitsErrors) {
9817 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9818 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009819 TEST_DESCRIPTION(
9820 "Attempt to update descriptor sets for images "
9821 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009822 VkResult err;
9823
9824 ASSERT_NO_FATAL_FAILURE(InitState());
9825 VkDescriptorPoolSize ds_type_count = {};
9826 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9827 ds_type_count.descriptorCount = 1;
9828
9829 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9830 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9831 ds_pool_ci.pNext = NULL;
9832 ds_pool_ci.maxSets = 5;
9833 ds_pool_ci.poolSizeCount = 1;
9834 ds_pool_ci.pPoolSizes = &ds_type_count;
9835
9836 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009837 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009838 ASSERT_VK_SUCCESS(err);
9839
9840 VkDescriptorSetLayoutBinding dsl_binding = {};
9841 dsl_binding.binding = 0;
9842 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9843 dsl_binding.descriptorCount = 1;
9844 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9845 dsl_binding.pImmutableSamplers = NULL;
9846
9847 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9848 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9849 ds_layout_ci.pNext = NULL;
9850 ds_layout_ci.bindingCount = 1;
9851 ds_layout_ci.pBindings = &dsl_binding;
9852 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009853 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009854 ASSERT_VK_SUCCESS(err);
9855
9856 VkDescriptorSet descriptor_set = {};
9857 VkDescriptorSetAllocateInfo alloc_info = {};
9858 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9859 alloc_info.descriptorSetCount = 1;
9860 alloc_info.descriptorPool = ds_pool;
9861 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009862 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009863 ASSERT_VK_SUCCESS(err);
9864
9865 // Create an image to be used for invalid updates
9866 VkImageCreateInfo image_ci = {};
9867 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9868 image_ci.imageType = VK_IMAGE_TYPE_2D;
9869 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9870 image_ci.extent.width = 64;
9871 image_ci.extent.height = 64;
9872 image_ci.extent.depth = 1;
9873 image_ci.mipLevels = 1;
9874 image_ci.arrayLayers = 1;
9875 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9876 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9877 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9878 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9879 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9880 VkImage image;
9881 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9882 ASSERT_VK_SUCCESS(err);
9883 // Bind memory to image
9884 VkMemoryRequirements mem_reqs;
9885 VkDeviceMemory image_mem;
9886 bool pass;
9887 VkMemoryAllocateInfo mem_alloc = {};
9888 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9889 mem_alloc.pNext = NULL;
9890 mem_alloc.allocationSize = 0;
9891 mem_alloc.memoryTypeIndex = 0;
9892 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9893 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009894 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009895 ASSERT_TRUE(pass);
9896 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9897 ASSERT_VK_SUCCESS(err);
9898 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9899 ASSERT_VK_SUCCESS(err);
9900 // Now create view for image
9901 VkImageViewCreateInfo image_view_ci = {};
9902 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9903 image_view_ci.image = image;
9904 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9905 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9906 image_view_ci.subresourceRange.layerCount = 1;
9907 image_view_ci.subresourceRange.baseArrayLayer = 0;
9908 image_view_ci.subresourceRange.levelCount = 1;
9909 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009911
9912 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009913 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009914 ASSERT_VK_SUCCESS(err);
9915
9916 VkDescriptorImageInfo img_info = {};
9917 img_info.imageView = image_view;
9918 VkWriteDescriptorSet descriptor_write = {};
9919 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9920 descriptor_write.dstBinding = 0;
9921 descriptor_write.descriptorCount = 1;
9922 descriptor_write.pTexelBufferView = NULL;
9923 descriptor_write.pBufferInfo = NULL;
9924 descriptor_write.pImageInfo = &img_info;
9925 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9926 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009927 const char *error_msg =
9928 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9929 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009931
9932 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9933
9934 m_errorMonitor->VerifyFound();
9935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9936 vkDestroyImage(m_device->device(), image, NULL);
9937 vkFreeMemory(m_device->device(), image_mem, NULL);
9938 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009939 m_errorMonitor->SetUnexpectedError(
9940 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009941 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9942 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9943}
9944
Karl Schultz6addd812016-02-02 17:17:23 -07009945TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009946 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009947 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009948
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9950 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9951 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009952
Tobin Ehlis3b780662015-05-28 12:11:26 -06009953 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009954 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009955 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009956 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9957 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009958
9959 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009960 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9961 ds_pool_ci.pNext = NULL;
9962 ds_pool_ci.maxSets = 1;
9963 ds_pool_ci.poolSizeCount = 1;
9964 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009965
Tobin Ehlis3b780662015-05-28 12:11:26 -06009966 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009967 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009968 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009969 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009970 dsl_binding.binding = 0;
9971 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9972 dsl_binding.descriptorCount = 1;
9973 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9974 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009975
Tony Barboureb254902015-07-15 12:50:33 -06009976 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009977 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9978 ds_layout_ci.pNext = NULL;
9979 ds_layout_ci.bindingCount = 1;
9980 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009981
Tobin Ehlis3b780662015-05-28 12:11:26 -06009982 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009984 ASSERT_VK_SUCCESS(err);
9985
9986 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009987 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009988 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009989 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009990 alloc_info.descriptorPool = ds_pool;
9991 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009992 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009993 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009994
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009995 VkSamplerCreateInfo sampler_ci = {};
9996 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9997 sampler_ci.pNext = NULL;
9998 sampler_ci.magFilter = VK_FILTER_NEAREST;
9999 sampler_ci.minFilter = VK_FILTER_NEAREST;
10000 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10001 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10002 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10003 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10004 sampler_ci.mipLodBias = 1.0;
10005 sampler_ci.anisotropyEnable = VK_FALSE;
10006 sampler_ci.maxAnisotropy = 1;
10007 sampler_ci.compareEnable = VK_FALSE;
10008 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10009 sampler_ci.minLod = 1.0;
10010 sampler_ci.maxLod = 1.0;
10011 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10012 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10013 VkSampler sampler;
10014 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10015 ASSERT_VK_SUCCESS(err);
10016
10017 VkDescriptorImageInfo info = {};
10018 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010019
10020 VkWriteDescriptorSet descriptor_write;
10021 memset(&descriptor_write, 0, sizeof(descriptor_write));
10022 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010023 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010024 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010025 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010026 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010027 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010028
10029 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10030
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010031 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010032
Chia-I Wuf7458c52015-10-26 21:10:41 +080010033 vkDestroySampler(m_device->device(), sampler, NULL);
10034 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10035 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010036}
10037
Karl Schultz6addd812016-02-02 17:17:23 -070010038TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010039 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010040 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010041
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010043
Tobin Ehlis3b780662015-05-28 12:11:26 -060010044 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010045 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010046 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010047 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10048 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010049
10050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10052 ds_pool_ci.pNext = NULL;
10053 ds_pool_ci.maxSets = 1;
10054 ds_pool_ci.poolSizeCount = 1;
10055 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010056
Tobin Ehlis3b780662015-05-28 12:11:26 -060010057 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010058 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010059 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010060
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;
Tony Barboureb254902015-07-15 12:50:33 -060010067
10068 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 // Correctly update descriptor to avoid "NOT_UPDATED" error
10088 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010089 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010090 buff_info.offset = 0;
10091 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010092
10093 VkWriteDescriptorSet descriptor_write;
10094 memset(&descriptor_write, 0, sizeof(descriptor_write));
10095 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010096 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010097 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010098 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010099 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10100 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010101
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010102 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010103 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10104
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010105 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010106
Chia-I Wuf7458c52015-10-26 21:10:41 +080010107 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10108 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010109}
10110
Karl Schultz6addd812016-02-02 17:17:23 -070010111TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010112 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010113 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010114
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010116
Tobin Ehlis3b780662015-05-28 12:11:26 -060010117 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010118 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010119 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010120 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10121 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010122
10123 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010124 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10125 ds_pool_ci.pNext = NULL;
10126 ds_pool_ci.maxSets = 1;
10127 ds_pool_ci.poolSizeCount = 1;
10128 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010129
Tobin Ehlis3b780662015-05-28 12:11:26 -060010130 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010131 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010132 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010133
Tony Barboureb254902015-07-15 12:50:33 -060010134 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010135 dsl_binding.binding = 0;
10136 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10137 dsl_binding.descriptorCount = 1;
10138 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10139 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010140
10141 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010142 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10143 ds_layout_ci.pNext = NULL;
10144 ds_layout_ci.bindingCount = 1;
10145 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010146 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010147 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010148 ASSERT_VK_SUCCESS(err);
10149
10150 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010151 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010152 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010153 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010154 alloc_info.descriptorPool = ds_pool;
10155 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010157 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010158
Tony Barboureb254902015-07-15 12:50:33 -060010159 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010160 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10161 sampler_ci.pNext = NULL;
10162 sampler_ci.magFilter = VK_FILTER_NEAREST;
10163 sampler_ci.minFilter = VK_FILTER_NEAREST;
10164 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10165 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10166 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10167 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10168 sampler_ci.mipLodBias = 1.0;
10169 sampler_ci.anisotropyEnable = VK_FALSE;
10170 sampler_ci.maxAnisotropy = 1;
10171 sampler_ci.compareEnable = VK_FALSE;
10172 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10173 sampler_ci.minLod = 1.0;
10174 sampler_ci.maxLod = 1.0;
10175 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10176 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010177
Tobin Ehlis3b780662015-05-28 12:11:26 -060010178 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010179 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010180 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010181
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010182 VkDescriptorImageInfo info = {};
10183 info.sampler = sampler;
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;
10189 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010190 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010191 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010192 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010193 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010194
10195 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 vkDestroySampler(m_device->device(), sampler, NULL);
10200 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10201 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010202}
10203
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010204TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10205 // Create layout w/ empty binding and attempt to update it
10206 VkResult err;
10207
10208 ASSERT_NO_FATAL_FAILURE(InitState());
10209
10210 VkDescriptorPoolSize ds_type_count = {};
10211 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10212 ds_type_count.descriptorCount = 1;
10213
10214 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10215 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10216 ds_pool_ci.pNext = NULL;
10217 ds_pool_ci.maxSets = 1;
10218 ds_pool_ci.poolSizeCount = 1;
10219 ds_pool_ci.pPoolSizes = &ds_type_count;
10220
10221 VkDescriptorPool ds_pool;
10222 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10223 ASSERT_VK_SUCCESS(err);
10224
10225 VkDescriptorSetLayoutBinding dsl_binding = {};
10226 dsl_binding.binding = 0;
10227 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10228 dsl_binding.descriptorCount = 0;
10229 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10230 dsl_binding.pImmutableSamplers = NULL;
10231
10232 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10233 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10234 ds_layout_ci.pNext = NULL;
10235 ds_layout_ci.bindingCount = 1;
10236 ds_layout_ci.pBindings = &dsl_binding;
10237 VkDescriptorSetLayout ds_layout;
10238 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10239 ASSERT_VK_SUCCESS(err);
10240
10241 VkDescriptorSet descriptor_set;
10242 VkDescriptorSetAllocateInfo alloc_info = {};
10243 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10244 alloc_info.descriptorSetCount = 1;
10245 alloc_info.descriptorPool = ds_pool;
10246 alloc_info.pSetLayouts = &ds_layout;
10247 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10248 ASSERT_VK_SUCCESS(err);
10249
10250 VkSamplerCreateInfo sampler_ci = {};
10251 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10252 sampler_ci.magFilter = VK_FILTER_NEAREST;
10253 sampler_ci.minFilter = VK_FILTER_NEAREST;
10254 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10255 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10256 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10257 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10258 sampler_ci.mipLodBias = 1.0;
10259 sampler_ci.maxAnisotropy = 1;
10260 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10261 sampler_ci.minLod = 1.0;
10262 sampler_ci.maxLod = 1.0;
10263 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10264
10265 VkSampler sampler;
10266 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10267 ASSERT_VK_SUCCESS(err);
10268
10269 VkDescriptorImageInfo info = {};
10270 info.sampler = sampler;
10271
10272 VkWriteDescriptorSet descriptor_write;
10273 memset(&descriptor_write, 0, sizeof(descriptor_write));
10274 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10275 descriptor_write.dstSet = descriptor_set;
10276 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010277 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010278 // This is the wrong type, but empty binding error will be flagged first
10279 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10280 descriptor_write.pImageInfo = &info;
10281
10282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10283 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10284 m_errorMonitor->VerifyFound();
10285
10286 vkDestroySampler(m_device->device(), sampler, NULL);
10287 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10288 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10289}
10290
Karl Schultz6addd812016-02-02 17:17:23 -070010291TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10292 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10293 // types
10294 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010296 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 -060010297
Tobin Ehlis3b780662015-05-28 12:11:26 -060010298 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010299
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010300 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010301 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10302 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010303
10304 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010305 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10306 ds_pool_ci.pNext = NULL;
10307 ds_pool_ci.maxSets = 1;
10308 ds_pool_ci.poolSizeCount = 1;
10309 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010310
Tobin Ehlis3b780662015-05-28 12:11:26 -060010311 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010312 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010313 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010314 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010315 dsl_binding.binding = 0;
10316 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10317 dsl_binding.descriptorCount = 1;
10318 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10319 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010320
Tony Barboureb254902015-07-15 12:50:33 -060010321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10323 ds_layout_ci.pNext = NULL;
10324 ds_layout_ci.bindingCount = 1;
10325 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010326
Tobin Ehlis3b780662015-05-28 12:11:26 -060010327 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010329 ASSERT_VK_SUCCESS(err);
10330
10331 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010332 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010333 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010334 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010335 alloc_info.descriptorPool = ds_pool;
10336 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010338 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010339
Tony Barboureb254902015-07-15 12:50:33 -060010340 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010341 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10342 sampler_ci.pNext = NULL;
10343 sampler_ci.magFilter = VK_FILTER_NEAREST;
10344 sampler_ci.minFilter = VK_FILTER_NEAREST;
10345 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10346 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10347 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10348 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10349 sampler_ci.mipLodBias = 1.0;
10350 sampler_ci.anisotropyEnable = VK_FALSE;
10351 sampler_ci.maxAnisotropy = 1;
10352 sampler_ci.compareEnable = VK_FALSE;
10353 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10354 sampler_ci.minLod = 1.0;
10355 sampler_ci.maxLod = 1.0;
10356 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10357 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010358 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010359 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010360 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010361
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010362 VkDescriptorImageInfo info = {};
10363 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010364
10365 VkWriteDescriptorSet descriptor_write;
10366 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010367 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010368 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010369 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010370 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010371 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010372 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010373
10374 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10375
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010376 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010377
Chia-I Wuf7458c52015-10-26 21:10:41 +080010378 vkDestroySampler(m_device->device(), sampler, NULL);
10379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010381}
10382
Karl Schultz6addd812016-02-02 17:17:23 -070010383TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010384 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010385 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010386
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010388
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010389 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010390 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10391 // code
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_SAMPLER;
10394 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -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;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010402
10403 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010405 ASSERT_VK_SUCCESS(err);
10406
10407 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010408 dsl_binding.binding = 0;
10409 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10410 dsl_binding.descriptorCount = 1;
10411 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10412 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010413
10414 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010415 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10416 ds_layout_ci.pNext = NULL;
10417 ds_layout_ci.bindingCount = 1;
10418 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010419 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -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;
Tobin Ehlisa1c28562015-10-23 16:00:08 -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 Ehlisa1c28562015-10-23 16:00:08 -060010430 ASSERT_VK_SUCCESS(err);
10431
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010432 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010433
10434 VkDescriptorImageInfo descriptor_info;
10435 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10436 descriptor_info.sampler = sampler;
10437
10438 VkWriteDescriptorSet descriptor_write;
10439 memset(&descriptor_write, 0, sizeof(descriptor_write));
10440 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010441 descriptor_write.dstSet = descriptorSet;
10442 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010443 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010444 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10445 descriptor_write.pImageInfo = &descriptor_info;
10446
10447 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10448
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010449 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010450
Chia-I Wuf7458c52015-10-26 21:10:41 +080010451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10452 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010453}
10454
Karl Schultz6addd812016-02-02 17:17:23 -070010455TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10456 // Create a single combined Image/Sampler descriptor and send it an invalid
10457 // imageView
10458 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010459
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010461
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010462 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010463 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010464 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10465 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010466
10467 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010468 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10469 ds_pool_ci.pNext = NULL;
10470 ds_pool_ci.maxSets = 1;
10471 ds_pool_ci.poolSizeCount = 1;
10472 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010473
10474 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010475 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010476 ASSERT_VK_SUCCESS(err);
10477
10478 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010479 dsl_binding.binding = 0;
10480 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10481 dsl_binding.descriptorCount = 1;
10482 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10483 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010484
10485 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010486 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10487 ds_layout_ci.pNext = NULL;
10488 ds_layout_ci.bindingCount = 1;
10489 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010490 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010491 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010492 ASSERT_VK_SUCCESS(err);
10493
10494 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010495 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010496 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010497 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010498 alloc_info.descriptorPool = ds_pool;
10499 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010500 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010501 ASSERT_VK_SUCCESS(err);
10502
10503 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010504 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10505 sampler_ci.pNext = NULL;
10506 sampler_ci.magFilter = VK_FILTER_NEAREST;
10507 sampler_ci.minFilter = VK_FILTER_NEAREST;
10508 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10509 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10510 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10511 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10512 sampler_ci.mipLodBias = 1.0;
10513 sampler_ci.anisotropyEnable = VK_FALSE;
10514 sampler_ci.maxAnisotropy = 1;
10515 sampler_ci.compareEnable = VK_FALSE;
10516 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10517 sampler_ci.minLod = 1.0;
10518 sampler_ci.maxLod = 1.0;
10519 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10520 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010521
10522 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010523 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010524 ASSERT_VK_SUCCESS(err);
10525
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010526 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010527
10528 VkDescriptorImageInfo descriptor_info;
10529 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10530 descriptor_info.sampler = sampler;
10531 descriptor_info.imageView = view;
10532
10533 VkWriteDescriptorSet descriptor_write;
10534 memset(&descriptor_write, 0, sizeof(descriptor_write));
10535 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010536 descriptor_write.dstSet = descriptorSet;
10537 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010538 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010539 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10540 descriptor_write.pImageInfo = &descriptor_info;
10541
10542 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10543
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010544 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010545
Chia-I Wuf7458c52015-10-26 21:10:41 +080010546 vkDestroySampler(m_device->device(), sampler, NULL);
10547 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10548 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010549}
10550
Karl Schultz6addd812016-02-02 17:17:23 -070010551TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10552 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10553 // into the other
10554 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010555
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10557 " binding #1 with type "
10558 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10559 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010560
Tobin Ehlis04356f92015-10-27 16:35:27 -060010561 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010562 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010563 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010564 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10565 ds_type_count[0].descriptorCount = 1;
10566 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10567 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010568
10569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10571 ds_pool_ci.pNext = NULL;
10572 ds_pool_ci.maxSets = 1;
10573 ds_pool_ci.poolSizeCount = 2;
10574 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010575
10576 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010577 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010578 ASSERT_VK_SUCCESS(err);
10579 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010580 dsl_binding[0].binding = 0;
10581 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10582 dsl_binding[0].descriptorCount = 1;
10583 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10584 dsl_binding[0].pImmutableSamplers = NULL;
10585 dsl_binding[1].binding = 1;
10586 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10587 dsl_binding[1].descriptorCount = 1;
10588 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10589 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010590
10591 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010592 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10593 ds_layout_ci.pNext = NULL;
10594 ds_layout_ci.bindingCount = 2;
10595 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010596
10597 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010598 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010599 ASSERT_VK_SUCCESS(err);
10600
10601 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010602 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010603 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010604 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010605 alloc_info.descriptorPool = ds_pool;
10606 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010608 ASSERT_VK_SUCCESS(err);
10609
10610 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010611 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10612 sampler_ci.pNext = NULL;
10613 sampler_ci.magFilter = VK_FILTER_NEAREST;
10614 sampler_ci.minFilter = VK_FILTER_NEAREST;
10615 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10616 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10617 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10618 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10619 sampler_ci.mipLodBias = 1.0;
10620 sampler_ci.anisotropyEnable = VK_FALSE;
10621 sampler_ci.maxAnisotropy = 1;
10622 sampler_ci.compareEnable = VK_FALSE;
10623 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10624 sampler_ci.minLod = 1.0;
10625 sampler_ci.maxLod = 1.0;
10626 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10627 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010628
10629 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010630 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010631 ASSERT_VK_SUCCESS(err);
10632
10633 VkDescriptorImageInfo info = {};
10634 info.sampler = sampler;
10635
10636 VkWriteDescriptorSet descriptor_write;
10637 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10638 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010639 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010640 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010641 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010642 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10643 descriptor_write.pImageInfo = &info;
10644 // This write update should succeed
10645 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10646 // Now perform a copy update that fails due to type mismatch
10647 VkCopyDescriptorSet copy_ds_update;
10648 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10649 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10650 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010651 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010652 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010653 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10654 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010655 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10656
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010657 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010658 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010659 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 -060010660 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10661 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10662 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010663 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010664 copy_ds_update.dstSet = descriptorSet;
10665 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010666 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010667 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10668
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010669 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010670
Tobin Ehlis04356f92015-10-27 16:35:27 -060010671 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10673 " binding#1 with offset index of 1 plus "
10674 "update array offset of 0 and update of "
10675 "5 descriptors oversteps total number "
10676 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010677
Tobin Ehlis04356f92015-10-27 16:35:27 -060010678 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10679 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10680 copy_ds_update.srcSet = descriptorSet;
10681 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010682 copy_ds_update.dstSet = descriptorSet;
10683 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010684 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010685 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10686
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010687 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010688
Chia-I Wuf7458c52015-10-26 21:10:41 +080010689 vkDestroySampler(m_device->device(), sampler, NULL);
10690 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10691 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010692}
10693
Karl Schultz6addd812016-02-02 17:17:23 -070010694TEST_F(VkLayerTest, NumSamplesMismatch) {
10695 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10696 // sampleCount
10697 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010698
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010700
Tobin Ehlis3b780662015-05-28 12:11:26 -060010701 ASSERT_NO_FATAL_FAILURE(InitState());
10702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010703 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010704 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010705 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010706
10707 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010708 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10709 ds_pool_ci.pNext = NULL;
10710 ds_pool_ci.maxSets = 1;
10711 ds_pool_ci.poolSizeCount = 1;
10712 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010713
Tobin Ehlis3b780662015-05-28 12:11:26 -060010714 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010715 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010716 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010717
Tony Barboureb254902015-07-15 12:50:33 -060010718 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010719 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010720 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010721 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010722 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10723 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010724
Tony Barboureb254902015-07-15 12:50:33 -060010725 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10726 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10727 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010728 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010729 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010730
Tobin Ehlis3b780662015-05-28 12:11:26 -060010731 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010732 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010733 ASSERT_VK_SUCCESS(err);
10734
10735 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010736 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010737 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010738 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010739 alloc_info.descriptorPool = ds_pool;
10740 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010741 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010742 ASSERT_VK_SUCCESS(err);
10743
Tony Barboureb254902015-07-15 12:50:33 -060010744 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010745 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010746 pipe_ms_state_ci.pNext = NULL;
10747 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10748 pipe_ms_state_ci.sampleShadingEnable = 0;
10749 pipe_ms_state_ci.minSampleShading = 1.0;
10750 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010751
Tony Barboureb254902015-07-15 12:50:33 -060010752 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010753 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10754 pipeline_layout_ci.pNext = NULL;
10755 pipeline_layout_ci.setLayoutCount = 1;
10756 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010757
10758 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010759 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010760 ASSERT_VK_SUCCESS(err);
10761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010762 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010763 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 -060010764 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010765 VkPipelineObj pipe(m_device);
10766 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010767 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010768 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010769 pipe.SetMSAA(&pipe_ms_state_ci);
10770 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010771
Tony Barbour552f6c02016-12-21 14:34:07 -070010772 m_commandBuffer->BeginCommandBuffer();
10773 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010774 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010775
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010776 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10777 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10778 VkRect2D scissor = {{0, 0}, {16, 16}};
10779 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10780
Mark Young29927482016-05-04 14:38:51 -060010781 // Render triangle (the error should trigger on the attempt to draw).
10782 Draw(3, 1, 0, 0);
10783
10784 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010785 m_commandBuffer->EndRenderPass();
10786 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010787
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010788 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010789
Chia-I Wuf7458c52015-10-26 21:10:41 +080010790 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10791 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10792 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010793}
Mark Young29927482016-05-04 14:38:51 -060010794
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010795TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010796 TEST_DESCRIPTION(
10797 "Hit RenderPass incompatible cases. "
10798 "Initial case is drawing with an active renderpass that's "
10799 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010800 VkResult err;
10801
10802 ASSERT_NO_FATAL_FAILURE(InitState());
10803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10804
10805 VkDescriptorSetLayoutBinding dsl_binding = {};
10806 dsl_binding.binding = 0;
10807 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10808 dsl_binding.descriptorCount = 1;
10809 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10810 dsl_binding.pImmutableSamplers = NULL;
10811
10812 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10813 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10814 ds_layout_ci.pNext = NULL;
10815 ds_layout_ci.bindingCount = 1;
10816 ds_layout_ci.pBindings = &dsl_binding;
10817
10818 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010819 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010820 ASSERT_VK_SUCCESS(err);
10821
10822 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10823 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10824 pipeline_layout_ci.pNext = NULL;
10825 pipeline_layout_ci.setLayoutCount = 1;
10826 pipeline_layout_ci.pSetLayouts = &ds_layout;
10827
10828 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010829 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010830 ASSERT_VK_SUCCESS(err);
10831
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010832 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010833 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 -060010834 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010835 // Create a renderpass that will be incompatible with default renderpass
10836 VkAttachmentReference attach = {};
10837 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10838 VkAttachmentReference color_att = {};
10839 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10840 VkSubpassDescription subpass = {};
10841 subpass.inputAttachmentCount = 1;
10842 subpass.pInputAttachments = &attach;
10843 subpass.colorAttachmentCount = 1;
10844 subpass.pColorAttachments = &color_att;
10845 VkRenderPassCreateInfo rpci = {};
10846 rpci.subpassCount = 1;
10847 rpci.pSubpasses = &subpass;
10848 rpci.attachmentCount = 1;
10849 VkAttachmentDescription attach_desc = {};
10850 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010851 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10852 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010853 rpci.pAttachments = &attach_desc;
10854 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10855 VkRenderPass rp;
10856 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10857 VkPipelineObj pipe(m_device);
10858 pipe.AddShader(&vs);
10859 pipe.AddShader(&fs);
10860 pipe.AddColorAttachment();
10861 VkViewport view_port = {};
10862 m_viewports.push_back(view_port);
10863 pipe.SetViewport(m_viewports);
10864 VkRect2D rect = {};
10865 m_scissors.push_back(rect);
10866 pipe.SetScissor(m_scissors);
10867 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10868
10869 VkCommandBufferInheritanceInfo cbii = {};
10870 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10871 cbii.renderPass = rp;
10872 cbii.subpass = 0;
10873 VkCommandBufferBeginInfo cbbi = {};
10874 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10875 cbbi.pInheritanceInfo = &cbii;
10876 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10877 VkRenderPassBeginInfo rpbi = {};
10878 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10879 rpbi.framebuffer = m_framebuffer;
10880 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010881 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10882 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010883
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010885 // Render triangle (the error should trigger on the attempt to draw).
10886 Draw(3, 1, 0, 0);
10887
10888 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010889 m_commandBuffer->EndRenderPass();
10890 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010891
10892 m_errorMonitor->VerifyFound();
10893
10894 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10895 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10896 vkDestroyRenderPass(m_device->device(), rp, NULL);
10897}
10898
Mark Youngc89c6312016-03-31 16:03:20 -060010899TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10900 // Create Pipeline where the number of blend attachments doesn't match the
10901 // number of color attachments. In this case, we don't add any color
10902 // blend attachments even though we have a color attachment.
10903 VkResult err;
10904
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010906
10907 ASSERT_NO_FATAL_FAILURE(InitState());
10908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10909 VkDescriptorPoolSize ds_type_count = {};
10910 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10911 ds_type_count.descriptorCount = 1;
10912
10913 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10914 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10915 ds_pool_ci.pNext = NULL;
10916 ds_pool_ci.maxSets = 1;
10917 ds_pool_ci.poolSizeCount = 1;
10918 ds_pool_ci.pPoolSizes = &ds_type_count;
10919
10920 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010921 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010922 ASSERT_VK_SUCCESS(err);
10923
10924 VkDescriptorSetLayoutBinding dsl_binding = {};
10925 dsl_binding.binding = 0;
10926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10927 dsl_binding.descriptorCount = 1;
10928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10929 dsl_binding.pImmutableSamplers = NULL;
10930
10931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10933 ds_layout_ci.pNext = NULL;
10934 ds_layout_ci.bindingCount = 1;
10935 ds_layout_ci.pBindings = &dsl_binding;
10936
10937 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010938 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010939 ASSERT_VK_SUCCESS(err);
10940
10941 VkDescriptorSet descriptorSet;
10942 VkDescriptorSetAllocateInfo alloc_info = {};
10943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10944 alloc_info.descriptorSetCount = 1;
10945 alloc_info.descriptorPool = ds_pool;
10946 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010948 ASSERT_VK_SUCCESS(err);
10949
10950 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010951 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010952 pipe_ms_state_ci.pNext = NULL;
10953 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10954 pipe_ms_state_ci.sampleShadingEnable = 0;
10955 pipe_ms_state_ci.minSampleShading = 1.0;
10956 pipe_ms_state_ci.pSampleMask = NULL;
10957
10958 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10959 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10960 pipeline_layout_ci.pNext = NULL;
10961 pipeline_layout_ci.setLayoutCount = 1;
10962 pipeline_layout_ci.pSetLayouts = &ds_layout;
10963
10964 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010965 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010966 ASSERT_VK_SUCCESS(err);
10967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010968 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010969 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 -060010970 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010971 VkPipelineObj pipe(m_device);
10972 pipe.AddShader(&vs);
10973 pipe.AddShader(&fs);
10974 pipe.SetMSAA(&pipe_ms_state_ci);
10975 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010976 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010977
10978 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10980 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10981}
Mark Young29927482016-05-04 14:38:51 -060010982
Mark Muellerd4914412016-06-13 17:52:06 -060010983TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010984 TEST_DESCRIPTION(
10985 "Points to a wrong colorAttachment index in a VkClearAttachment "
10986 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010987 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010989
10990 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10991 m_errorMonitor->VerifyFound();
10992}
10993
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010994TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010995 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10996 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010997
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010998 ASSERT_NO_FATAL_FAILURE(InitState());
10999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011000
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011001 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011002 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11003 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011004
11005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011006 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;
Tony Barboureb254902015-07-15 12:50:33 -060011011
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011012 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011013 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011014 ASSERT_VK_SUCCESS(err);
11015
Tony Barboureb254902015-07-15 12:50:33 -060011016 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011017 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;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011022
Tony Barboureb254902015-07-15 12:50:33 -060011023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011024 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;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011028
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011029 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011030 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011031 ASSERT_VK_SUCCESS(err);
11032
11033 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011034 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011035 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011036 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011037 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);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011040 ASSERT_VK_SUCCESS(err);
11041
Tony Barboureb254902015-07-15 12:50:33 -060011042 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;
Karl Schultz6addd812016-02-02 17:17:23 -070011044 pipe_ms_state_ci.pNext = NULL;
11045 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11046 pipe_ms_state_ci.sampleShadingEnable = 0;
11047 pipe_ms_state_ci.minSampleShading = 1.0;
11048 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011049
Tony Barboureb254902015-07-15 12:50:33 -060011050 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011051 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;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011055
11056 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011057 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011058 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011060 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011061 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011062 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011063 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011064
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011065 VkPipelineObj pipe(m_device);
11066 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011067 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011068 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011069 m_errorMonitor->SetUnexpectedError(
11070 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11071 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011072 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011073
Tony Barbour552f6c02016-12-21 14:34:07 -070011074 m_commandBuffer->BeginCommandBuffer();
11075 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011076
Karl Schultz6addd812016-02-02 17:17:23 -070011077 // Main thing we care about for this test is that the VkImage obj we're
11078 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011079 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011080 VkClearAttachment color_attachment;
11081 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11082 color_attachment.clearValue.color.float32[0] = 1.0;
11083 color_attachment.clearValue.color.float32[1] = 1.0;
11084 color_attachment.clearValue.color.float32[2] = 1.0;
11085 color_attachment.clearValue.color.float32[3] = 1.0;
11086 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011087 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011088
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011089 // Call for full-sized FB Color attachment prior to issuing a Draw
11090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011091 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011092 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011093 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011094
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011095 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11096 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11098 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11099 m_errorMonitor->VerifyFound();
11100
11101 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11102 clear_rect.layerCount = 2;
11103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11104 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011105 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011106
Chia-I Wuf7458c52015-10-26 21:10:41 +080011107 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11108 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11109 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011110}
11111
Karl Schultz6addd812016-02-02 17:17:23 -070011112TEST_F(VkLayerTest, VtxBufferBadIndex) {
11113 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11116 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011117
Tobin Ehlis502480b2015-06-24 15:53:07 -060011118 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011119 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011121
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011122 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011123 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11124 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011125
11126 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011127 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11128 ds_pool_ci.pNext = NULL;
11129 ds_pool_ci.maxSets = 1;
11130 ds_pool_ci.poolSizeCount = 1;
11131 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011132
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011133 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011135 ASSERT_VK_SUCCESS(err);
11136
Tony Barboureb254902015-07-15 12:50:33 -060011137 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011138 dsl_binding.binding = 0;
11139 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11140 dsl_binding.descriptorCount = 1;
11141 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11142 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011143
Tony Barboureb254902015-07-15 12:50:33 -060011144 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011145 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11146 ds_layout_ci.pNext = NULL;
11147 ds_layout_ci.bindingCount = 1;
11148 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011149
Tobin Ehlis502480b2015-06-24 15:53:07 -060011150 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011151 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011152 ASSERT_VK_SUCCESS(err);
11153
11154 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011155 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011156 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011157 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011158 alloc_info.descriptorPool = ds_pool;
11159 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011160 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011161 ASSERT_VK_SUCCESS(err);
11162
Tony Barboureb254902015-07-15 12:50:33 -060011163 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011164 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011165 pipe_ms_state_ci.pNext = NULL;
11166 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11167 pipe_ms_state_ci.sampleShadingEnable = 0;
11168 pipe_ms_state_ci.minSampleShading = 1.0;
11169 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011170
Tony Barboureb254902015-07-15 12:50:33 -060011171 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011172 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11173 pipeline_layout_ci.pNext = NULL;
11174 pipeline_layout_ci.setLayoutCount = 1;
11175 pipeline_layout_ci.pSetLayouts = &ds_layout;
11176 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011178 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011179 ASSERT_VK_SUCCESS(err);
11180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011182 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 -060011183 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011184 VkPipelineObj pipe(m_device);
11185 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011186 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011187 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011188 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011189 pipe.SetViewport(m_viewports);
11190 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011191 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011192
Tony Barbour552f6c02016-12-21 14:34:07 -070011193 m_commandBuffer->BeginCommandBuffer();
11194 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011195 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011196 // Don't care about actual data, just need to get to draw to flag error
11197 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011199 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011200 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011201
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011202 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011203
Chia-I Wuf7458c52015-10-26 21:10:41 +080011204 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11205 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11206 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011207}
Mark Muellerdfe37552016-07-07 14:47:42 -060011208
Mark Mueller2ee294f2016-08-04 12:59:48 -060011209TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011210 TEST_DESCRIPTION(
11211 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11212 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011213 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011214
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011215 const char *invalid_queueFamilyIndex_message =
11216 "Invalid queue create request in vkCreateDevice(). Invalid "
11217 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011219 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011220
Mark Mueller880fce52016-08-17 15:23:23 -060011221 // The following test fails with recent NVidia drivers.
11222 // By the time core_validation is reached, the NVidia
11223 // driver has sanitized the invalid condition and core_validation
11224 // is not introduced to the failure condition. This is not the case
11225 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011226 // uint32_t count = static_cast<uint32_t>(~0);
11227 // VkPhysicalDevice physical_device;
11228 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11229 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011232 float queue_priority = 0.0;
11233
11234 VkDeviceQueueCreateInfo queue_create_info = {};
11235 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11236 queue_create_info.queueCount = 1;
11237 queue_create_info.pQueuePriorities = &queue_priority;
11238 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11239
11240 VkPhysicalDeviceFeatures features = m_device->phy().features();
11241 VkDevice testDevice;
11242 VkDeviceCreateInfo device_create_info = {};
11243 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11244 device_create_info.queueCreateInfoCount = 1;
11245 device_create_info.pQueueCreateInfos = &queue_create_info;
11246 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011247 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011248 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11249 m_errorMonitor->VerifyFound();
11250
11251 queue_create_info.queueFamilyIndex = 1;
11252
11253 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11254 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11255 for (unsigned i = 0; i < feature_count; i++) {
11256 if (VK_FALSE == feature_array[i]) {
11257 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011259 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011260 m_errorMonitor->SetUnexpectedError(
11261 "You requested features that are unavailable on this device. You should first query feature availability by "
11262 "calling vkGetPhysicalDeviceFeatures().");
11263 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011264 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11265 m_errorMonitor->VerifyFound();
11266 break;
11267 }
11268 }
11269}
11270
Tobin Ehlis16edf082016-11-21 12:33:49 -070011271TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11272 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11273
11274 ASSERT_NO_FATAL_FAILURE(InitState());
11275
11276 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11277 std::vector<VkDeviceQueueCreateInfo> queue_info;
11278 queue_info.reserve(queue_props.size());
11279 std::vector<std::vector<float>> queue_priorities;
11280 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11281 VkDeviceQueueCreateInfo qi{};
11282 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11283 qi.queueFamilyIndex = i;
11284 qi.queueCount = queue_props[i].queueCount;
11285 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11286 qi.pQueuePriorities = queue_priorities[i].data();
11287 queue_info.push_back(qi);
11288 }
11289
11290 std::vector<const char *> device_extension_names;
11291
11292 VkDevice local_device;
11293 VkDeviceCreateInfo device_create_info = {};
11294 auto features = m_device->phy().features();
11295 // Intentionally disable pipeline stats
11296 features.pipelineStatisticsQuery = VK_FALSE;
11297 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11298 device_create_info.pNext = NULL;
11299 device_create_info.queueCreateInfoCount = queue_info.size();
11300 device_create_info.pQueueCreateInfos = queue_info.data();
11301 device_create_info.enabledLayerCount = 0;
11302 device_create_info.ppEnabledLayerNames = NULL;
11303 device_create_info.pEnabledFeatures = &features;
11304 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11305 ASSERT_VK_SUCCESS(err);
11306
11307 VkQueryPoolCreateInfo qpci{};
11308 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11309 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11310 qpci.queryCount = 1;
11311 VkQueryPool query_pool;
11312
11313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11314 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11315 m_errorMonitor->VerifyFound();
11316
11317 vkDestroyDevice(local_device, nullptr);
11318}
11319
Mark Mueller2ee294f2016-08-04 12:59:48 -060011320TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011321 TEST_DESCRIPTION(
11322 "Use an invalid queue index in a vkCmdWaitEvents call."
11323 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011324
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011325 const char *invalid_queue_index =
11326 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11327 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11328 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011330 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011333
11334 ASSERT_NO_FATAL_FAILURE(InitState());
11335
11336 VkEvent event;
11337 VkEventCreateInfo event_create_info{};
11338 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11339 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11340
Mark Mueller2ee294f2016-08-04 12:59:48 -060011341 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011342 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011343
Tony Barbour552f6c02016-12-21 14:34:07 -070011344 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011345
11346 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011347 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 -060011348 ASSERT_TRUE(image.initialized());
11349 VkImageMemoryBarrier img_barrier = {};
11350 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11351 img_barrier.pNext = NULL;
11352 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11353 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11354 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11355 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11356 img_barrier.image = image.handle();
11357 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011358
11359 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11360 // that layer validation catches the case when it is not.
11361 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011362 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11363 img_barrier.subresourceRange.baseArrayLayer = 0;
11364 img_barrier.subresourceRange.baseMipLevel = 0;
11365 img_barrier.subresourceRange.layerCount = 1;
11366 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011367 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11368 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011369 m_errorMonitor->VerifyFound();
11370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011372
11373 VkQueryPool query_pool;
11374 VkQueryPoolCreateInfo query_pool_create_info = {};
11375 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11376 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11377 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011378 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011380 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011381 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11382
11383 vkEndCommandBuffer(m_commandBuffer->handle());
11384 m_errorMonitor->VerifyFound();
11385
11386 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11387 vkDestroyEvent(m_device->device(), event, nullptr);
11388}
11389
Mark Muellerdfe37552016-07-07 14:47:42 -060011390TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011391 TEST_DESCRIPTION(
11392 "Submit a command buffer using deleted vertex buffer, "
11393 "delete a buffer twice, use an invalid offset for each "
11394 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011395
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011396 const char *deleted_buffer_in_command_buffer =
11397 "Cannot submit cmd buffer "
11398 "using deleted buffer ";
11399 const char *invalid_offset_message =
11400 "vkBindBufferMemory(): "
11401 "memoryOffset is 0x";
11402 const char *invalid_storage_buffer_offset_message =
11403 "vkBindBufferMemory(): "
11404 "storage memoryOffset "
11405 "is 0x";
11406 const char *invalid_texel_buffer_offset_message =
11407 "vkBindBufferMemory(): "
11408 "texel memoryOffset "
11409 "is 0x";
11410 const char *invalid_uniform_buffer_offset_message =
11411 "vkBindBufferMemory(): "
11412 "uniform memoryOffset "
11413 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011414
11415 ASSERT_NO_FATAL_FAILURE(InitState());
11416 ASSERT_NO_FATAL_FAILURE(InitViewport());
11417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11418
11419 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011420 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011421 pipe_ms_state_ci.pNext = NULL;
11422 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11423 pipe_ms_state_ci.sampleShadingEnable = 0;
11424 pipe_ms_state_ci.minSampleShading = 1.0;
11425 pipe_ms_state_ci.pSampleMask = nullptr;
11426
11427 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11428 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11429 VkPipelineLayout pipeline_layout;
11430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011431 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011432 ASSERT_VK_SUCCESS(err);
11433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011434 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11435 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011436 VkPipelineObj pipe(m_device);
11437 pipe.AddShader(&vs);
11438 pipe.AddShader(&fs);
11439 pipe.AddColorAttachment();
11440 pipe.SetMSAA(&pipe_ms_state_ci);
11441 pipe.SetViewport(m_viewports);
11442 pipe.SetScissor(m_scissors);
11443 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11444
Tony Barbour552f6c02016-12-21 14:34:07 -070011445 m_commandBuffer->BeginCommandBuffer();
11446 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011447 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011448
11449 {
11450 // Create and bind a vertex buffer in a reduced scope, which will cause
11451 // it to be deleted upon leaving this scope
11452 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011453 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011454 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11455 draw_verticies.AddVertexInputToPipe(pipe);
11456 }
11457
11458 Draw(1, 0, 0, 0);
11459
Tony Barbour552f6c02016-12-21 14:34:07 -070011460 m_commandBuffer->EndRenderPass();
11461 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011464 QueueCommandBuffer(false);
11465 m_errorMonitor->VerifyFound();
11466
11467 {
11468 // Create and bind a vertex buffer in a reduced scope, and delete it
11469 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011470 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011472 buffer_test.TestDoubleDestroy();
11473 }
11474 m_errorMonitor->VerifyFound();
11475
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011476 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011477 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011478 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011480 m_errorMonitor->SetUnexpectedError(
11481 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11482 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011483 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11484 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011485 m_errorMonitor->VerifyFound();
11486 }
11487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011488 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11489 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011490 // Create and bind a memory buffer with an invalid offset again,
11491 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011493 m_errorMonitor->SetUnexpectedError(
11494 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11495 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011496 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11497 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011498 m_errorMonitor->VerifyFound();
11499 }
11500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011501 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011502 // Create and bind a memory buffer with an invalid offset again, but
11503 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011505 m_errorMonitor->SetUnexpectedError(
11506 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11507 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011508 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11509 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011510 m_errorMonitor->VerifyFound();
11511 }
11512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011513 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011514 // Create and bind a memory buffer with an invalid offset again, but
11515 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011517 m_errorMonitor->SetUnexpectedError(
11518 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11519 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011520 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11521 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011522 m_errorMonitor->VerifyFound();
11523 }
11524
11525 {
11526 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011528 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11529 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11531 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011532 m_errorMonitor->VerifyFound();
11533 }
11534
11535 {
11536 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011538 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11539 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011540 }
11541 m_errorMonitor->VerifyFound();
11542
11543 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11544}
11545
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011546// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11547TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011548 TEST_DESCRIPTION(
11549 "Hit all possible validation checks associated with the "
11550 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11551 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011552 // 3 in ValidateCmdBufImageLayouts
11553 // * -1 Attempt to submit cmd buf w/ deleted image
11554 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11555 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011556
11557 ASSERT_NO_FATAL_FAILURE(InitState());
11558 // Create src & dst images to use for copy operations
11559 VkImage src_image;
11560 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011561 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011562
11563 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11564 const int32_t tex_width = 32;
11565 const int32_t tex_height = 32;
11566
11567 VkImageCreateInfo image_create_info = {};
11568 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11569 image_create_info.pNext = NULL;
11570 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11571 image_create_info.format = tex_format;
11572 image_create_info.extent.width = tex_width;
11573 image_create_info.extent.height = tex_height;
11574 image_create_info.extent.depth = 1;
11575 image_create_info.mipLevels = 1;
11576 image_create_info.arrayLayers = 4;
11577 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11578 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11579 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011580 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011581 image_create_info.flags = 0;
11582
11583 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11584 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011585 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011586 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11587 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011588 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11589 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11590 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11591 ASSERT_VK_SUCCESS(err);
11592
11593 // Allocate memory
11594 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011595 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011596 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011597 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11598 mem_alloc.pNext = NULL;
11599 mem_alloc.allocationSize = 0;
11600 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011601
11602 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011603 mem_alloc.allocationSize = img_mem_reqs.size;
11604 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011605 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011606 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011607 ASSERT_VK_SUCCESS(err);
11608
11609 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011610 mem_alloc.allocationSize = img_mem_reqs.size;
11611 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011612 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011613 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011614 ASSERT_VK_SUCCESS(err);
11615
11616 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011617 mem_alloc.allocationSize = img_mem_reqs.size;
11618 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011619 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011620 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011621 ASSERT_VK_SUCCESS(err);
11622
11623 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11624 ASSERT_VK_SUCCESS(err);
11625 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11626 ASSERT_VK_SUCCESS(err);
11627 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11628 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011629
Tony Barbour552f6c02016-12-21 14:34:07 -070011630 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011631 VkImageCopy copy_region;
11632 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11633 copy_region.srcSubresource.mipLevel = 0;
11634 copy_region.srcSubresource.baseArrayLayer = 0;
11635 copy_region.srcSubresource.layerCount = 1;
11636 copy_region.srcOffset.x = 0;
11637 copy_region.srcOffset.y = 0;
11638 copy_region.srcOffset.z = 0;
11639 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11640 copy_region.dstSubresource.mipLevel = 0;
11641 copy_region.dstSubresource.baseArrayLayer = 0;
11642 copy_region.dstSubresource.layerCount = 1;
11643 copy_region.dstOffset.x = 0;
11644 copy_region.dstOffset.y = 0;
11645 copy_region.dstOffset.z = 0;
11646 copy_region.extent.width = 1;
11647 copy_region.extent.height = 1;
11648 copy_region.extent.depth = 1;
11649
11650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11651 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011652 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011653 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 -060011654 m_errorMonitor->VerifyFound();
11655 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11657 "Cannot copy from an image whose source layout is "
11658 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11659 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011660 m_errorMonitor->SetUnexpectedError(
11661 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011662 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 -060011663 m_errorMonitor->VerifyFound();
11664 // Final src error is due to bad layout type
11665 m_errorMonitor->SetDesiredFailureMsg(
11666 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11667 "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 -070011668 m_errorMonitor->SetUnexpectedError(
11669 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11670 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011671 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 -060011672 m_errorMonitor->VerifyFound();
11673 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11675 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011676 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011677 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 -060011678 m_errorMonitor->VerifyFound();
11679 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11681 "Cannot copy from an image whose dest layout is "
11682 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11683 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011684 m_errorMonitor->SetUnexpectedError(
11685 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011686 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 -060011687 m_errorMonitor->VerifyFound();
11688 m_errorMonitor->SetDesiredFailureMsg(
11689 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11690 "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 -070011691 m_errorMonitor->SetUnexpectedError(
11692 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11693 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011694 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 -060011695 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011696
Cort3b021012016-12-07 12:00:57 -080011697 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11698 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11699 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11700 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11701 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11702 transfer_dst_image_barrier[0].srcAccessMask = 0;
11703 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11704 transfer_dst_image_barrier[0].image = dst_image;
11705 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11706 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11707 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11708 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11709 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11710 transfer_dst_image_barrier[0].image = depth_image;
11711 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11712 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11713 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11714
11715 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011716 VkClearColorValue color_clear_value = {};
11717 VkImageSubresourceRange clear_range;
11718 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11719 clear_range.baseMipLevel = 0;
11720 clear_range.baseArrayLayer = 0;
11721 clear_range.layerCount = 1;
11722 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011723
Cort3b021012016-12-07 12:00:57 -080011724 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11725 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011728 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011729 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011730 // Fail due to provided layout not matching actual current layout for color clear.
11731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011732 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011733 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011734
Cort530cf382016-12-08 09:59:47 -080011735 VkClearDepthStencilValue depth_clear_value = {};
11736 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011737
11738 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11739 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011742 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011743 m_errorMonitor->VerifyFound();
11744 // Fail due to provided layout not matching actual current layout for depth clear.
11745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011746 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011747 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011748
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011749 // Now cause error due to bad image layout transition in PipelineBarrier
11750 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011751 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011752 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011753 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011754 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011755 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11756 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011757 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11759 "You cannot transition the layout of aspect 1 from "
11760 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11761 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011762 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11763 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011764 m_errorMonitor->VerifyFound();
11765
11766 // Finally some layout errors at RenderPass create time
11767 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11768 VkAttachmentReference attach = {};
11769 // perf warning for GENERAL layout w/ non-DS input attachment
11770 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11771 VkSubpassDescription subpass = {};
11772 subpass.inputAttachmentCount = 1;
11773 subpass.pInputAttachments = &attach;
11774 VkRenderPassCreateInfo rpci = {};
11775 rpci.subpassCount = 1;
11776 rpci.pSubpasses = &subpass;
11777 rpci.attachmentCount = 1;
11778 VkAttachmentDescription attach_desc = {};
11779 attach_desc.format = VK_FORMAT_UNDEFINED;
11780 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011781 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011782 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11784 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011785 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11786 m_errorMonitor->VerifyFound();
11787 // error w/ non-general layout
11788 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11789
11790 m_errorMonitor->SetDesiredFailureMsg(
11791 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11792 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11793 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11794 m_errorMonitor->VerifyFound();
11795 subpass.inputAttachmentCount = 0;
11796 subpass.colorAttachmentCount = 1;
11797 subpass.pColorAttachments = &attach;
11798 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11799 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11801 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011802 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11803 m_errorMonitor->VerifyFound();
11804 // error w/ non-color opt or GENERAL layout for color attachment
11805 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11806 m_errorMonitor->SetDesiredFailureMsg(
11807 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11808 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11809 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11810 m_errorMonitor->VerifyFound();
11811 subpass.colorAttachmentCount = 0;
11812 subpass.pDepthStencilAttachment = &attach;
11813 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11814 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11816 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011817 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11818 m_errorMonitor->VerifyFound();
11819 // error w/ non-ds opt or GENERAL layout for color attachment
11820 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11822 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11823 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011824 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11825 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011826 // For this error we need a valid renderpass so create default one
11827 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11828 attach.attachment = 0;
11829 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11830 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11831 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11832 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11833 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11834 // Can't do a CLEAR load on READ_ONLY initialLayout
11835 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11836 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11837 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11839 " with invalid first layout "
11840 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11841 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011842 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11843 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011844
Cort3b021012016-12-07 12:00:57 -080011845 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11846 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11847 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011848 vkDestroyImage(m_device->device(), src_image, NULL);
11849 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011850 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011851}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011852
Tobin Ehlise0936662016-10-11 08:10:51 -060011853TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11854 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11855 VkResult err;
11856
11857 ASSERT_NO_FATAL_FAILURE(InitState());
11858
11859 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11860 VkImageTiling tiling;
11861 VkFormatProperties format_properties;
11862 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11863 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11864 tiling = VK_IMAGE_TILING_LINEAR;
11865 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11866 tiling = VK_IMAGE_TILING_OPTIMAL;
11867 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011868 printf(
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070011869 " Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011870 return;
11871 }
11872
11873 VkDescriptorPoolSize ds_type = {};
11874 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11875 ds_type.descriptorCount = 1;
11876
11877 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11878 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11879 ds_pool_ci.maxSets = 1;
11880 ds_pool_ci.poolSizeCount = 1;
11881 ds_pool_ci.pPoolSizes = &ds_type;
11882 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11883
11884 VkDescriptorPool ds_pool;
11885 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11886 ASSERT_VK_SUCCESS(err);
11887
11888 VkDescriptorSetLayoutBinding dsl_binding = {};
11889 dsl_binding.binding = 0;
11890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11891 dsl_binding.descriptorCount = 1;
11892 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11893 dsl_binding.pImmutableSamplers = NULL;
11894
11895 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11896 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11897 ds_layout_ci.pNext = NULL;
11898 ds_layout_ci.bindingCount = 1;
11899 ds_layout_ci.pBindings = &dsl_binding;
11900
11901 VkDescriptorSetLayout ds_layout;
11902 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11903 ASSERT_VK_SUCCESS(err);
11904
11905 VkDescriptorSetAllocateInfo alloc_info = {};
11906 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11907 alloc_info.descriptorSetCount = 1;
11908 alloc_info.descriptorPool = ds_pool;
11909 alloc_info.pSetLayouts = &ds_layout;
11910 VkDescriptorSet descriptor_set;
11911 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11912 ASSERT_VK_SUCCESS(err);
11913
11914 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11915 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11916 pipeline_layout_ci.pNext = NULL;
11917 pipeline_layout_ci.setLayoutCount = 1;
11918 pipeline_layout_ci.pSetLayouts = &ds_layout;
11919 VkPipelineLayout pipeline_layout;
11920 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11921 ASSERT_VK_SUCCESS(err);
11922
11923 VkImageObj image(m_device);
11924 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11925 ASSERT_TRUE(image.initialized());
11926 VkImageView view = image.targetView(tex_format);
11927
11928 VkDescriptorImageInfo image_info = {};
11929 image_info.imageView = view;
11930 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11931
11932 VkWriteDescriptorSet descriptor_write = {};
11933 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11934 descriptor_write.dstSet = descriptor_set;
11935 descriptor_write.dstBinding = 0;
11936 descriptor_write.descriptorCount = 1;
11937 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11938 descriptor_write.pImageInfo = &image_info;
11939
11940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11941 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11942 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11943 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11944 m_errorMonitor->VerifyFound();
11945
11946 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11948 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11949 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11950}
11951
Mark Mueller93b938f2016-08-18 10:27:40 -060011952TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011953 TEST_DESCRIPTION(
11954 "Use vkCmdExecuteCommands with invalid state "
11955 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011956
11957 ASSERT_NO_FATAL_FAILURE(InitState());
11958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11959
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011960 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011961 const char *simultaneous_use_message2 =
11962 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11963 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011964
11965 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011967 command_buffer_allocate_info.commandPool = m_commandPool;
11968 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11969 command_buffer_allocate_info.commandBufferCount = 1;
11970
11971 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011972 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011973 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11974 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011975 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011976 command_buffer_inheritance_info.renderPass = m_renderPass;
11977 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011978
Mark Mueller93b938f2016-08-18 10:27:40 -060011979 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011980 command_buffer_begin_info.flags =
11981 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011982 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11983
11984 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11985 vkEndCommandBuffer(secondary_command_buffer);
11986
Mark Mueller93b938f2016-08-18 10:27:40 -060011987 VkSubmitInfo submit_info = {};
11988 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11989 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011990 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011991
Mark Mueller4042b652016-09-05 22:52:21 -060011992 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011993 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11995 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011996 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011997 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011998 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11999 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012000
Dave Houltonfbf52152017-01-06 12:55:29 -070012001 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012002 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012003 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012004
Mark Mueller4042b652016-09-05 22:52:21 -060012005 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012006 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12007 m_errorMonitor->SetUnexpectedError(
12008 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12009 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012010 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012011 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12014 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012015 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012016 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12017 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012018
12019 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012020
12021 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012022}
12023
Tony Barbour626994c2017-02-08 15:29:37 -070012024TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12025 TEST_DESCRIPTION(
12026 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12027 "errors");
12028 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12029 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12030 ASSERT_NO_FATAL_FAILURE(InitState());
12031
12032 VkCommandBuffer cmd_bufs[2];
12033 VkCommandBufferAllocateInfo alloc_info;
12034 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12035 alloc_info.pNext = NULL;
12036 alloc_info.commandBufferCount = 2;
12037 alloc_info.commandPool = m_commandPool;
12038 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12039 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12040
12041 VkCommandBufferBeginInfo cb_binfo;
12042 cb_binfo.pNext = NULL;
12043 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12044 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12045 cb_binfo.flags = 0;
12046 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12047 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12048 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12049 vkEndCommandBuffer(cmd_bufs[0]);
12050 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12051
12052 VkSubmitInfo submit_info = {};
12053 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12054 submit_info.commandBufferCount = 2;
12055 submit_info.pCommandBuffers = duplicates;
12056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12057 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12058 m_errorMonitor->VerifyFound();
12059 vkQueueWaitIdle(m_device->m_queue);
12060
12061 // Set one time use and now look for one time submit
12062 duplicates[0] = duplicates[1] = cmd_bufs[1];
12063 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12064 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12065 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12066 vkEndCommandBuffer(cmd_bufs[1]);
12067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12068 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12069 m_errorMonitor->VerifyFound();
12070 vkQueueWaitIdle(m_device->m_queue);
12071}
12072
Tobin Ehlisb093da82017-01-19 12:05:27 -070012073TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012074 TEST_DESCRIPTION(
12075 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12076 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012077
12078 ASSERT_NO_FATAL_FAILURE(InitState());
12079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12080
12081 std::vector<const char *> device_extension_names;
12082 auto features = m_device->phy().features();
12083 // Make sure gs & ts are disabled
12084 features.geometryShader = false;
12085 features.tessellationShader = false;
12086 // The sacrificial device object
12087 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12088
12089 VkCommandPoolCreateInfo pool_create_info{};
12090 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12091 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12092
12093 VkCommandPool command_pool;
12094 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12095
12096 VkCommandBufferAllocateInfo cmd = {};
12097 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12098 cmd.pNext = NULL;
12099 cmd.commandPool = command_pool;
12100 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12101 cmd.commandBufferCount = 1;
12102
12103 VkCommandBuffer cmd_buffer;
12104 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12105 ASSERT_VK_SUCCESS(err);
12106
12107 VkEvent event;
12108 VkEventCreateInfo evci = {};
12109 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12110 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12111 ASSERT_VK_SUCCESS(result);
12112
12113 VkCommandBufferBeginInfo cbbi = {};
12114 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12115 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12117 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12118 m_errorMonitor->VerifyFound();
12119
12120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12121 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12122 m_errorMonitor->VerifyFound();
12123
12124 vkDestroyEvent(test_device.handle(), event, NULL);
12125 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12126}
12127
Mark Mueller917f6bc2016-08-30 10:57:19 -060012128TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012129 TEST_DESCRIPTION(
12130 "Use vkCmdExecuteCommands with invalid state "
12131 "in primary and secondary command buffers. "
12132 "Delete objects that are inuse. Call VkQueueSubmit "
12133 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012134
12135 ASSERT_NO_FATAL_FAILURE(InitState());
12136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12137
Tony Barbour552f6c02016-12-21 14:34:07 -070012138 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012139
12140 VkEvent event;
12141 VkEventCreateInfo event_create_info = {};
12142 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12143 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012144 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012145
Tony Barbour552f6c02016-12-21 14:34:07 -070012146 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012147 vkDestroyEvent(m_device->device(), event, nullptr);
12148
12149 VkSubmitInfo submit_info = {};
12150 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12151 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012152 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070012153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012155 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12156 m_errorMonitor->VerifyFound();
12157
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012158 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012159 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12160
12161 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12162
Mark Mueller917f6bc2016-08-30 10:57:19 -060012163 VkSemaphoreCreateInfo semaphore_create_info = {};
12164 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12165 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012166 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012167 VkFenceCreateInfo fence_create_info = {};
12168 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12169 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012170 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012171
12172 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012173 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012174 descriptor_pool_type_count.descriptorCount = 1;
12175
12176 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12177 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12178 descriptor_pool_create_info.maxSets = 1;
12179 descriptor_pool_create_info.poolSizeCount = 1;
12180 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012181 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012182
12183 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012184 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012185
12186 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012187 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012188 descriptorset_layout_binding.descriptorCount = 1;
12189 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12190
12191 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012192 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012193 descriptorset_layout_create_info.bindingCount = 1;
12194 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12195
12196 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012197 ASSERT_VK_SUCCESS(
12198 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012199
12200 VkDescriptorSet descriptorset;
12201 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012202 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012203 descriptorset_allocate_info.descriptorSetCount = 1;
12204 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12205 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012206 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012207
Mark Mueller4042b652016-09-05 22:52:21 -060012208 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12209
12210 VkDescriptorBufferInfo buffer_info = {};
12211 buffer_info.buffer = buffer_test.GetBuffer();
12212 buffer_info.offset = 0;
12213 buffer_info.range = 1024;
12214
12215 VkWriteDescriptorSet write_descriptor_set = {};
12216 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12217 write_descriptor_set.dstSet = descriptorset;
12218 write_descriptor_set.descriptorCount = 1;
12219 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12220 write_descriptor_set.pBufferInfo = &buffer_info;
12221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012222 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012224 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12225 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012226
12227 VkPipelineObj pipe(m_device);
12228 pipe.AddColorAttachment();
12229 pipe.AddShader(&vs);
12230 pipe.AddShader(&fs);
12231
12232 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012233 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012234 pipeline_layout_create_info.setLayoutCount = 1;
12235 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12236
12237 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012238 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012239
12240 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12241
Tony Barbour552f6c02016-12-21 14:34:07 -070012242 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012243 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012245 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12246 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12247 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012248
Tony Barbour552f6c02016-12-21 14:34:07 -070012249 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012250
Mark Mueller917f6bc2016-08-30 10:57:19 -060012251 submit_info.signalSemaphoreCount = 1;
12252 submit_info.pSignalSemaphores = &semaphore;
12253 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012254 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012255
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012257 vkDestroyEvent(m_device->device(), event, nullptr);
12258 m_errorMonitor->VerifyFound();
12259
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012261 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12262 m_errorMonitor->VerifyFound();
12263
Jeremy Hayes08369882017-02-02 10:31:06 -070012264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012265 vkDestroyFence(m_device->device(), fence, nullptr);
12266 m_errorMonitor->VerifyFound();
12267
Tobin Ehlis122207b2016-09-01 08:50:06 -070012268 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012269 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12270 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012271 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012272 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12273 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012274 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012275 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12276 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012277 vkDestroyEvent(m_device->device(), event, nullptr);
12278 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012279 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012280 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12281}
12282
Tobin Ehlis2adda372016-09-01 08:51:06 -070012283TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12284 TEST_DESCRIPTION("Delete in-use query pool.");
12285
12286 ASSERT_NO_FATAL_FAILURE(InitState());
12287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12288
12289 VkQueryPool query_pool;
12290 VkQueryPoolCreateInfo query_pool_ci{};
12291 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12292 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12293 query_pool_ci.queryCount = 1;
12294 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012295 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012296 // Reset query pool to create binding with cmd buffer
12297 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12298
Tony Barbour552f6c02016-12-21 14:34:07 -070012299 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012300
12301 VkSubmitInfo submit_info = {};
12302 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12303 submit_info.commandBufferCount = 1;
12304 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12305 // Submit cmd buffer and then destroy query pool while in-flight
12306 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12307
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012309 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12310 m_errorMonitor->VerifyFound();
12311
12312 vkQueueWaitIdle(m_device->m_queue);
12313 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012314 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12315 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012316 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12317}
12318
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012319TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12320 TEST_DESCRIPTION("Delete in-use pipeline.");
12321
12322 ASSERT_NO_FATAL_FAILURE(InitState());
12323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12324
12325 // Empty pipeline layout used for binding PSO
12326 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12327 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12328 pipeline_layout_ci.setLayoutCount = 0;
12329 pipeline_layout_ci.pSetLayouts = NULL;
12330
12331 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012332 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012333 ASSERT_VK_SUCCESS(err);
12334
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012336 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012337 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12338 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012339 // Store pipeline handle so we can actually delete it before test finishes
12340 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012341 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012342 VkPipelineObj pipe(m_device);
12343 pipe.AddShader(&vs);
12344 pipe.AddShader(&fs);
12345 pipe.AddColorAttachment();
12346 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12347 delete_this_pipeline = pipe.handle();
12348
Tony Barbour552f6c02016-12-21 14:34:07 -070012349 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012350 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012351 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012352
Tony Barbour552f6c02016-12-21 14:34:07 -070012353 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012354
12355 VkSubmitInfo submit_info = {};
12356 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12357 submit_info.commandBufferCount = 1;
12358 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12359 // Submit cmd buffer and then pipeline destroyed while in-flight
12360 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012361 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012362 m_errorMonitor->VerifyFound();
12363 // Make sure queue finished and then actually delete pipeline
12364 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012365 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12366 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012367 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12368 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12369}
12370
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012371TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12372 TEST_DESCRIPTION("Delete in-use imageView.");
12373
12374 ASSERT_NO_FATAL_FAILURE(InitState());
12375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12376
12377 VkDescriptorPoolSize ds_type_count;
12378 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12379 ds_type_count.descriptorCount = 1;
12380
12381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12383 ds_pool_ci.maxSets = 1;
12384 ds_pool_ci.poolSizeCount = 1;
12385 ds_pool_ci.pPoolSizes = &ds_type_count;
12386
12387 VkDescriptorPool ds_pool;
12388 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12389 ASSERT_VK_SUCCESS(err);
12390
12391 VkSamplerCreateInfo sampler_ci = {};
12392 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12393 sampler_ci.pNext = NULL;
12394 sampler_ci.magFilter = VK_FILTER_NEAREST;
12395 sampler_ci.minFilter = VK_FILTER_NEAREST;
12396 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12397 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12398 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12399 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12400 sampler_ci.mipLodBias = 1.0;
12401 sampler_ci.anisotropyEnable = VK_FALSE;
12402 sampler_ci.maxAnisotropy = 1;
12403 sampler_ci.compareEnable = VK_FALSE;
12404 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12405 sampler_ci.minLod = 1.0;
12406 sampler_ci.maxLod = 1.0;
12407 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12408 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12409 VkSampler sampler;
12410
12411 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12412 ASSERT_VK_SUCCESS(err);
12413
12414 VkDescriptorSetLayoutBinding layout_binding;
12415 layout_binding.binding = 0;
12416 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12417 layout_binding.descriptorCount = 1;
12418 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12419 layout_binding.pImmutableSamplers = NULL;
12420
12421 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12422 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12423 ds_layout_ci.bindingCount = 1;
12424 ds_layout_ci.pBindings = &layout_binding;
12425 VkDescriptorSetLayout ds_layout;
12426 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12427 ASSERT_VK_SUCCESS(err);
12428
12429 VkDescriptorSetAllocateInfo alloc_info = {};
12430 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12431 alloc_info.descriptorSetCount = 1;
12432 alloc_info.descriptorPool = ds_pool;
12433 alloc_info.pSetLayouts = &ds_layout;
12434 VkDescriptorSet descriptor_set;
12435 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12436 ASSERT_VK_SUCCESS(err);
12437
12438 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12439 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12440 pipeline_layout_ci.pNext = NULL;
12441 pipeline_layout_ci.setLayoutCount = 1;
12442 pipeline_layout_ci.pSetLayouts = &ds_layout;
12443
12444 VkPipelineLayout pipeline_layout;
12445 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12446 ASSERT_VK_SUCCESS(err);
12447
12448 VkImageObj image(m_device);
12449 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12450 ASSERT_TRUE(image.initialized());
12451
12452 VkImageView view;
12453 VkImageViewCreateInfo ivci = {};
12454 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12455 ivci.image = image.handle();
12456 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12457 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12458 ivci.subresourceRange.layerCount = 1;
12459 ivci.subresourceRange.baseMipLevel = 0;
12460 ivci.subresourceRange.levelCount = 1;
12461 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12462
12463 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12464 ASSERT_VK_SUCCESS(err);
12465
12466 VkDescriptorImageInfo image_info{};
12467 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12468 image_info.imageView = view;
12469 image_info.sampler = sampler;
12470
12471 VkWriteDescriptorSet descriptor_write = {};
12472 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12473 descriptor_write.dstSet = descriptor_set;
12474 descriptor_write.dstBinding = 0;
12475 descriptor_write.descriptorCount = 1;
12476 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12477 descriptor_write.pImageInfo = &image_info;
12478
12479 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12480
12481 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012482 char const *vsSource =
12483 "#version 450\n"
12484 "\n"
12485 "out gl_PerVertex { \n"
12486 " vec4 gl_Position;\n"
12487 "};\n"
12488 "void main(){\n"
12489 " gl_Position = vec4(1);\n"
12490 "}\n";
12491 char const *fsSource =
12492 "#version 450\n"
12493 "\n"
12494 "layout(set=0, binding=0) uniform sampler2D s;\n"
12495 "layout(location=0) out vec4 x;\n"
12496 "void main(){\n"
12497 " x = texture(s, vec2(1));\n"
12498 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12501 VkPipelineObj pipe(m_device);
12502 pipe.AddShader(&vs);
12503 pipe.AddShader(&fs);
12504 pipe.AddColorAttachment();
12505 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12506
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012508
Tony Barbour552f6c02016-12-21 14:34:07 -070012509 m_commandBuffer->BeginCommandBuffer();
12510 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012511 // Bind pipeline to cmd buffer
12512 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12513 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12514 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012515
12516 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12517 VkRect2D scissor = {{0, 0}, {16, 16}};
12518 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12519 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12520
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012521 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012522 m_commandBuffer->EndRenderPass();
12523 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012524 // Submit cmd buffer then destroy sampler
12525 VkSubmitInfo submit_info = {};
12526 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12527 submit_info.commandBufferCount = 1;
12528 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12529 // Submit cmd buffer and then destroy imageView while in-flight
12530 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12531
12532 vkDestroyImageView(m_device->device(), view, nullptr);
12533 m_errorMonitor->VerifyFound();
12534 vkQueueWaitIdle(m_device->m_queue);
12535 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012536 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12537 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012538 vkDestroyImageView(m_device->device(), view, NULL);
12539 vkDestroySampler(m_device->device(), sampler, nullptr);
12540 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12541 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12542 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12543}
12544
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012545TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12546 TEST_DESCRIPTION("Delete in-use bufferView.");
12547
12548 ASSERT_NO_FATAL_FAILURE(InitState());
12549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12550
12551 VkDescriptorPoolSize ds_type_count;
12552 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12553 ds_type_count.descriptorCount = 1;
12554
12555 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12556 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12557 ds_pool_ci.maxSets = 1;
12558 ds_pool_ci.poolSizeCount = 1;
12559 ds_pool_ci.pPoolSizes = &ds_type_count;
12560
12561 VkDescriptorPool ds_pool;
12562 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12563 ASSERT_VK_SUCCESS(err);
12564
12565 VkDescriptorSetLayoutBinding layout_binding;
12566 layout_binding.binding = 0;
12567 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12568 layout_binding.descriptorCount = 1;
12569 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12570 layout_binding.pImmutableSamplers = NULL;
12571
12572 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12573 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12574 ds_layout_ci.bindingCount = 1;
12575 ds_layout_ci.pBindings = &layout_binding;
12576 VkDescriptorSetLayout ds_layout;
12577 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12578 ASSERT_VK_SUCCESS(err);
12579
12580 VkDescriptorSetAllocateInfo alloc_info = {};
12581 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12582 alloc_info.descriptorSetCount = 1;
12583 alloc_info.descriptorPool = ds_pool;
12584 alloc_info.pSetLayouts = &ds_layout;
12585 VkDescriptorSet descriptor_set;
12586 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12587 ASSERT_VK_SUCCESS(err);
12588
12589 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12590 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12591 pipeline_layout_ci.pNext = NULL;
12592 pipeline_layout_ci.setLayoutCount = 1;
12593 pipeline_layout_ci.pSetLayouts = &ds_layout;
12594
12595 VkPipelineLayout pipeline_layout;
12596 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12597 ASSERT_VK_SUCCESS(err);
12598
12599 VkBuffer buffer;
12600 uint32_t queue_family_index = 0;
12601 VkBufferCreateInfo buffer_create_info = {};
12602 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12603 buffer_create_info.size = 1024;
12604 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12605 buffer_create_info.queueFamilyIndexCount = 1;
12606 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12607
12608 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12609 ASSERT_VK_SUCCESS(err);
12610
12611 VkMemoryRequirements memory_reqs;
12612 VkDeviceMemory buffer_memory;
12613
12614 VkMemoryAllocateInfo memory_info = {};
12615 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12616 memory_info.allocationSize = 0;
12617 memory_info.memoryTypeIndex = 0;
12618
12619 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12620 memory_info.allocationSize = memory_reqs.size;
12621 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12622 ASSERT_TRUE(pass);
12623
12624 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12625 ASSERT_VK_SUCCESS(err);
12626 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12627 ASSERT_VK_SUCCESS(err);
12628
12629 VkBufferView view;
12630 VkBufferViewCreateInfo bvci = {};
12631 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12632 bvci.buffer = buffer;
12633 bvci.format = VK_FORMAT_R8_UNORM;
12634 bvci.range = VK_WHOLE_SIZE;
12635
12636 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12637 ASSERT_VK_SUCCESS(err);
12638
12639 VkWriteDescriptorSet descriptor_write = {};
12640 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12641 descriptor_write.dstSet = descriptor_set;
12642 descriptor_write.dstBinding = 0;
12643 descriptor_write.descriptorCount = 1;
12644 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12645 descriptor_write.pTexelBufferView = &view;
12646
12647 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12648
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012649 char const *vsSource =
12650 "#version 450\n"
12651 "\n"
12652 "out gl_PerVertex { \n"
12653 " vec4 gl_Position;\n"
12654 "};\n"
12655 "void main(){\n"
12656 " gl_Position = vec4(1);\n"
12657 "}\n";
12658 char const *fsSource =
12659 "#version 450\n"
12660 "\n"
12661 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12662 "layout(location=0) out vec4 x;\n"
12663 "void main(){\n"
12664 " x = imageLoad(s, 0);\n"
12665 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012666 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12667 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12668 VkPipelineObj pipe(m_device);
12669 pipe.AddShader(&vs);
12670 pipe.AddShader(&fs);
12671 pipe.AddColorAttachment();
12672 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12673
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012675
Tony Barbour552f6c02016-12-21 14:34:07 -070012676 m_commandBuffer->BeginCommandBuffer();
12677 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012678 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12679 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12680 VkRect2D scissor = {{0, 0}, {16, 16}};
12681 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12682 // Bind pipeline to cmd buffer
12683 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12684 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12685 &descriptor_set, 0, nullptr);
12686 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012687 m_commandBuffer->EndRenderPass();
12688 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012689
12690 VkSubmitInfo submit_info = {};
12691 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12692 submit_info.commandBufferCount = 1;
12693 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12694 // Submit cmd buffer and then destroy bufferView while in-flight
12695 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12696
12697 vkDestroyBufferView(m_device->device(), view, nullptr);
12698 m_errorMonitor->VerifyFound();
12699 vkQueueWaitIdle(m_device->m_queue);
12700 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012701 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12702 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012703 vkDestroyBufferView(m_device->device(), view, NULL);
12704 vkDestroyBuffer(m_device->device(), buffer, NULL);
12705 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12706 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12707 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12708 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12709}
12710
Tobin Ehlis209532e2016-09-07 13:52:18 -060012711TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12712 TEST_DESCRIPTION("Delete in-use sampler.");
12713
12714 ASSERT_NO_FATAL_FAILURE(InitState());
12715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12716
12717 VkDescriptorPoolSize ds_type_count;
12718 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12719 ds_type_count.descriptorCount = 1;
12720
12721 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12722 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12723 ds_pool_ci.maxSets = 1;
12724 ds_pool_ci.poolSizeCount = 1;
12725 ds_pool_ci.pPoolSizes = &ds_type_count;
12726
12727 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012728 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012729 ASSERT_VK_SUCCESS(err);
12730
12731 VkSamplerCreateInfo sampler_ci = {};
12732 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12733 sampler_ci.pNext = NULL;
12734 sampler_ci.magFilter = VK_FILTER_NEAREST;
12735 sampler_ci.minFilter = VK_FILTER_NEAREST;
12736 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12737 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12738 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12739 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12740 sampler_ci.mipLodBias = 1.0;
12741 sampler_ci.anisotropyEnable = VK_FALSE;
12742 sampler_ci.maxAnisotropy = 1;
12743 sampler_ci.compareEnable = VK_FALSE;
12744 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12745 sampler_ci.minLod = 1.0;
12746 sampler_ci.maxLod = 1.0;
12747 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12748 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12749 VkSampler sampler;
12750
12751 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12752 ASSERT_VK_SUCCESS(err);
12753
12754 VkDescriptorSetLayoutBinding layout_binding;
12755 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012756 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012757 layout_binding.descriptorCount = 1;
12758 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12759 layout_binding.pImmutableSamplers = NULL;
12760
12761 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12762 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12763 ds_layout_ci.bindingCount = 1;
12764 ds_layout_ci.pBindings = &layout_binding;
12765 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012766 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012767 ASSERT_VK_SUCCESS(err);
12768
12769 VkDescriptorSetAllocateInfo alloc_info = {};
12770 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12771 alloc_info.descriptorSetCount = 1;
12772 alloc_info.descriptorPool = ds_pool;
12773 alloc_info.pSetLayouts = &ds_layout;
12774 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012775 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012776 ASSERT_VK_SUCCESS(err);
12777
12778 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12779 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12780 pipeline_layout_ci.pNext = NULL;
12781 pipeline_layout_ci.setLayoutCount = 1;
12782 pipeline_layout_ci.pSetLayouts = &ds_layout;
12783
12784 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012785 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012786 ASSERT_VK_SUCCESS(err);
12787
12788 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012789 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 -060012790 ASSERT_TRUE(image.initialized());
12791
12792 VkImageView view;
12793 VkImageViewCreateInfo ivci = {};
12794 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12795 ivci.image = image.handle();
12796 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12797 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12798 ivci.subresourceRange.layerCount = 1;
12799 ivci.subresourceRange.baseMipLevel = 0;
12800 ivci.subresourceRange.levelCount = 1;
12801 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12802
12803 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12804 ASSERT_VK_SUCCESS(err);
12805
12806 VkDescriptorImageInfo image_info{};
12807 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12808 image_info.imageView = view;
12809 image_info.sampler = sampler;
12810
12811 VkWriteDescriptorSet descriptor_write = {};
12812 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12813 descriptor_write.dstSet = descriptor_set;
12814 descriptor_write.dstBinding = 0;
12815 descriptor_write.descriptorCount = 1;
12816 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12817 descriptor_write.pImageInfo = &image_info;
12818
12819 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12820
12821 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012822 char const *vsSource =
12823 "#version 450\n"
12824 "\n"
12825 "out gl_PerVertex { \n"
12826 " vec4 gl_Position;\n"
12827 "};\n"
12828 "void main(){\n"
12829 " gl_Position = vec4(1);\n"
12830 "}\n";
12831 char const *fsSource =
12832 "#version 450\n"
12833 "\n"
12834 "layout(set=0, binding=0) uniform sampler2D s;\n"
12835 "layout(location=0) out vec4 x;\n"
12836 "void main(){\n"
12837 " x = texture(s, vec2(1));\n"
12838 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012839 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12840 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12841 VkPipelineObj pipe(m_device);
12842 pipe.AddShader(&vs);
12843 pipe.AddShader(&fs);
12844 pipe.AddColorAttachment();
12845 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12846
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012848
Tony Barbour552f6c02016-12-21 14:34:07 -070012849 m_commandBuffer->BeginCommandBuffer();
12850 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012851 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012852 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12853 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12854 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012855
12856 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12857 VkRect2D scissor = {{0, 0}, {16, 16}};
12858 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12859 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12860
Tobin Ehlis209532e2016-09-07 13:52:18 -060012861 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012862 m_commandBuffer->EndRenderPass();
12863 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012864 // Submit cmd buffer then destroy sampler
12865 VkSubmitInfo submit_info = {};
12866 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12867 submit_info.commandBufferCount = 1;
12868 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12869 // Submit cmd buffer and then destroy sampler while in-flight
12870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12871
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012872 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012873 m_errorMonitor->VerifyFound();
12874 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012875
Tobin Ehlis209532e2016-09-07 13:52:18 -060012876 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012877 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12878 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012879 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012880 vkDestroyImageView(m_device->device(), view, NULL);
12881 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12882 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12883 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12884}
12885
Mark Mueller1cd9f412016-08-25 13:23:52 -060012886TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012887 TEST_DESCRIPTION(
12888 "Call VkQueueSubmit with a semaphore that is already "
12889 "signaled but not waited on by the queue. Wait on a "
12890 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012891
12892 ASSERT_NO_FATAL_FAILURE(InitState());
12893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12894
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012895 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 -070012896 const char *invalid_fence_wait_message =
12897 " which has not been submitted on a Queue or during "
12898 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012899
Tony Barbour552f6c02016-12-21 14:34:07 -070012900 m_commandBuffer->BeginCommandBuffer();
12901 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012902
12903 VkSemaphoreCreateInfo semaphore_create_info = {};
12904 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12905 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012906 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012907 VkSubmitInfo submit_info = {};
12908 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12909 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012910 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012911 submit_info.signalSemaphoreCount = 1;
12912 submit_info.pSignalSemaphores = &semaphore;
12913 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012914 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012915 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012916 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012917 m_commandBuffer->BeginCommandBuffer();
12918 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12921 m_errorMonitor->VerifyFound();
12922
Mark Mueller1cd9f412016-08-25 13:23:52 -060012923 VkFenceCreateInfo fence_create_info = {};
12924 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12925 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012926 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012927
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012929 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12930 m_errorMonitor->VerifyFound();
12931
Mark Mueller4042b652016-09-05 22:52:21 -060012932 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012933 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012934 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12935}
12936
Tobin Ehlis4af23302016-07-19 10:50:30 -060012937TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012938 TEST_DESCRIPTION(
12939 "Bind a secondary command buffer with with a framebuffer "
12940 "that does not match the framebuffer for the active "
12941 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012942 ASSERT_NO_FATAL_FAILURE(InitState());
12943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12944
12945 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012946 VkAttachmentDescription attachment = {0,
12947 VK_FORMAT_B8G8R8A8_UNORM,
12948 VK_SAMPLE_COUNT_1_BIT,
12949 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12950 VK_ATTACHMENT_STORE_OP_STORE,
12951 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12952 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12953 VK_IMAGE_LAYOUT_UNDEFINED,
12954 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012955
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012956 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012958 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012960 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012961
12962 VkRenderPass rp;
12963 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12964 ASSERT_VK_SUCCESS(err);
12965
12966 // A compatible framebuffer.
12967 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012968 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 -060012969 ASSERT_TRUE(image.initialized());
12970
12971 VkImageViewCreateInfo ivci = {
12972 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12973 nullptr,
12974 0,
12975 image.handle(),
12976 VK_IMAGE_VIEW_TYPE_2D,
12977 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012978 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12979 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012980 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12981 };
12982 VkImageView view;
12983 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12984 ASSERT_VK_SUCCESS(err);
12985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012986 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012987 VkFramebuffer fb;
12988 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12989 ASSERT_VK_SUCCESS(err);
12990
12991 VkCommandBufferAllocateInfo cbai = {};
12992 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12993 cbai.commandPool = m_commandPool;
12994 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12995 cbai.commandBufferCount = 1;
12996
12997 VkCommandBuffer sec_cb;
12998 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12999 ASSERT_VK_SUCCESS(err);
13000 VkCommandBufferBeginInfo cbbi = {};
13001 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013002 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013003 cbii.renderPass = renderPass();
13004 cbii.framebuffer = fb;
13005 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13006 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013007 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 -060013008 cbbi.pInheritanceInfo = &cbii;
13009 vkBeginCommandBuffer(sec_cb, &cbbi);
13010 vkEndCommandBuffer(sec_cb);
13011
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013012 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013013 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13014 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013017 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013018 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13019 m_errorMonitor->VerifyFound();
13020 // Cleanup
13021 vkDestroyImageView(m_device->device(), view, NULL);
13022 vkDestroyRenderPass(m_device->device(), rp, NULL);
13023 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13024}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013025
13026TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013027 TEST_DESCRIPTION(
13028 "If logicOp is available on the device, set it to an "
13029 "invalid value. If logicOp is not available, attempt to "
13030 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013031 ASSERT_NO_FATAL_FAILURE(InitState());
13032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13033
13034 auto features = m_device->phy().features();
13035 // Set the expected error depending on whether or not logicOp available
13036 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13038 "If logic operations feature not "
13039 "enabled, logicOpEnable must be "
13040 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013041 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013043 }
13044 // Create a pipeline using logicOp
13045 VkResult err;
13046
13047 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13048 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13049
13050 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013051 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013052 ASSERT_VK_SUCCESS(err);
13053
13054 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13055 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13056 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013057 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013058 vp_state_ci.pViewports = &vp;
13059 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013060 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013061 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013062
13063 VkPipelineShaderStageCreateInfo shaderStages[2];
13064 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013066 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13067 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013068 shaderStages[0] = vs.GetStageCreateInfo();
13069 shaderStages[1] = fs.GetStageCreateInfo();
13070
13071 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13072 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13073
13074 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13075 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13076 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13077
13078 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13079 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013080 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013081
13082 VkPipelineColorBlendAttachmentState att = {};
13083 att.blendEnable = VK_FALSE;
13084 att.colorWriteMask = 0xf;
13085
13086 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13087 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13088 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13089 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013090 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013091 cb_ci.attachmentCount = 1;
13092 cb_ci.pAttachments = &att;
13093
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013094 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13095 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13096 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13097
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013098 VkGraphicsPipelineCreateInfo gp_ci = {};
13099 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13100 gp_ci.stageCount = 2;
13101 gp_ci.pStages = shaderStages;
13102 gp_ci.pVertexInputState = &vi_ci;
13103 gp_ci.pInputAssemblyState = &ia_ci;
13104 gp_ci.pViewportState = &vp_state_ci;
13105 gp_ci.pRasterizationState = &rs_ci;
13106 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013107 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013108 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13109 gp_ci.layout = pipeline_layout;
13110 gp_ci.renderPass = renderPass();
13111
13112 VkPipelineCacheCreateInfo pc_ci = {};
13113 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13114
13115 VkPipeline pipeline;
13116 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013117 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013118 ASSERT_VK_SUCCESS(err);
13119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013120 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013121 m_errorMonitor->VerifyFound();
13122 if (VK_SUCCESS == err) {
13123 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13124 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013125 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13126 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13127}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013128
Mike Stroyanaccf7692015-05-12 16:00:45 -060013129#if GTEST_IS_THREADSAFE
13130struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013131 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013132 VkEvent event;
13133 bool bailout;
13134};
13135
Karl Schultz6addd812016-02-02 17:17:23 -070013136extern "C" void *AddToCommandBuffer(void *arg) {
13137 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013138
Mike Stroyana6d14942016-07-13 15:10:05 -060013139 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013140 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013141 if (data->bailout) {
13142 break;
13143 }
13144 }
13145 return NULL;
13146}
13147
Karl Schultz6addd812016-02-02 17:17:23 -070013148TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013149 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013152
Mike Stroyanaccf7692015-05-12 16:00:45 -060013153 ASSERT_NO_FATAL_FAILURE(InitState());
13154 ASSERT_NO_FATAL_FAILURE(InitViewport());
13155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13156
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013157 // Calls AllocateCommandBuffers
13158 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013159
13160 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013161 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013162
13163 VkEventCreateInfo event_info;
13164 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013165 VkResult err;
13166
13167 memset(&event_info, 0, sizeof(event_info));
13168 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13169
Chia-I Wuf7458c52015-10-26 21:10:41 +080013170 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013171 ASSERT_VK_SUCCESS(err);
13172
Mike Stroyanaccf7692015-05-12 16:00:45 -060013173 err = vkResetEvent(device(), event);
13174 ASSERT_VK_SUCCESS(err);
13175
13176 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013177 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013178 data.event = event;
13179 data.bailout = false;
13180 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013181
13182 // First do some correct operations using multiple threads.
13183 // Add many entries to command buffer from another thread.
13184 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13185 // Make non-conflicting calls from this thread at the same time.
13186 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013187 uint32_t count;
13188 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013189 }
13190 test_platform_thread_join(thread, NULL);
13191
13192 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013193 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013194 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013195 // Add many entries to command buffer from this thread at the same time.
13196 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013197
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013198 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013199 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013200
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013201 m_errorMonitor->SetBailout(NULL);
13202
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013203 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013204
Chia-I Wuf7458c52015-10-26 21:10:41 +080013205 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013206}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013207#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013208
Karl Schultz6addd812016-02-02 17:17:23 -070013209TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013210 TEST_DESCRIPTION(
13211 "Test that an error is produced for a spirv module "
13212 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013215
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013216 ASSERT_NO_FATAL_FAILURE(InitState());
13217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13218
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013219 VkShaderModule module;
13220 VkShaderModuleCreateInfo moduleCreateInfo;
13221 struct icd_spv_header spv;
13222
13223 spv.magic = ICD_SPV_MAGIC;
13224 spv.version = ICD_SPV_VERSION;
13225 spv.gen_magic = 0;
13226
13227 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13228 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013229 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013230 moduleCreateInfo.codeSize = 4;
13231 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013232 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013233
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013234 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013235}
13236
Karl Schultz6addd812016-02-02 17:17:23 -070013237TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013238 TEST_DESCRIPTION(
13239 "Test that an error is produced for a spirv module "
13240 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013243
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013244 ASSERT_NO_FATAL_FAILURE(InitState());
13245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13246
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013247 VkShaderModule module;
13248 VkShaderModuleCreateInfo moduleCreateInfo;
13249 struct icd_spv_header spv;
13250
13251 spv.magic = ~ICD_SPV_MAGIC;
13252 spv.version = ICD_SPV_VERSION;
13253 spv.gen_magic = 0;
13254
13255 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13256 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013257 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013258 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13259 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013260 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013261
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013262 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013263}
13264
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013265#if 0
13266// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013267TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013269 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013270
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013271 ASSERT_NO_FATAL_FAILURE(InitState());
13272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13273
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013274 VkShaderModule module;
13275 VkShaderModuleCreateInfo moduleCreateInfo;
13276 struct icd_spv_header spv;
13277
13278 spv.magic = ICD_SPV_MAGIC;
13279 spv.version = ~ICD_SPV_VERSION;
13280 spv.gen_magic = 0;
13281
13282 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13283 moduleCreateInfo.pNext = NULL;
13284
Karl Schultz6addd812016-02-02 17:17:23 -070013285 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013286 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13287 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013288 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013289
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013290 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013291}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013292#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013293
Karl Schultz6addd812016-02-02 17:17:23 -070013294TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013295 TEST_DESCRIPTION(
13296 "Test that a warning is produced for a vertex output that "
13297 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013299
Chris Forbes9f7ff632015-05-25 11:13:08 +120013300 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013302
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013303 char const *vsSource =
13304 "#version 450\n"
13305 "\n"
13306 "layout(location=0) out float x;\n"
13307 "out gl_PerVertex {\n"
13308 " vec4 gl_Position;\n"
13309 "};\n"
13310 "void main(){\n"
13311 " gl_Position = vec4(1);\n"
13312 " x = 0;\n"
13313 "}\n";
13314 char const *fsSource =
13315 "#version 450\n"
13316 "\n"
13317 "layout(location=0) out vec4 color;\n"
13318 "void main(){\n"
13319 " color = vec4(1);\n"
13320 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013321
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013322 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13323 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013324
13325 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013326 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013327 pipe.AddShader(&vs);
13328 pipe.AddShader(&fs);
13329
Chris Forbes9f7ff632015-05-25 11:13:08 +120013330 VkDescriptorSetObj descriptorSet(m_device);
13331 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013332 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013333
Tony Barbour5781e8f2015-08-04 16:23:11 -060013334 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013335
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013336 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013337}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013338
Mark Mueller098c9cb2016-09-08 09:01:57 -060013339TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13340 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13341
13342 ASSERT_NO_FATAL_FAILURE(InitState());
13343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13344
13345 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013346 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013347
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013348 char const *vsSource =
13349 "#version 450\n"
13350 "\n"
13351 "out gl_PerVertex {\n"
13352 " vec4 gl_Position;\n"
13353 "};\n"
13354 "void main(){\n"
13355 " gl_Position = vec4(1);\n"
13356 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013357
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013358 char const *fsSource =
13359 "#version 450\n"
13360 "\n"
13361 "layout (constant_id = 0) const float r = 0.0f;\n"
13362 "layout(location = 0) out vec4 uFragColor;\n"
13363 "void main(){\n"
13364 " uFragColor = vec4(r,1,0,1);\n"
13365 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013366
13367 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13368 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13369
13370 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13371 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13372
13373 VkPipelineLayout pipeline_layout;
13374 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13375
13376 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13377 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13378 vp_state_create_info.viewportCount = 1;
13379 VkViewport viewport = {};
13380 vp_state_create_info.pViewports = &viewport;
13381 vp_state_create_info.scissorCount = 1;
13382 VkRect2D scissors = {};
13383 vp_state_create_info.pScissors = &scissors;
13384
13385 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13386
13387 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13388 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13389 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13390 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13391
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013392 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013393
13394 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13395 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13396
13397 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13398 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13399 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13400
13401 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13402 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13403 rasterization_state_create_info.pNext = nullptr;
13404 rasterization_state_create_info.lineWidth = 1.0f;
13405 rasterization_state_create_info.rasterizerDiscardEnable = true;
13406
13407 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13408 color_blend_attachment_state.blendEnable = VK_FALSE;
13409 color_blend_attachment_state.colorWriteMask = 0xf;
13410
13411 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13412 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13413 color_blend_state_create_info.attachmentCount = 1;
13414 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13415
13416 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13417 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13418 graphicspipe_create_info.stageCount = 2;
13419 graphicspipe_create_info.pStages = shader_stage_create_info;
13420 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13421 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13422 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13423 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13424 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13425 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13426 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13427 graphicspipe_create_info.layout = pipeline_layout;
13428 graphicspipe_create_info.renderPass = renderPass();
13429
13430 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13431 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13432
13433 VkPipelineCache pipelineCache;
13434 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13435
13436 // This structure maps constant ids to data locations.
13437 const VkSpecializationMapEntry entry =
13438 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013439 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013440
13441 uint32_t data = 1;
13442
13443 // Set up the info describing spec map and data
13444 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013445 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013446 };
13447 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13448
13449 VkPipeline pipeline;
13450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13451 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13452 m_errorMonitor->VerifyFound();
13453
13454 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13455 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13456}
13457
13458TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13459 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13460
13461 ASSERT_NO_FATAL_FAILURE(InitState());
13462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13463
13464 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13465
13466 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13467 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13468 descriptor_pool_type_count[0].descriptorCount = 1;
13469 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13470 descriptor_pool_type_count[1].descriptorCount = 1;
13471
13472 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13473 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13474 descriptor_pool_create_info.maxSets = 1;
13475 descriptor_pool_create_info.poolSizeCount = 2;
13476 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13477 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13478
13479 VkDescriptorPool descriptorset_pool;
13480 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13481
13482 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13483 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13484 descriptorset_layout_binding.descriptorCount = 1;
13485 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13486
13487 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13488 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13489 descriptorset_layout_create_info.bindingCount = 1;
13490 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13491
13492 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013493 ASSERT_VK_SUCCESS(
13494 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013495
13496 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13497 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13498 descriptorset_allocate_info.descriptorSetCount = 1;
13499 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13500 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13501 VkDescriptorSet descriptorset;
13502 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13503
13504 // Challenge core_validation with a non uniform buffer type.
13505 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013507 char const *vsSource =
13508 "#version 450\n"
13509 "\n"
13510 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13511 " mat4 mvp;\n"
13512 "} ubuf;\n"
13513 "out gl_PerVertex {\n"
13514 " vec4 gl_Position;\n"
13515 "};\n"
13516 "void main(){\n"
13517 " gl_Position = ubuf.mvp * vec4(1);\n"
13518 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013519
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013520 char const *fsSource =
13521 "#version 450\n"
13522 "\n"
13523 "layout(location = 0) out vec4 uFragColor;\n"
13524 "void main(){\n"
13525 " uFragColor = vec4(0,1,0,1);\n"
13526 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013527
13528 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13529 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13530
13531 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13532 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13533 pipeline_layout_create_info.setLayoutCount = 1;
13534 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13535
13536 VkPipelineLayout pipeline_layout;
13537 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13538
13539 VkPipelineObj pipe(m_device);
13540 pipe.AddColorAttachment();
13541 pipe.AddShader(&vs);
13542 pipe.AddShader(&fs);
13543
13544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13545 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13546 m_errorMonitor->VerifyFound();
13547
13548 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13549 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13550 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13551}
13552
13553TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13554 TEST_DESCRIPTION(
13555 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13556
13557 ASSERT_NO_FATAL_FAILURE(InitState());
13558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13559
13560 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13561
13562 VkDescriptorPoolSize descriptor_pool_type_count = {};
13563 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13564 descriptor_pool_type_count.descriptorCount = 1;
13565
13566 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13567 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13568 descriptor_pool_create_info.maxSets = 1;
13569 descriptor_pool_create_info.poolSizeCount = 1;
13570 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13571 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13572
13573 VkDescriptorPool descriptorset_pool;
13574 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13575
13576 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13577 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13578 descriptorset_layout_binding.descriptorCount = 1;
13579 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13580 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13581
13582 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13583 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13584 descriptorset_layout_create_info.bindingCount = 1;
13585 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13586
13587 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013588 ASSERT_VK_SUCCESS(
13589 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013590
13591 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13592 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13593 descriptorset_allocate_info.descriptorSetCount = 1;
13594 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13595 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13596 VkDescriptorSet descriptorset;
13597 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13598
13599 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13600
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013601 char const *vsSource =
13602 "#version 450\n"
13603 "\n"
13604 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13605 " mat4 mvp;\n"
13606 "} ubuf;\n"
13607 "out gl_PerVertex {\n"
13608 " vec4 gl_Position;\n"
13609 "};\n"
13610 "void main(){\n"
13611 " gl_Position = ubuf.mvp * vec4(1);\n"
13612 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013613
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013614 char const *fsSource =
13615 "#version 450\n"
13616 "\n"
13617 "layout(location = 0) out vec4 uFragColor;\n"
13618 "void main(){\n"
13619 " uFragColor = vec4(0,1,0,1);\n"
13620 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013621
13622 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13623 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13624
13625 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13626 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13627 pipeline_layout_create_info.setLayoutCount = 1;
13628 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13629
13630 VkPipelineLayout pipeline_layout;
13631 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13632
13633 VkPipelineObj pipe(m_device);
13634 pipe.AddColorAttachment();
13635 pipe.AddShader(&vs);
13636 pipe.AddShader(&fs);
13637
13638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13639 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13640 m_errorMonitor->VerifyFound();
13641
13642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13643 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13644 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13645}
13646
13647TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013648 TEST_DESCRIPTION(
13649 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13650 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013651
13652 ASSERT_NO_FATAL_FAILURE(InitState());
13653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13654
13655 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013656 "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 -060013657
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013658 char const *vsSource =
13659 "#version 450\n"
13660 "\n"
13661 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13662 "out gl_PerVertex {\n"
13663 " vec4 gl_Position;\n"
13664 "};\n"
13665 "void main(){\n"
13666 " gl_Position = vec4(consts.x);\n"
13667 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013668
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013669 char const *fsSource =
13670 "#version 450\n"
13671 "\n"
13672 "layout(location = 0) out vec4 uFragColor;\n"
13673 "void main(){\n"
13674 " uFragColor = vec4(0,1,0,1);\n"
13675 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013676
13677 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13678 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13679
13680 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13681 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13682
13683 // Set up a push constant range
13684 VkPushConstantRange push_constant_ranges = {};
13685 // Set to the wrong stage to challenge core_validation
13686 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13687 push_constant_ranges.size = 4;
13688
13689 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13690 pipeline_layout_create_info.pushConstantRangeCount = 1;
13691
13692 VkPipelineLayout pipeline_layout;
13693 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13694
13695 VkPipelineObj pipe(m_device);
13696 pipe.AddColorAttachment();
13697 pipe.AddShader(&vs);
13698 pipe.AddShader(&fs);
13699
13700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13702 m_errorMonitor->VerifyFound();
13703
13704 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13705}
13706
13707TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13708 TEST_DESCRIPTION(
13709 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13710
13711 ASSERT_NO_FATAL_FAILURE(InitState());
13712 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13713
13714 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013715 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013716
13717 // Some awkward steps are required to test with custom device features.
13718 std::vector<const char *> device_extension_names;
13719 auto features = m_device->phy().features();
13720 // Disable support for 64 bit floats
13721 features.shaderFloat64 = false;
13722 // The sacrificial device object
13723 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13724
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013725 char const *vsSource =
13726 "#version 450\n"
13727 "\n"
13728 "out gl_PerVertex {\n"
13729 " vec4 gl_Position;\n"
13730 "};\n"
13731 "void main(){\n"
13732 " gl_Position = vec4(1);\n"
13733 "}\n";
13734 char const *fsSource =
13735 "#version 450\n"
13736 "\n"
13737 "layout(location=0) out vec4 color;\n"
13738 "void main(){\n"
13739 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13740 " color = vec4(green);\n"
13741 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013742
13743 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13744 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13745
13746 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013747
13748 VkPipelineObj pipe(&test_device);
13749 pipe.AddColorAttachment();
13750 pipe.AddShader(&vs);
13751 pipe.AddShader(&fs);
13752
13753 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13754 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13755 VkPipelineLayout pipeline_layout;
13756 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13757
13758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13759 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13760 m_errorMonitor->VerifyFound();
13761
13762 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13763}
13764
13765TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13766 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13767
13768 ASSERT_NO_FATAL_FAILURE(InitState());
13769 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13770
13771 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13772
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013773 char const *vsSource =
13774 "#version 450\n"
13775 "\n"
13776 "out gl_PerVertex {\n"
13777 " vec4 gl_Position;\n"
13778 "};\n"
13779 "layout(xfb_buffer = 1) out;"
13780 "void main(){\n"
13781 " gl_Position = vec4(1);\n"
13782 "}\n";
13783 char const *fsSource =
13784 "#version 450\n"
13785 "\n"
13786 "layout(location=0) out vec4 color;\n"
13787 "void main(){\n"
13788 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13789 " color = vec4(green);\n"
13790 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013791
13792 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13793 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13794
13795 VkPipelineObj pipe(m_device);
13796 pipe.AddColorAttachment();
13797 pipe.AddShader(&vs);
13798 pipe.AddShader(&fs);
13799
13800 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13801 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13802 VkPipelineLayout pipeline_layout;
13803 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13804
13805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13806 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13807 m_errorMonitor->VerifyFound();
13808
13809 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13810}
13811
Karl Schultz6addd812016-02-02 17:17:23 -070013812TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013813 TEST_DESCRIPTION(
13814 "Test that an error is produced for a fragment shader input "
13815 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013818
Chris Forbes59cb88d2015-05-25 11:13:13 +120013819 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013821
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013822 char const *vsSource =
13823 "#version 450\n"
13824 "\n"
13825 "out gl_PerVertex {\n"
13826 " vec4 gl_Position;\n"
13827 "};\n"
13828 "void main(){\n"
13829 " gl_Position = vec4(1);\n"
13830 "}\n";
13831 char const *fsSource =
13832 "#version 450\n"
13833 "\n"
13834 "layout(location=0) in float x;\n"
13835 "layout(location=0) out vec4 color;\n"
13836 "void main(){\n"
13837 " color = vec4(x);\n"
13838 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013839
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013840 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13841 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013842
13843 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013844 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013845 pipe.AddShader(&vs);
13846 pipe.AddShader(&fs);
13847
Chris Forbes59cb88d2015-05-25 11:13:13 +120013848 VkDescriptorSetObj descriptorSet(m_device);
13849 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013850 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013851
Tony Barbour5781e8f2015-08-04 16:23:11 -060013852 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013853
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013854 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013855}
13856
Karl Schultz6addd812016-02-02 17:17:23 -070013857TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013858 TEST_DESCRIPTION(
13859 "Test that an error is produced for a fragment shader input "
13860 "within an interace block, which is not present in the outputs "
13861 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013863
13864 ASSERT_NO_FATAL_FAILURE(InitState());
13865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13866
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013867 char const *vsSource =
13868 "#version 450\n"
13869 "\n"
13870 "out gl_PerVertex {\n"
13871 " vec4 gl_Position;\n"
13872 "};\n"
13873 "void main(){\n"
13874 " gl_Position = vec4(1);\n"
13875 "}\n";
13876 char const *fsSource =
13877 "#version 450\n"
13878 "\n"
13879 "in block { layout(location=0) float x; } ins;\n"
13880 "layout(location=0) out vec4 color;\n"
13881 "void main(){\n"
13882 " color = vec4(ins.x);\n"
13883 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013884
13885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13887
13888 VkPipelineObj pipe(m_device);
13889 pipe.AddColorAttachment();
13890 pipe.AddShader(&vs);
13891 pipe.AddShader(&fs);
13892
13893 VkDescriptorSetObj descriptorSet(m_device);
13894 descriptorSet.AppendDummy();
13895 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13896
13897 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13898
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013899 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013900}
13901
Karl Schultz6addd812016-02-02 17:17:23 -070013902TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013903 TEST_DESCRIPTION(
13904 "Test that an error is produced for mismatched array sizes "
13905 "across the vertex->fragment shader interface");
13906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13907 "Type mismatch on location 0.0: 'ptr to "
13908 "output arr[2] of float32' vs 'ptr to "
13909 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013910
13911 ASSERT_NO_FATAL_FAILURE(InitState());
13912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13913
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013914 char const *vsSource =
13915 "#version 450\n"
13916 "\n"
13917 "layout(location=0) out float x[2];\n"
13918 "out gl_PerVertex {\n"
13919 " vec4 gl_Position;\n"
13920 "};\n"
13921 "void main(){\n"
13922 " x[0] = 0; x[1] = 0;\n"
13923 " gl_Position = vec4(1);\n"
13924 "}\n";
13925 char const *fsSource =
13926 "#version 450\n"
13927 "\n"
13928 "layout(location=0) in float x[1];\n"
13929 "layout(location=0) out vec4 color;\n"
13930 "void main(){\n"
13931 " color = vec4(x[0]);\n"
13932 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013933
13934 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13935 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13936
13937 VkPipelineObj pipe(m_device);
13938 pipe.AddColorAttachment();
13939 pipe.AddShader(&vs);
13940 pipe.AddShader(&fs);
13941
13942 VkDescriptorSetObj descriptorSet(m_device);
13943 descriptorSet.AppendDummy();
13944 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13945
13946 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013948 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013949}
13950
Karl Schultz6addd812016-02-02 17:17:23 -070013951TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013952 TEST_DESCRIPTION(
13953 "Test that an error is produced for mismatched types across "
13954 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013956
Chris Forbesb56af562015-05-25 11:13:17 +120013957 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013959
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013960 char const *vsSource =
13961 "#version 450\n"
13962 "\n"
13963 "layout(location=0) out int x;\n"
13964 "out gl_PerVertex {\n"
13965 " vec4 gl_Position;\n"
13966 "};\n"
13967 "void main(){\n"
13968 " x = 0;\n"
13969 " gl_Position = vec4(1);\n"
13970 "}\n";
13971 char const *fsSource =
13972 "#version 450\n"
13973 "\n"
13974 "layout(location=0) in float x;\n" /* VS writes int */
13975 "layout(location=0) out vec4 color;\n"
13976 "void main(){\n"
13977 " color = vec4(x);\n"
13978 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013979
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013980 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13981 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013982
13983 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013984 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013985 pipe.AddShader(&vs);
13986 pipe.AddShader(&fs);
13987
Chris Forbesb56af562015-05-25 11:13:17 +120013988 VkDescriptorSetObj descriptorSet(m_device);
13989 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013990 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013991
Tony Barbour5781e8f2015-08-04 16:23:11 -060013992 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013993
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013994 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013995}
13996
Karl Schultz6addd812016-02-02 17:17:23 -070013997TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013998 TEST_DESCRIPTION(
13999 "Test that an error is produced for mismatched types across "
14000 "the vertex->fragment shader interface, when the variable is contained within "
14001 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014003
14004 ASSERT_NO_FATAL_FAILURE(InitState());
14005 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14006
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014007 char const *vsSource =
14008 "#version 450\n"
14009 "\n"
14010 "out block { layout(location=0) int x; } outs;\n"
14011 "out gl_PerVertex {\n"
14012 " vec4 gl_Position;\n"
14013 "};\n"
14014 "void main(){\n"
14015 " outs.x = 0;\n"
14016 " gl_Position = vec4(1);\n"
14017 "}\n";
14018 char const *fsSource =
14019 "#version 450\n"
14020 "\n"
14021 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14022 "layout(location=0) out vec4 color;\n"
14023 "void main(){\n"
14024 " color = vec4(ins.x);\n"
14025 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014026
14027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14029
14030 VkPipelineObj pipe(m_device);
14031 pipe.AddColorAttachment();
14032 pipe.AddShader(&vs);
14033 pipe.AddShader(&fs);
14034
14035 VkDescriptorSetObj descriptorSet(m_device);
14036 descriptorSet.AppendDummy();
14037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14038
14039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014041 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014042}
14043
14044TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014045 TEST_DESCRIPTION(
14046 "Test that an error is produced for location mismatches across "
14047 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14048 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014049 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 +130014050
14051 ASSERT_NO_FATAL_FAILURE(InitState());
14052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14053
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014054 char const *vsSource =
14055 "#version 450\n"
14056 "\n"
14057 "out block { layout(location=1) float x; } outs;\n"
14058 "out gl_PerVertex {\n"
14059 " vec4 gl_Position;\n"
14060 "};\n"
14061 "void main(){\n"
14062 " outs.x = 0;\n"
14063 " gl_Position = vec4(1);\n"
14064 "}\n";
14065 char const *fsSource =
14066 "#version 450\n"
14067 "\n"
14068 "in block { layout(location=0) float x; } ins;\n"
14069 "layout(location=0) out vec4 color;\n"
14070 "void main(){\n"
14071 " color = vec4(ins.x);\n"
14072 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014073
14074 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14075 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14076
14077 VkPipelineObj pipe(m_device);
14078 pipe.AddColorAttachment();
14079 pipe.AddShader(&vs);
14080 pipe.AddShader(&fs);
14081
14082 VkDescriptorSetObj descriptorSet(m_device);
14083 descriptorSet.AppendDummy();
14084 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14085
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014086 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014087 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14088
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014089 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014090}
14091
14092TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014093 TEST_DESCRIPTION(
14094 "Test that an error is produced for component mismatches across the "
14095 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14096 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014097 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 +130014098
14099 ASSERT_NO_FATAL_FAILURE(InitState());
14100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14101
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014102 char const *vsSource =
14103 "#version 450\n"
14104 "\n"
14105 "out block { layout(location=0, component=0) float x; } outs;\n"
14106 "out gl_PerVertex {\n"
14107 " vec4 gl_Position;\n"
14108 "};\n"
14109 "void main(){\n"
14110 " outs.x = 0;\n"
14111 " gl_Position = vec4(1);\n"
14112 "}\n";
14113 char const *fsSource =
14114 "#version 450\n"
14115 "\n"
14116 "in block { layout(location=0, component=1) float x; } ins;\n"
14117 "layout(location=0) out vec4 color;\n"
14118 "void main(){\n"
14119 " color = vec4(ins.x);\n"
14120 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014121
14122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14124
14125 VkPipelineObj pipe(m_device);
14126 pipe.AddColorAttachment();
14127 pipe.AddShader(&vs);
14128 pipe.AddShader(&fs);
14129
14130 VkDescriptorSetObj descriptorSet(m_device);
14131 descriptorSet.AppendDummy();
14132 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14133
14134 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14135
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014136 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014137}
14138
Chris Forbes1f3b0152016-11-30 12:48:40 +130014139TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14140 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14141
14142 ASSERT_NO_FATAL_FAILURE(InitState());
14143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14144
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014145 char const *vsSource =
14146 "#version 450\n"
14147 "layout(location=0) out mediump float x;\n"
14148 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14149 char const *fsSource =
14150 "#version 450\n"
14151 "layout(location=0) in highp float x;\n"
14152 "layout(location=0) out vec4 color;\n"
14153 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014154
14155 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14156 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14157
14158 VkPipelineObj pipe(m_device);
14159 pipe.AddColorAttachment();
14160 pipe.AddShader(&vs);
14161 pipe.AddShader(&fs);
14162
14163 VkDescriptorSetObj descriptorSet(m_device);
14164 descriptorSet.AppendDummy();
14165 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14166
14167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14168
14169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14170
14171 m_errorMonitor->VerifyFound();
14172}
14173
Chris Forbes870a39e2016-11-30 12:55:56 +130014174TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14175 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14176
14177 ASSERT_NO_FATAL_FAILURE(InitState());
14178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14179
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014180 char const *vsSource =
14181 "#version 450\n"
14182 "out block { layout(location=0) mediump float x; };\n"
14183 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14184 char const *fsSource =
14185 "#version 450\n"
14186 "in block { layout(location=0) highp float x; };\n"
14187 "layout(location=0) out vec4 color;\n"
14188 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014189
14190 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14191 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14192
14193 VkPipelineObj pipe(m_device);
14194 pipe.AddColorAttachment();
14195 pipe.AddShader(&vs);
14196 pipe.AddShader(&fs);
14197
14198 VkDescriptorSetObj descriptorSet(m_device);
14199 descriptorSet.AppendDummy();
14200 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14201
14202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14203
14204 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14205
14206 m_errorMonitor->VerifyFound();
14207}
14208
Karl Schultz6addd812016-02-02 17:17:23 -070014209TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014210 TEST_DESCRIPTION(
14211 "Test that a warning is produced for a vertex attribute which is "
14212 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014214
Chris Forbesde136e02015-05-25 11:13:28 +120014215 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014217
14218 VkVertexInputBindingDescription input_binding;
14219 memset(&input_binding, 0, sizeof(input_binding));
14220
14221 VkVertexInputAttributeDescription input_attrib;
14222 memset(&input_attrib, 0, sizeof(input_attrib));
14223 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14224
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014225 char const *vsSource =
14226 "#version 450\n"
14227 "\n"
14228 "out gl_PerVertex {\n"
14229 " vec4 gl_Position;\n"
14230 "};\n"
14231 "void main(){\n"
14232 " gl_Position = vec4(1);\n"
14233 "}\n";
14234 char const *fsSource =
14235 "#version 450\n"
14236 "\n"
14237 "layout(location=0) out vec4 color;\n"
14238 "void main(){\n"
14239 " color = vec4(1);\n"
14240 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014241
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014242 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14243 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014244
14245 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014246 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014247 pipe.AddShader(&vs);
14248 pipe.AddShader(&fs);
14249
14250 pipe.AddVertexInputBindings(&input_binding, 1);
14251 pipe.AddVertexInputAttribs(&input_attrib, 1);
14252
Chris Forbesde136e02015-05-25 11:13:28 +120014253 VkDescriptorSetObj descriptorSet(m_device);
14254 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014255 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014256
Tony Barbour5781e8f2015-08-04 16:23:11 -060014257 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014258
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014259 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014260}
14261
Karl Schultz6addd812016-02-02 17:17:23 -070014262TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014263 TEST_DESCRIPTION(
14264 "Test that a warning is produced for a location mismatch on "
14265 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014267
14268 ASSERT_NO_FATAL_FAILURE(InitState());
14269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14270
14271 VkVertexInputBindingDescription input_binding;
14272 memset(&input_binding, 0, sizeof(input_binding));
14273
14274 VkVertexInputAttributeDescription input_attrib;
14275 memset(&input_attrib, 0, sizeof(input_attrib));
14276 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14277
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014278 char const *vsSource =
14279 "#version 450\n"
14280 "\n"
14281 "layout(location=1) in float x;\n"
14282 "out gl_PerVertex {\n"
14283 " vec4 gl_Position;\n"
14284 "};\n"
14285 "void main(){\n"
14286 " gl_Position = vec4(x);\n"
14287 "}\n";
14288 char const *fsSource =
14289 "#version 450\n"
14290 "\n"
14291 "layout(location=0) out vec4 color;\n"
14292 "void main(){\n"
14293 " color = vec4(1);\n"
14294 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014295
14296 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14297 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14298
14299 VkPipelineObj pipe(m_device);
14300 pipe.AddColorAttachment();
14301 pipe.AddShader(&vs);
14302 pipe.AddShader(&fs);
14303
14304 pipe.AddVertexInputBindings(&input_binding, 1);
14305 pipe.AddVertexInputAttribs(&input_attrib, 1);
14306
14307 VkDescriptorSetObj descriptorSet(m_device);
14308 descriptorSet.AppendDummy();
14309 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14310
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014311 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014312 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14313
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014314 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014315}
14316
Karl Schultz6addd812016-02-02 17:17:23 -070014317TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014318 TEST_DESCRIPTION(
14319 "Test that an error is produced for a vertex shader input which is not "
14320 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14322 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014323
Chris Forbes62e8e502015-05-25 11:13:29 +120014324 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014326
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014327 char const *vsSource =
14328 "#version 450\n"
14329 "\n"
14330 "layout(location=0) in vec4 x;\n" /* not provided */
14331 "out gl_PerVertex {\n"
14332 " vec4 gl_Position;\n"
14333 "};\n"
14334 "void main(){\n"
14335 " gl_Position = x;\n"
14336 "}\n";
14337 char const *fsSource =
14338 "#version 450\n"
14339 "\n"
14340 "layout(location=0) out vec4 color;\n"
14341 "void main(){\n"
14342 " color = vec4(1);\n"
14343 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014344
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014345 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14346 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014347
14348 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014349 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014350 pipe.AddShader(&vs);
14351 pipe.AddShader(&fs);
14352
Chris Forbes62e8e502015-05-25 11:13:29 +120014353 VkDescriptorSetObj descriptorSet(m_device);
14354 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014355 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014356
Tony Barbour5781e8f2015-08-04 16:23:11 -060014357 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014358
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014359 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014360}
14361
Karl Schultz6addd812016-02-02 17:17:23 -070014362TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014363 TEST_DESCRIPTION(
14364 "Test that an error is produced for a mismatch between the "
14365 "fundamental type (float/int/uint) of an attribute and the "
14366 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014367 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 -060014368
Chris Forbesc97d98e2015-05-25 11:13:31 +120014369 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014371
14372 VkVertexInputBindingDescription input_binding;
14373 memset(&input_binding, 0, sizeof(input_binding));
14374
14375 VkVertexInputAttributeDescription input_attrib;
14376 memset(&input_attrib, 0, sizeof(input_attrib));
14377 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14378
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014379 char const *vsSource =
14380 "#version 450\n"
14381 "\n"
14382 "layout(location=0) in int x;\n" /* attrib provided float */
14383 "out gl_PerVertex {\n"
14384 " vec4 gl_Position;\n"
14385 "};\n"
14386 "void main(){\n"
14387 " gl_Position = vec4(x);\n"
14388 "}\n";
14389 char const *fsSource =
14390 "#version 450\n"
14391 "\n"
14392 "layout(location=0) out vec4 color;\n"
14393 "void main(){\n"
14394 " color = vec4(1);\n"
14395 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014396
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014397 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14398 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014399
14400 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014401 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014402 pipe.AddShader(&vs);
14403 pipe.AddShader(&fs);
14404
14405 pipe.AddVertexInputBindings(&input_binding, 1);
14406 pipe.AddVertexInputAttribs(&input_attrib, 1);
14407
Chris Forbesc97d98e2015-05-25 11:13:31 +120014408 VkDescriptorSetObj descriptorSet(m_device);
14409 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014410 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014411
Tony Barbour5781e8f2015-08-04 16:23:11 -060014412 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014413
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014414 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014415}
14416
Chris Forbesc68b43c2016-04-06 11:18:47 +120014417TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014418 TEST_DESCRIPTION(
14419 "Test that an error is produced for a pipeline containing multiple "
14420 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14422 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014423
14424 ASSERT_NO_FATAL_FAILURE(InitState());
14425 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14426
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014427 char const *vsSource =
14428 "#version 450\n"
14429 "\n"
14430 "out gl_PerVertex {\n"
14431 " vec4 gl_Position;\n"
14432 "};\n"
14433 "void main(){\n"
14434 " gl_Position = vec4(1);\n"
14435 "}\n";
14436 char const *fsSource =
14437 "#version 450\n"
14438 "\n"
14439 "layout(location=0) out vec4 color;\n"
14440 "void main(){\n"
14441 " color = vec4(1);\n"
14442 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014443
14444 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14445 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14446
14447 VkPipelineObj pipe(m_device);
14448 pipe.AddColorAttachment();
14449 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014450 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014451 pipe.AddShader(&fs);
14452
14453 VkDescriptorSetObj descriptorSet(m_device);
14454 descriptorSet.AppendDummy();
14455 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14456
14457 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14458
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014459 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014460}
14461
Chris Forbes82ff92a2016-09-09 10:50:24 +120014462TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014464
14465 ASSERT_NO_FATAL_FAILURE(InitState());
14466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14467
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014468 char const *vsSource =
14469 "#version 450\n"
14470 "out gl_PerVertex {\n"
14471 " vec4 gl_Position;\n"
14472 "};\n"
14473 "void main(){\n"
14474 " gl_Position = vec4(0);\n"
14475 "}\n";
14476 char const *fsSource =
14477 "#version 450\n"
14478 "\n"
14479 "layout(location=0) out vec4 color;\n"
14480 "void main(){\n"
14481 " color = vec4(1);\n"
14482 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014483
14484 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14485 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14486
14487 VkPipelineObj pipe(m_device);
14488 pipe.AddColorAttachment();
14489 pipe.AddShader(&vs);
14490 pipe.AddShader(&fs);
14491
14492 VkDescriptorSetObj descriptorSet(m_device);
14493 descriptorSet.AppendDummy();
14494 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14495
14496 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14497
14498 m_errorMonitor->VerifyFound();
14499}
14500
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014501TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14503 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14504 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014505
14506 ASSERT_NO_FATAL_FAILURE(InitState());
14507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14508
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014509 char const *vsSource =
14510 "#version 450\n"
14511 "void main(){ gl_Position = vec4(0); }\n";
14512 char const *fsSource =
14513 "#version 450\n"
14514 "\n"
14515 "layout(location=0) out vec4 color;\n"
14516 "void main(){\n"
14517 " color = vec4(1);\n"
14518 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014519
14520 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14521 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14522
14523 VkPipelineObj pipe(m_device);
14524 pipe.AddColorAttachment();
14525 pipe.AddShader(&vs);
14526 pipe.AddShader(&fs);
14527
14528 VkDescriptorSetObj descriptorSet(m_device);
14529 descriptorSet.AppendDummy();
14530 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14531
14532 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014533 {
14534 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14535 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14536 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014537 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014538 {
14539 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14540 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14541 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014542 },
14543 };
14544 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014545 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014546 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014547 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14548 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014549 VkRenderPass rp;
14550 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14551 ASSERT_VK_SUCCESS(err);
14552
14553 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14554
14555 m_errorMonitor->VerifyFound();
14556
14557 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14558}
14559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014560TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014561 TEST_DESCRIPTION(
14562 "Test that an error is produced for a variable output from "
14563 "the TCS without the patch decoration, but consumed in the TES "
14564 "with the decoration.");
14565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14566 "is per-vertex in tessellation control shader stage "
14567 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014568
14569 ASSERT_NO_FATAL_FAILURE(InitState());
14570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14571
Chris Forbesc1e852d2016-04-04 19:26:42 +120014572 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014573 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014574 return;
14575 }
14576
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014577 char const *vsSource =
14578 "#version 450\n"
14579 "void main(){}\n";
14580 char const *tcsSource =
14581 "#version 450\n"
14582 "layout(location=0) out int x[];\n"
14583 "layout(vertices=3) out;\n"
14584 "void main(){\n"
14585 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14586 " gl_TessLevelInner[0] = 1;\n"
14587 " x[gl_InvocationID] = gl_InvocationID;\n"
14588 "}\n";
14589 char const *tesSource =
14590 "#version 450\n"
14591 "layout(triangles, equal_spacing, cw) in;\n"
14592 "layout(location=0) patch in int x;\n"
14593 "out gl_PerVertex { vec4 gl_Position; };\n"
14594 "void main(){\n"
14595 " gl_Position.xyz = gl_TessCoord;\n"
14596 " gl_Position.w = x;\n"
14597 "}\n";
14598 char const *fsSource =
14599 "#version 450\n"
14600 "layout(location=0) out vec4 color;\n"
14601 "void main(){\n"
14602 " color = vec4(1);\n"
14603 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014604
14605 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14606 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14607 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14608 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014610 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14611 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014613 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014614
14615 VkPipelineObj pipe(m_device);
14616 pipe.SetInputAssembly(&iasci);
14617 pipe.SetTessellation(&tsci);
14618 pipe.AddColorAttachment();
14619 pipe.AddShader(&vs);
14620 pipe.AddShader(&tcs);
14621 pipe.AddShader(&tes);
14622 pipe.AddShader(&fs);
14623
14624 VkDescriptorSetObj descriptorSet(m_device);
14625 descriptorSet.AppendDummy();
14626 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14627
14628 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14629
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014630 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014631}
14632
Karl Schultz6addd812016-02-02 17:17:23 -070014633TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014634 TEST_DESCRIPTION(
14635 "Test that an error is produced for a vertex attribute setup where multiple "
14636 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14638 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014639
Chris Forbes280ba2c2015-06-12 11:16:41 +120014640 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014642
14643 /* Two binding descriptions for binding 0 */
14644 VkVertexInputBindingDescription input_bindings[2];
14645 memset(input_bindings, 0, sizeof(input_bindings));
14646
14647 VkVertexInputAttributeDescription input_attrib;
14648 memset(&input_attrib, 0, sizeof(input_attrib));
14649 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14650
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014651 char const *vsSource =
14652 "#version 450\n"
14653 "\n"
14654 "layout(location=0) in float x;\n" /* attrib provided float */
14655 "out gl_PerVertex {\n"
14656 " vec4 gl_Position;\n"
14657 "};\n"
14658 "void main(){\n"
14659 " gl_Position = vec4(x);\n"
14660 "}\n";
14661 char const *fsSource =
14662 "#version 450\n"
14663 "\n"
14664 "layout(location=0) out vec4 color;\n"
14665 "void main(){\n"
14666 " color = vec4(1);\n"
14667 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014668
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014669 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14670 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014671
14672 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014673 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014674 pipe.AddShader(&vs);
14675 pipe.AddShader(&fs);
14676
14677 pipe.AddVertexInputBindings(input_bindings, 2);
14678 pipe.AddVertexInputAttribs(&input_attrib, 1);
14679
Chris Forbes280ba2c2015-06-12 11:16:41 +120014680 VkDescriptorSetObj descriptorSet(m_device);
14681 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014682 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014683
Tony Barbour5781e8f2015-08-04 16:23:11 -060014684 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014685
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014686 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014687}
Chris Forbes8f68b562015-05-25 11:13:32 +120014688
Karl Schultz6addd812016-02-02 17:17:23 -070014689TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014690 TEST_DESCRIPTION(
14691 "Test that an error is produced for a fragment shader which does not "
14692 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014694
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014695 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014696
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014697 char const *vsSource =
14698 "#version 450\n"
14699 "\n"
14700 "out gl_PerVertex {\n"
14701 " vec4 gl_Position;\n"
14702 "};\n"
14703 "void main(){\n"
14704 " gl_Position = vec4(1);\n"
14705 "}\n";
14706 char const *fsSource =
14707 "#version 450\n"
14708 "\n"
14709 "void main(){\n"
14710 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014711
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014712 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14713 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014714
14715 VkPipelineObj pipe(m_device);
14716 pipe.AddShader(&vs);
14717 pipe.AddShader(&fs);
14718
Chia-I Wu08accc62015-07-07 11:50:03 +080014719 /* set up CB 0, not written */
14720 pipe.AddColorAttachment();
14721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014722
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014723 VkDescriptorSetObj descriptorSet(m_device);
14724 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014725 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014726
Tony Barbour5781e8f2015-08-04 16:23:11 -060014727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014728
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014729 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014730}
14731
Karl Schultz6addd812016-02-02 17:17:23 -070014732TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014733 TEST_DESCRIPTION(
14734 "Test that a warning is produced for a fragment shader which provides a spurious "
14735 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014737 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014738
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014739 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014740
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014741 char const *vsSource =
14742 "#version 450\n"
14743 "\n"
14744 "out gl_PerVertex {\n"
14745 " vec4 gl_Position;\n"
14746 "};\n"
14747 "void main(){\n"
14748 " gl_Position = vec4(1);\n"
14749 "}\n";
14750 char const *fsSource =
14751 "#version 450\n"
14752 "\n"
14753 "layout(location=0) out vec4 x;\n"
14754 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14755 "void main(){\n"
14756 " x = vec4(1);\n"
14757 " y = vec4(1);\n"
14758 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014759
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014760 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14761 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014762
14763 VkPipelineObj pipe(m_device);
14764 pipe.AddShader(&vs);
14765 pipe.AddShader(&fs);
14766
Chia-I Wu08accc62015-07-07 11:50:03 +080014767 /* set up CB 0, not written */
14768 pipe.AddColorAttachment();
14769 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014770 /* FS writes CB 1, but we don't configure it */
14771
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014772 VkDescriptorSetObj descriptorSet(m_device);
14773 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014774 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014775
Tony Barbour5781e8f2015-08-04 16:23:11 -060014776 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014777
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014778 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014779}
14780
Karl Schultz6addd812016-02-02 17:17:23 -070014781TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014782 TEST_DESCRIPTION(
14783 "Test that an error is produced for a mismatch between the fundamental "
14784 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014786
Chris Forbesa36d69e2015-05-25 11:13:44 +120014787 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014788
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014789 char const *vsSource =
14790 "#version 450\n"
14791 "\n"
14792 "out gl_PerVertex {\n"
14793 " vec4 gl_Position;\n"
14794 "};\n"
14795 "void main(){\n"
14796 " gl_Position = vec4(1);\n"
14797 "}\n";
14798 char const *fsSource =
14799 "#version 450\n"
14800 "\n"
14801 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14802 "void main(){\n"
14803 " x = ivec4(1);\n"
14804 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014805
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014806 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14807 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014808
14809 VkPipelineObj pipe(m_device);
14810 pipe.AddShader(&vs);
14811 pipe.AddShader(&fs);
14812
Chia-I Wu08accc62015-07-07 11:50:03 +080014813 /* set up CB 0; type is UNORM by default */
14814 pipe.AddColorAttachment();
14815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014816
Chris Forbesa36d69e2015-05-25 11:13:44 +120014817 VkDescriptorSetObj descriptorSet(m_device);
14818 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014819 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014820
Tony Barbour5781e8f2015-08-04 16:23:11 -060014821 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014822
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014823 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014824}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014825
Karl Schultz6addd812016-02-02 17:17:23 -070014826TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014827 TEST_DESCRIPTION(
14828 "Test that an error is produced for a shader consuming a uniform "
14829 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014831
Chris Forbes556c76c2015-08-14 12:04:59 +120014832 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014833
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014834 char const *vsSource =
14835 "#version 450\n"
14836 "\n"
14837 "out gl_PerVertex {\n"
14838 " vec4 gl_Position;\n"
14839 "};\n"
14840 "void main(){\n"
14841 " gl_Position = vec4(1);\n"
14842 "}\n";
14843 char const *fsSource =
14844 "#version 450\n"
14845 "\n"
14846 "layout(location=0) out vec4 x;\n"
14847 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14848 "void main(){\n"
14849 " x = vec4(bar.y);\n"
14850 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014851
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014852 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14853 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014854
Chris Forbes556c76c2015-08-14 12:04:59 +120014855 VkPipelineObj pipe(m_device);
14856 pipe.AddShader(&vs);
14857 pipe.AddShader(&fs);
14858
14859 /* set up CB 0; type is UNORM by default */
14860 pipe.AddColorAttachment();
14861 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14862
14863 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014864 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014865
14866 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14867
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014868 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014869}
14870
Chris Forbes5c59e902016-02-26 16:56:09 +130014871TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014872 TEST_DESCRIPTION(
14873 "Test that an error is produced for a shader consuming push constants "
14874 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014876
14877 ASSERT_NO_FATAL_FAILURE(InitState());
14878
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014879 char const *vsSource =
14880 "#version 450\n"
14881 "\n"
14882 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14883 "out gl_PerVertex {\n"
14884 " vec4 gl_Position;\n"
14885 "};\n"
14886 "void main(){\n"
14887 " gl_Position = vec4(consts.x);\n"
14888 "}\n";
14889 char const *fsSource =
14890 "#version 450\n"
14891 "\n"
14892 "layout(location=0) out vec4 x;\n"
14893 "void main(){\n"
14894 " x = vec4(1);\n"
14895 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014896
14897 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14898 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14899
14900 VkPipelineObj pipe(m_device);
14901 pipe.AddShader(&vs);
14902 pipe.AddShader(&fs);
14903
14904 /* set up CB 0; type is UNORM by default */
14905 pipe.AddColorAttachment();
14906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14907
14908 VkDescriptorSetObj descriptorSet(m_device);
14909 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14910
14911 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14912
14913 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014914 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014915}
14916
Chris Forbes3fb17902016-08-22 14:57:55 +120014917TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014918 TEST_DESCRIPTION(
14919 "Test that an error is produced for a shader consuming an input attachment "
14920 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14922 "consumes input attachment index 0 but not provided in subpass");
14923
14924 ASSERT_NO_FATAL_FAILURE(InitState());
14925
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014926 char const *vsSource =
14927 "#version 450\n"
14928 "\n"
14929 "out gl_PerVertex {\n"
14930 " vec4 gl_Position;\n"
14931 "};\n"
14932 "void main(){\n"
14933 " gl_Position = vec4(1);\n"
14934 "}\n";
14935 char const *fsSource =
14936 "#version 450\n"
14937 "\n"
14938 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14939 "layout(location=0) out vec4 color;\n"
14940 "void main() {\n"
14941 " color = subpassLoad(x);\n"
14942 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014943
14944 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14945 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14946
14947 VkPipelineObj pipe(m_device);
14948 pipe.AddShader(&vs);
14949 pipe.AddShader(&fs);
14950 pipe.AddColorAttachment();
14951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014953 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14954 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014955 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014956 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014957 ASSERT_VK_SUCCESS(err);
14958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014959 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014960 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014961 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014962 ASSERT_VK_SUCCESS(err);
14963
14964 // error here.
14965 pipe.CreateVKPipeline(pl, renderPass());
14966
14967 m_errorMonitor->VerifyFound();
14968
14969 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14970 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14971}
14972
Chris Forbes5a9a0472016-08-22 16:02:09 +120014973TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014974 TEST_DESCRIPTION(
14975 "Test that an error is produced for a shader consuming an input attachment "
14976 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14978 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14979
14980 ASSERT_NO_FATAL_FAILURE(InitState());
14981
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014982 char const *vsSource =
14983 "#version 450\n"
14984 "\n"
14985 "out gl_PerVertex {\n"
14986 " vec4 gl_Position;\n"
14987 "};\n"
14988 "void main(){\n"
14989 " gl_Position = vec4(1);\n"
14990 "}\n";
14991 char const *fsSource =
14992 "#version 450\n"
14993 "\n"
14994 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14995 "layout(location=0) out vec4 color;\n"
14996 "void main() {\n"
14997 " color = subpassLoad(x);\n"
14998 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014999
15000 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15001 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15002
15003 VkPipelineObj pipe(m_device);
15004 pipe.AddShader(&vs);
15005 pipe.AddShader(&fs);
15006 pipe.AddColorAttachment();
15007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015009 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15010 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015011 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015012 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015013 ASSERT_VK_SUCCESS(err);
15014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015015 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015016 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015017 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015018 ASSERT_VK_SUCCESS(err);
15019
15020 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015021 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15022 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15023 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15024 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15025 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 +120015026 };
15027 VkAttachmentReference color = {
15028 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15029 };
15030 VkAttachmentReference input = {
15031 1, VK_IMAGE_LAYOUT_GENERAL,
15032 };
15033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015034 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015036 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015037 VkRenderPass rp;
15038 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15039 ASSERT_VK_SUCCESS(err);
15040
15041 // error here.
15042 pipe.CreateVKPipeline(pl, rp);
15043
15044 m_errorMonitor->VerifyFound();
15045
15046 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15047 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15048 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15049}
15050
Chris Forbes541f7b02016-08-22 15:30:27 +120015051TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015052 TEST_DESCRIPTION(
15053 "Test that an error is produced for a shader consuming an input attachment "
15054 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015056 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015057
15058 ASSERT_NO_FATAL_FAILURE(InitState());
15059
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015060 char const *vsSource =
15061 "#version 450\n"
15062 "\n"
15063 "out gl_PerVertex {\n"
15064 " vec4 gl_Position;\n"
15065 "};\n"
15066 "void main(){\n"
15067 " gl_Position = vec4(1);\n"
15068 "}\n";
15069 char const *fsSource =
15070 "#version 450\n"
15071 "\n"
15072 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15073 "layout(location=0) out vec4 color;\n"
15074 "void main() {\n"
15075 " color = subpassLoad(xs[0]);\n"
15076 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015077
15078 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15079 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15080
15081 VkPipelineObj pipe(m_device);
15082 pipe.AddShader(&vs);
15083 pipe.AddShader(&fs);
15084 pipe.AddColorAttachment();
15085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15086
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015087 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15088 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015089 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015090 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015091 ASSERT_VK_SUCCESS(err);
15092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015093 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015094 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015095 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015096 ASSERT_VK_SUCCESS(err);
15097
15098 // error here.
15099 pipe.CreateVKPipeline(pl, renderPass());
15100
15101 m_errorMonitor->VerifyFound();
15102
15103 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15104 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15105}
15106
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015107TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015108 TEST_DESCRIPTION(
15109 "Test that an error is produced for a compute pipeline consuming a "
15110 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015112
15113 ASSERT_NO_FATAL_FAILURE(InitState());
15114
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015115 char const *csSource =
15116 "#version 450\n"
15117 "\n"
15118 "layout(local_size_x=1) in;\n"
15119 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15120 "void main(){\n"
15121 " x = vec4(1);\n"
15122 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015123
15124 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15125
15126 VkDescriptorSetObj descriptorSet(m_device);
15127 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015129 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15130 nullptr,
15131 0,
15132 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15133 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15134 descriptorSet.GetPipelineLayout(),
15135 VK_NULL_HANDLE,
15136 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015137
15138 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015139 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015140
15141 m_errorMonitor->VerifyFound();
15142
15143 if (err == VK_SUCCESS) {
15144 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15145 }
15146}
15147
Chris Forbes22a9b092016-07-19 14:34:05 +120015148TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015149 TEST_DESCRIPTION(
15150 "Test that an error is produced for a pipeline consuming a "
15151 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15153 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015154
15155 ASSERT_NO_FATAL_FAILURE(InitState());
15156
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015157 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15158 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015159 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015160 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015161 ASSERT_VK_SUCCESS(err);
15162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015163 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015164 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015165 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015166 ASSERT_VK_SUCCESS(err);
15167
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015168 char const *csSource =
15169 "#version 450\n"
15170 "\n"
15171 "layout(local_size_x=1) in;\n"
15172 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15173 "void main() {\n"
15174 " x.x = 1.0f;\n"
15175 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015176 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015178 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15179 nullptr,
15180 0,
15181 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15182 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15183 pl,
15184 VK_NULL_HANDLE,
15185 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015186
15187 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015188 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015189
15190 m_errorMonitor->VerifyFound();
15191
15192 if (err == VK_SUCCESS) {
15193 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15194 }
15195
15196 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15197 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15198}
15199
Chris Forbes50020592016-07-27 13:52:41 +120015200TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015201 TEST_DESCRIPTION(
15202 "Test that an error is produced when an image view type "
15203 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015205 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 +120015206
15207 ASSERT_NO_FATAL_FAILURE(InitState());
15208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15209
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015210 char const *vsSource =
15211 "#version 450\n"
15212 "\n"
15213 "out gl_PerVertex { vec4 gl_Position; };\n"
15214 "void main() { gl_Position = vec4(0); }\n";
15215 char const *fsSource =
15216 "#version 450\n"
15217 "\n"
15218 "layout(set=0, binding=0) uniform sampler3D s;\n"
15219 "layout(location=0) out vec4 color;\n"
15220 "void main() {\n"
15221 " color = texture(s, vec3(0));\n"
15222 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015223 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15224 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15225
15226 VkPipelineObj pipe(m_device);
15227 pipe.AddShader(&vs);
15228 pipe.AddShader(&fs);
15229 pipe.AddColorAttachment();
15230
15231 VkTextureObj texture(m_device, nullptr);
15232 VkSamplerObj sampler(m_device);
15233
15234 VkDescriptorSetObj descriptorSet(m_device);
15235 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15236 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15237
15238 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15239 ASSERT_VK_SUCCESS(err);
15240
Tony Barbour552f6c02016-12-21 14:34:07 -070015241 m_commandBuffer->BeginCommandBuffer();
15242 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015243
15244 m_commandBuffer->BindPipeline(pipe);
15245 m_commandBuffer->BindDescriptorSet(descriptorSet);
15246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015247 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015248 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015249 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015250 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15251
15252 // error produced here.
15253 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15254
15255 m_errorMonitor->VerifyFound();
15256
Tony Barbour552f6c02016-12-21 14:34:07 -070015257 m_commandBuffer->EndRenderPass();
15258 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015259}
15260
Chris Forbes5533bfc2016-07-27 14:12:34 +120015261TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015262 TEST_DESCRIPTION(
15263 "Test that an error is produced when a multisampled images "
15264 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015267
15268 ASSERT_NO_FATAL_FAILURE(InitState());
15269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15270
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015271 char const *vsSource =
15272 "#version 450\n"
15273 "\n"
15274 "out gl_PerVertex { vec4 gl_Position; };\n"
15275 "void main() { gl_Position = vec4(0); }\n";
15276 char const *fsSource =
15277 "#version 450\n"
15278 "\n"
15279 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15280 "layout(location=0) out vec4 color;\n"
15281 "void main() {\n"
15282 " color = texelFetch(s, ivec2(0), 0);\n"
15283 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015284 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15285 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15286
15287 VkPipelineObj pipe(m_device);
15288 pipe.AddShader(&vs);
15289 pipe.AddShader(&fs);
15290 pipe.AddColorAttachment();
15291
15292 VkTextureObj texture(m_device, nullptr);
15293 VkSamplerObj sampler(m_device);
15294
15295 VkDescriptorSetObj descriptorSet(m_device);
15296 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15297 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15298
15299 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15300 ASSERT_VK_SUCCESS(err);
15301
Tony Barbour552f6c02016-12-21 14:34:07 -070015302 m_commandBuffer->BeginCommandBuffer();
15303 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015304
15305 m_commandBuffer->BindPipeline(pipe);
15306 m_commandBuffer->BindDescriptorSet(descriptorSet);
15307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015308 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015309 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015310 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015311 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15312
15313 // error produced here.
15314 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15315
15316 m_errorMonitor->VerifyFound();
15317
Tony Barbour552f6c02016-12-21 14:34:07 -070015318 m_commandBuffer->EndRenderPass();
15319 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015320}
15321
Mark Youngc48c4c12016-04-11 14:26:49 -060015322TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015324
15325 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015326
15327 // Create an image
15328 VkImage image;
15329
Karl Schultz6addd812016-02-02 17:17:23 -070015330 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15331 const int32_t tex_width = 32;
15332 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015333
15334 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015335 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15336 image_create_info.pNext = NULL;
15337 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15338 image_create_info.format = tex_format;
15339 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015340 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015341 image_create_info.extent.depth = 1;
15342 image_create_info.mipLevels = 1;
15343 image_create_info.arrayLayers = 1;
15344 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15345 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15346 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15347 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015348
15349 // Introduce error by sending down a bogus width extent
15350 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015351 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015352
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015353 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015354}
15355
Mark Youngc48c4c12016-04-11 14:26:49 -060015356TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015358
15359 ASSERT_NO_FATAL_FAILURE(InitState());
15360
15361 // Create an image
15362 VkImage image;
15363
15364 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15365 const int32_t tex_width = 32;
15366 const int32_t tex_height = 32;
15367
15368 VkImageCreateInfo image_create_info = {};
15369 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15370 image_create_info.pNext = NULL;
15371 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15372 image_create_info.format = tex_format;
15373 image_create_info.extent.width = tex_width;
15374 image_create_info.extent.height = tex_height;
15375 image_create_info.extent.depth = 1;
15376 image_create_info.mipLevels = 1;
15377 image_create_info.arrayLayers = 1;
15378 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15379 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15380 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15381 image_create_info.flags = 0;
15382
15383 // Introduce error by sending down a bogus width extent
15384 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015385 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015386 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15387
15388 m_errorMonitor->VerifyFound();
15389}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015390
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015391TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015392 TEST_DESCRIPTION(
15393 "Create a render pass with an attachment description "
15394 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015395
15396 ASSERT_NO_FATAL_FAILURE(InitState());
15397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15398
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015400
15401 VkAttachmentReference color_attach = {};
15402 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15403 color_attach.attachment = 0;
15404 VkSubpassDescription subpass = {};
15405 subpass.colorAttachmentCount = 1;
15406 subpass.pColorAttachments = &color_attach;
15407
15408 VkRenderPassCreateInfo rpci = {};
15409 rpci.subpassCount = 1;
15410 rpci.pSubpasses = &subpass;
15411 rpci.attachmentCount = 1;
15412 VkAttachmentDescription attach_desc = {};
15413 attach_desc.format = VK_FORMAT_UNDEFINED;
15414 rpci.pAttachments = &attach_desc;
15415 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15416 VkRenderPass rp;
15417 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15418
15419 m_errorMonitor->VerifyFound();
15420
15421 if (result == VK_SUCCESS) {
15422 vkDestroyRenderPass(m_device->device(), rp, NULL);
15423 }
15424}
15425
Karl Schultz6addd812016-02-02 17:17:23 -070015426TEST_F(VkLayerTest, InvalidImageView) {
15427 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015428
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015430
Tobin Ehliscde08892015-09-22 10:11:37 -060015431 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015432
Mike Stroyana3082432015-09-25 13:39:21 -060015433 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015434 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015435
Karl Schultz6addd812016-02-02 17:17:23 -070015436 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15437 const int32_t tex_width = 32;
15438 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015439
15440 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015441 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15442 image_create_info.pNext = NULL;
15443 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15444 image_create_info.format = tex_format;
15445 image_create_info.extent.width = tex_width;
15446 image_create_info.extent.height = tex_height;
15447 image_create_info.extent.depth = 1;
15448 image_create_info.mipLevels = 1;
15449 image_create_info.arrayLayers = 1;
15450 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15451 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15452 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15453 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015454
Chia-I Wuf7458c52015-10-26 21:10:41 +080015455 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015456 ASSERT_VK_SUCCESS(err);
15457
15458 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015459 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015460 image_view_create_info.image = image;
15461 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15462 image_view_create_info.format = tex_format;
15463 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015464 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015465 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015466 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015467
15468 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015469 m_errorMonitor->SetUnexpectedError(
15470 "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 -060015471 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015472
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015473 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015474 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015475}
Mike Stroyana3082432015-09-25 13:39:21 -060015476
Mark Youngd339ba32016-05-30 13:28:35 -060015477TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15478 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015480 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015481
15482 ASSERT_NO_FATAL_FAILURE(InitState());
15483
15484 // Create an image and try to create a view with no memory backing the image
15485 VkImage image;
15486
15487 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15488 const int32_t tex_width = 32;
15489 const int32_t tex_height = 32;
15490
15491 VkImageCreateInfo image_create_info = {};
15492 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15493 image_create_info.pNext = NULL;
15494 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15495 image_create_info.format = tex_format;
15496 image_create_info.extent.width = tex_width;
15497 image_create_info.extent.height = tex_height;
15498 image_create_info.extent.depth = 1;
15499 image_create_info.mipLevels = 1;
15500 image_create_info.arrayLayers = 1;
15501 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15502 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15503 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15504 image_create_info.flags = 0;
15505
15506 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15507 ASSERT_VK_SUCCESS(err);
15508
15509 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015510 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015511 image_view_create_info.image = image;
15512 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15513 image_view_create_info.format = tex_format;
15514 image_view_create_info.subresourceRange.layerCount = 1;
15515 image_view_create_info.subresourceRange.baseMipLevel = 0;
15516 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015517 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015518
15519 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015520 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015521
15522 m_errorMonitor->VerifyFound();
15523 vkDestroyImage(m_device->device(), image, NULL);
15524 // If last error is success, it still created the view, so delete it.
15525 if (err == VK_SUCCESS) {
15526 vkDestroyImageView(m_device->device(), view, NULL);
15527 }
Mark Youngd339ba32016-05-30 13:28:35 -060015528}
15529
Karl Schultz6addd812016-02-02 17:17:23 -070015530TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015531 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015533
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015534 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015535
Karl Schultz6addd812016-02-02 17:17:23 -070015536 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015537 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015538 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015539 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015540
15541 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015542 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015543 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015544 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15545 image_view_create_info.format = tex_format;
15546 image_view_create_info.subresourceRange.baseMipLevel = 0;
15547 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015548 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015549 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015550 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015551
15552 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015553 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015554
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015555 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015556}
15557
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015558TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015559 VkResult err;
15560 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015561
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015563
Mike Stroyana3082432015-09-25 13:39:21 -060015564 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015565
15566 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015567 VkImage srcImage;
15568 VkImage dstImage;
15569 VkDeviceMemory srcMem;
15570 VkDeviceMemory destMem;
15571 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015572
15573 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015574 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15575 image_create_info.pNext = NULL;
15576 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15577 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15578 image_create_info.extent.width = 32;
15579 image_create_info.extent.height = 32;
15580 image_create_info.extent.depth = 1;
15581 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015582 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015583 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15584 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15585 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15586 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015588 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015589 ASSERT_VK_SUCCESS(err);
15590
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015591 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015592 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015593 ASSERT_VK_SUCCESS(err);
15594
15595 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015596 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015597 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15598 memAlloc.pNext = NULL;
15599 memAlloc.allocationSize = 0;
15600 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015601
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015602 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015603 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015604 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015605 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015606 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015607 ASSERT_VK_SUCCESS(err);
15608
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015609 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015610 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015611 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015612 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015613 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015614 ASSERT_VK_SUCCESS(err);
15615
15616 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15617 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015618 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015619 ASSERT_VK_SUCCESS(err);
15620
Tony Barbour552f6c02016-12-21 14:34:07 -070015621 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015622 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015623 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015624 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015625 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015626 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015627 copyRegion.srcOffset.x = 0;
15628 copyRegion.srcOffset.y = 0;
15629 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015630 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015631 copyRegion.dstSubresource.mipLevel = 0;
15632 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015633 // Introduce failure by forcing the dst layerCount to differ from src
15634 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015635 copyRegion.dstOffset.x = 0;
15636 copyRegion.dstOffset.y = 0;
15637 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015638 copyRegion.extent.width = 1;
15639 copyRegion.extent.height = 1;
15640 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015641 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015642 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015643
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015644 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015645
Chia-I Wuf7458c52015-10-26 21:10:41 +080015646 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015647 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015648 vkFreeMemory(m_device->device(), srcMem, NULL);
15649 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015650}
15651
Tony Barbourd6673642016-05-05 14:46:39 -060015652TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015653 TEST_DESCRIPTION("Creating images with unsuported formats ");
15654
15655 ASSERT_NO_FATAL_FAILURE(InitState());
15656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15657 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015658 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 -060015659 VK_IMAGE_TILING_OPTIMAL, 0);
15660 ASSERT_TRUE(image.initialized());
15661
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015662 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015663 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015665 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15666 image_create_info.format = VK_FORMAT_UNDEFINED;
15667 image_create_info.extent.width = 32;
15668 image_create_info.extent.height = 32;
15669 image_create_info.extent.depth = 1;
15670 image_create_info.mipLevels = 1;
15671 image_create_info.arrayLayers = 1;
15672 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15673 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15674 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015675
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15677 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015678
15679 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015680 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15681 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15682 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15683 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015684 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15685 m_errorMonitor->VerifyFound();
15686
Tony Barbourd6673642016-05-05 14:46:39 -060015687 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015688 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015689 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15690 VkFormat format = static_cast<VkFormat>(f);
15691 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015692 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015693 unsupported = format;
15694 break;
15695 }
15696 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015697
Tony Barbourd6673642016-05-05 14:46:39 -060015698 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015699 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015701
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015702 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15703 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15704 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15705 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15706 m_errorMonitor->SetUnexpectedError(
15707 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15708 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15709 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015710 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015711 m_errorMonitor->VerifyFound();
15712 }
15713}
15714
15715TEST_F(VkLayerTest, ImageLayerViewTests) {
15716 VkResult ret;
15717 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15718
15719 ASSERT_NO_FATAL_FAILURE(InitState());
15720
15721 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015722 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 -060015723 VK_IMAGE_TILING_OPTIMAL, 0);
15724 ASSERT_TRUE(image.initialized());
15725
15726 VkImageView imgView;
15727 VkImageViewCreateInfo imgViewInfo = {};
15728 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15729 imgViewInfo.image = image.handle();
15730 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15731 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15732 imgViewInfo.subresourceRange.layerCount = 1;
15733 imgViewInfo.subresourceRange.baseMipLevel = 0;
15734 imgViewInfo.subresourceRange.levelCount = 1;
15735 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15736
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015738 // View can't have baseMipLevel >= image's mipLevels - Expect
15739 // VIEW_CREATE_ERROR
15740 imgViewInfo.subresourceRange.baseMipLevel = 1;
15741 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15742 m_errorMonitor->VerifyFound();
15743 imgViewInfo.subresourceRange.baseMipLevel = 0;
15744
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015746 // View can't have baseArrayLayer >= image's arraySize - Expect
15747 // VIEW_CREATE_ERROR
15748 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15749 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15750 m_errorMonitor->VerifyFound();
15751 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15752
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015754 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15755 imgViewInfo.subresourceRange.levelCount = 0;
15756 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15757 m_errorMonitor->VerifyFound();
15758 imgViewInfo.subresourceRange.levelCount = 1;
15759
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015760 m_errorMonitor->SetDesiredFailureMsg(
15761 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15762 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015763 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15764 imgViewInfo.subresourceRange.layerCount = 0;
15765 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15766 m_errorMonitor->VerifyFound();
15767 imgViewInfo.subresourceRange.layerCount = 1;
15768
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15770 "Formats MUST be IDENTICAL unless "
15771 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15772 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015773 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15774 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15775 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15776 m_errorMonitor->VerifyFound();
15777 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15778
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015780 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15781 // VIEW_CREATE_ERROR
15782 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15783 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15784 m_errorMonitor->VerifyFound();
15785 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15786
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015788 // TODO: Update framework to easily passing mutable flag into ImageObj init
15789 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015790 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15791 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15792 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015793 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15794 // VIEW_CREATE_ERROR
15795 VkImageCreateInfo mutImgInfo = image.create_info();
15796 VkImage mutImage;
15797 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015798 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015799 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15800 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15801 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15802 ASSERT_VK_SUCCESS(ret);
15803 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015804 m_errorMonitor->SetUnexpectedError(
15805 "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 -060015806 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15807 m_errorMonitor->VerifyFound();
15808 imgViewInfo.image = image.handle();
15809 vkDestroyImage(m_device->handle(), mutImage, NULL);
15810}
15811
Dave Houlton59a20702017-02-02 17:26:23 -070015812TEST_F(VkLayerTest, ImageBufferCopyTests) {
15813 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
15814
15815 ASSERT_NO_FATAL_FAILURE(InitState());
15816 VkImageObj image_64k(m_device); // 128^2 texels, 64k
15817 VkImageObj image_16k(m_device); // 64^2 texels, 16k
15818 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
15819 VkImageObj image_16k_bc5(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
15820 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
15821 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15822 VK_IMAGE_TILING_OPTIMAL, 0);
15823 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
15824 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15825 VK_IMAGE_TILING_OPTIMAL, 0);
15826 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15827 VK_IMAGE_TILING_OPTIMAL, 0);
15828 image_16k_bc5.init(32, 32, VK_FORMAT_BC5_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15829 ASSERT_TRUE(image_64k.initialized());
15830 ASSERT_TRUE(image_16k.initialized());
15831 ASSERT_TRUE(image_16k_depth.initialized());
15832 ASSERT_TRUE(image_16k_bc5.initialized());
15833
15834 vk_testing::Buffer buffer_64k, buffer_16k;
15835 VkMemoryPropertyFlags reqs = 0;
15836 buffer_64k.init_as_src_and_dst(*m_device, 128 * 128 * 4, reqs); // 64k
15837 buffer_16k.init_as_src_and_dst(*m_device, 64 * 64 * 4, reqs); // 16k
15838
15839 VkBufferImageCopy region = {};
15840 region.bufferRowLength = 0;
15841 region.bufferImageHeight = 0;
15842 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15843 region.imageSubresource.layerCount = 1;
15844 region.imageOffset = {0, 0, 0};
15845 region.imageExtent = {64, 64, 1};
15846 region.bufferOffset = 0;
15847
15848 // attempt copies before putting command buffer in recording state
15849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
15850 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15851 &region);
15852 m_errorMonitor->VerifyFound();
15853
15854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
15855 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
15856 &region);
15857 m_errorMonitor->VerifyFound();
15858
15859 // start recording
15860 m_commandBuffer->BeginCommandBuffer();
15861
15862 // successful copies
15863 m_errorMonitor->ExpectSuccess();
15864 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15865 &region);
15866 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15867 &region);
15868 region.imageOffset.x = 16; // 16k copy, offset requires larger image
15869 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15870 &region);
15871 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
15872 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15873 &region);
15874 region.imageOffset.x = 0;
15875 region.imageExtent.height = 64;
15876 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
15877 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
15878 &region);
15879 m_errorMonitor->VerifyNotFound();
15880
15881 // image/buffer too small (extent) on copy to image
15882 region.imageExtent = {65, 64, 1};
15883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
15884 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15885 &region);
15886 m_errorMonitor->VerifyFound();
15887
15888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
15889 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15890 &region);
15891 m_errorMonitor->VerifyFound();
15892
15893 // image/buffer too small (offset) on copy to image
15894 region.imageExtent = {64, 64, 1};
15895 region.imageOffset = {0, 4, 0};
15896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
15897 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15898 &region);
15899 m_errorMonitor->VerifyFound();
15900
15901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
15902 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15903 &region);
15904 m_errorMonitor->VerifyFound();
15905
15906 // image/buffer too small on copy to buffer
15907 region.imageExtent = {64, 64, 1};
15908 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070015909 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070015910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
15911 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15912 &region);
15913 m_errorMonitor->VerifyFound();
15914
15915 region.imageExtent = {64, 65, 1};
15916 region.bufferOffset = 0;
15917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
15918 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
15919 &region);
15920 m_errorMonitor->VerifyFound();
15921
15922 // buffer size ok but rowlength causes loose packing
15923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
15924 region.imageExtent = {64, 64, 1};
15925 region.bufferRowLength = 68;
15926 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15927 &region);
15928 m_errorMonitor->VerifyFound();
15929
Dave Houlton59a20702017-02-02 17:26:23 -070015930 // aspect bits
15931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
15932 region.imageExtent = {64, 64, 1};
15933 region.bufferRowLength = 0;
15934 region.bufferImageHeight = 0;
15935 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15936 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
15937 buffer_16k.handle(), 1, &region);
15938 m_errorMonitor->VerifyFound();
15939
15940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
15941 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
15942 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15943 &region);
15944 m_errorMonitor->VerifyFound();
15945
15946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
15947 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15948 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
15949 buffer_16k.handle(), 1, &region);
15950 m_errorMonitor->VerifyFound();
15951
15952 // copying compressed formats
15953
15954 // Just fits
15955 m_errorMonitor->ExpectSuccess();
15956 region.imageExtent = {128, 128, 1};
15957 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(),
15958 1, &region);
15959 m_errorMonitor->VerifyNotFound();
15960
15961 // with offset, too big for buffer
15962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
15963 region.bufferOffset = 16;
15964 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(),
15965 1, &region);
15966 m_errorMonitor->VerifyFound();
15967
15968 // buffer offset must be a multiple of texel block size (16)
15969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
15970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
15971 region.imageExtent = {64, 64, 1};
15972 region.bufferOffset = 24;
15973 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(),
15974 1, &region);
15975 m_errorMonitor->VerifyFound();
15976
15977 // rowlength not a multiple of block width (4)
15978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
15979 region.bufferOffset = 0;
15980 region.bufferRowLength = 130;
15981 region.bufferImageHeight = 0;
15982 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(),
15983 1, &region);
15984 m_errorMonitor->VerifyFound();
15985
15986 // imageheight not a multiple of block height (4)
15987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
15988 region.bufferRowLength = 0;
15989 region.bufferImageHeight = 130;
15990 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(),
15991 1, &region);
15992 m_errorMonitor->VerifyFound();
15993
15994 // image extents must be multiple of block dimensions (4x4)
15995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
15996 region.bufferImageHeight = 0;
15997 region.imageOffset = {4, 6, 0};
15998 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(),
15999 1, &region);
16000 m_errorMonitor->VerifyFound();
16001
16002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16003 region.imageOffset = {22, 0, 0};
16004 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_bc5.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(),
16005 1, &region);
16006 m_errorMonitor->VerifyFound();
16007}
16008
Tony Barbourd6673642016-05-05 14:46:39 -060016009TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016010 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016011
16012 ASSERT_NO_FATAL_FAILURE(InitState());
16013
Rene Lindsay135204f2016-12-22 17:11:09 -070016014 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016015 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016016 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 -070016017 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016018 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016019 vk_testing::Buffer buffer;
16020 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016021 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016022 VkBufferImageCopy region = {};
16023 region.bufferRowLength = 128;
16024 region.bufferImageHeight = 128;
16025 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16026 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016027 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016028 region.imageExtent.height = 4;
16029 region.imageExtent.width = 4;
16030 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016031
16032 VkImageObj image2(m_device);
16033 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 -070016034 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016035 ASSERT_TRUE(image2.initialized());
16036 vk_testing::Buffer buffer2;
16037 VkMemoryPropertyFlags reqs2 = 0;
16038 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16039 VkBufferImageCopy region2 = {};
16040 region2.bufferRowLength = 128;
16041 region2.bufferImageHeight = 128;
16042 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16043 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16044 region2.imageSubresource.layerCount = 1;
16045 region2.imageExtent.height = 4;
16046 region2.imageExtent.width = 4;
16047 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016048 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016049
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016050 // Image must have offset.z of 0 and extent.depth of 1
16051 // Introduce failure by setting imageExtent.depth to 0
16052 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016054 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016055 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016056 m_errorMonitor->VerifyFound();
16057
16058 region.imageExtent.depth = 1;
16059
16060 // Image must have offset.z of 0 and extent.depth of 1
16061 // Introduce failure by setting imageOffset.z to 4
16062 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016064 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016065 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016066 m_errorMonitor->VerifyFound();
16067
16068 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016069 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16070 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016071 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016073 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16074 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016075 m_errorMonitor->VerifyFound();
16076
16077 // BufferOffset must be a multiple of 4
16078 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016079 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016081 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16082 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016083 m_errorMonitor->VerifyFound();
16084
16085 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16086 region.bufferOffset = 0;
16087 region.imageExtent.height = 128;
16088 region.imageExtent.width = 128;
16089 // Introduce failure by setting bufferRowLength > 0 but less than width
16090 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016092 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16093 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016094 m_errorMonitor->VerifyFound();
16095
16096 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16097 region.bufferRowLength = 128;
16098 // Introduce failure by setting bufferRowHeight > 0 but less than height
16099 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016101 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16102 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016103 m_errorMonitor->VerifyFound();
16104
16105 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016106 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016107 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16108 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016109 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016110 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16111 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016112 VkImageBlit blitRegion = {};
16113 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16114 blitRegion.srcSubresource.baseArrayLayer = 0;
16115 blitRegion.srcSubresource.layerCount = 1;
16116 blitRegion.srcSubresource.mipLevel = 0;
16117 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16118 blitRegion.dstSubresource.baseArrayLayer = 0;
16119 blitRegion.dstSubresource.layerCount = 1;
16120 blitRegion.dstSubresource.mipLevel = 0;
16121
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016122 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016124 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016125 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16126 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016127 m_errorMonitor->VerifyFound();
16128
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016130 VkImageMemoryBarrier img_barrier;
16131 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16132 img_barrier.pNext = NULL;
16133 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16134 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16135 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16136 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16137 img_barrier.image = image.handle();
16138 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16139 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16140 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16141 img_barrier.subresourceRange.baseArrayLayer = 0;
16142 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016143 img_barrier.subresourceRange.layerCount = 0;
16144 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016145 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16146 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016147 m_errorMonitor->VerifyFound();
16148 img_barrier.subresourceRange.layerCount = 1;
16149}
16150
16151TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016152 TEST_DESCRIPTION("Exceed the limits of image format ");
16153
Cody Northropc31a84f2016-08-22 10:41:47 -060016154 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016156 VkImageCreateInfo image_create_info = {};
16157 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16158 image_create_info.pNext = NULL;
16159 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16160 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16161 image_create_info.extent.width = 32;
16162 image_create_info.extent.height = 32;
16163 image_create_info.extent.depth = 1;
16164 image_create_info.mipLevels = 1;
16165 image_create_info.arrayLayers = 1;
16166 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16167 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16168 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16169 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16170 image_create_info.flags = 0;
16171
16172 VkImage nullImg;
16173 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016174 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16175 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016176 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016177 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16178 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16179 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016180 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016183 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16184 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16185 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16186 m_errorMonitor->VerifyFound();
16187 image_create_info.mipLevels = 1;
16188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016190 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16191 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16192 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16193 m_errorMonitor->VerifyFound();
16194 image_create_info.arrayLayers = 1;
16195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016197 int samples = imgFmtProps.sampleCounts >> 1;
16198 image_create_info.samples = (VkSampleCountFlagBits)samples;
16199 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16200 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16201 m_errorMonitor->VerifyFound();
16202 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16203
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16205 "pCreateInfo->initialLayout, must be "
16206 "VK_IMAGE_LAYOUT_UNDEFINED or "
16207 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016208 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16209 // Expect INVALID_LAYOUT
16210 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16211 m_errorMonitor->VerifyFound();
16212 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16213}
16214
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016215TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016216 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016218
16219 ASSERT_NO_FATAL_FAILURE(InitState());
16220
16221 VkImageObj src_image(m_device);
16222 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16223 VkImageObj dst_image(m_device);
16224 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16225
Tony Barbour552f6c02016-12-21 14:34:07 -070016226 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016227 VkImageCopy copy_region;
16228 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16229 copy_region.srcSubresource.mipLevel = 0;
16230 copy_region.srcSubresource.baseArrayLayer = 0;
16231 copy_region.srcSubresource.layerCount = 0;
16232 copy_region.srcOffset.x = 0;
16233 copy_region.srcOffset.y = 0;
16234 copy_region.srcOffset.z = 0;
16235 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16236 copy_region.dstSubresource.mipLevel = 0;
16237 copy_region.dstSubresource.baseArrayLayer = 0;
16238 copy_region.dstSubresource.layerCount = 0;
16239 copy_region.dstOffset.x = 0;
16240 copy_region.dstOffset.y = 0;
16241 copy_region.dstOffset.z = 0;
16242 copy_region.extent.width = 64;
16243 copy_region.extent.height = 64;
16244 copy_region.extent.depth = 1;
16245 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16246 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016247 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016248
16249 m_errorMonitor->VerifyFound();
16250}
16251
16252TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016253 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016255
16256 ASSERT_NO_FATAL_FAILURE(InitState());
16257
16258 VkImageObj src_image(m_device);
16259 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16260 VkImageObj dst_image(m_device);
16261 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16262
Tony Barbour552f6c02016-12-21 14:34:07 -070016263 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016264 VkImageCopy copy_region;
16265 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16266 copy_region.srcSubresource.mipLevel = 0;
16267 copy_region.srcSubresource.baseArrayLayer = 0;
16268 copy_region.srcSubresource.layerCount = 0;
16269 copy_region.srcOffset.x = 0;
16270 copy_region.srcOffset.y = 0;
16271 copy_region.srcOffset.z = 0;
16272 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16273 copy_region.dstSubresource.mipLevel = 0;
16274 copy_region.dstSubresource.baseArrayLayer = 0;
16275 copy_region.dstSubresource.layerCount = 0;
16276 copy_region.dstOffset.x = 0;
16277 copy_region.dstOffset.y = 0;
16278 copy_region.dstOffset.z = 0;
16279 copy_region.extent.width = 64;
16280 copy_region.extent.height = 64;
16281 copy_region.extent.depth = 1;
16282 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16283 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016284 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016285
16286 m_errorMonitor->VerifyFound();
16287}
16288
Karl Schultz6addd812016-02-02 17:17:23 -070016289TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016290 VkResult err;
16291 bool pass;
16292
16293 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016295
16296 ASSERT_NO_FATAL_FAILURE(InitState());
16297
16298 // Create two images of different types and try to copy between them
16299 VkImage srcImage;
16300 VkImage dstImage;
16301 VkDeviceMemory srcMem;
16302 VkDeviceMemory destMem;
16303 VkMemoryRequirements memReqs;
16304
16305 VkImageCreateInfo image_create_info = {};
16306 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16307 image_create_info.pNext = NULL;
16308 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16309 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16310 image_create_info.extent.width = 32;
16311 image_create_info.extent.height = 32;
16312 image_create_info.extent.depth = 1;
16313 image_create_info.mipLevels = 1;
16314 image_create_info.arrayLayers = 1;
16315 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16316 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16317 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16318 image_create_info.flags = 0;
16319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016320 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016321 ASSERT_VK_SUCCESS(err);
16322
16323 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16324 // Introduce failure by creating second image with a different-sized format.
16325 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016327 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016328 ASSERT_VK_SUCCESS(err);
16329
16330 // Allocate memory
16331 VkMemoryAllocateInfo memAlloc = {};
16332 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16333 memAlloc.pNext = NULL;
16334 memAlloc.allocationSize = 0;
16335 memAlloc.memoryTypeIndex = 0;
16336
16337 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16338 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016339 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016340 ASSERT_TRUE(pass);
16341 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16342 ASSERT_VK_SUCCESS(err);
16343
16344 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16345 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016346 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016347 ASSERT_TRUE(pass);
16348 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16349 ASSERT_VK_SUCCESS(err);
16350
16351 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16352 ASSERT_VK_SUCCESS(err);
16353 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16354 ASSERT_VK_SUCCESS(err);
16355
Tony Barbour552f6c02016-12-21 14:34:07 -070016356 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016357 VkImageCopy copyRegion;
16358 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16359 copyRegion.srcSubresource.mipLevel = 0;
16360 copyRegion.srcSubresource.baseArrayLayer = 0;
16361 copyRegion.srcSubresource.layerCount = 0;
16362 copyRegion.srcOffset.x = 0;
16363 copyRegion.srcOffset.y = 0;
16364 copyRegion.srcOffset.z = 0;
16365 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16366 copyRegion.dstSubresource.mipLevel = 0;
16367 copyRegion.dstSubresource.baseArrayLayer = 0;
16368 copyRegion.dstSubresource.layerCount = 0;
16369 copyRegion.dstOffset.x = 0;
16370 copyRegion.dstOffset.y = 0;
16371 copyRegion.dstOffset.z = 0;
16372 copyRegion.extent.width = 1;
16373 copyRegion.extent.height = 1;
16374 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016375 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016376 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016377
16378 m_errorMonitor->VerifyFound();
16379
16380 vkDestroyImage(m_device->device(), srcImage, NULL);
16381 vkDestroyImage(m_device->device(), dstImage, NULL);
16382 vkFreeMemory(m_device->device(), srcMem, NULL);
16383 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016384}
16385
Karl Schultz6addd812016-02-02 17:17:23 -070016386TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16387 VkResult err;
16388 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016389
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016390 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16392 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016393
Mike Stroyana3082432015-09-25 13:39:21 -060016394 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016395
16396 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016397 VkImage srcImage;
16398 VkImage dstImage;
16399 VkDeviceMemory srcMem;
16400 VkDeviceMemory destMem;
16401 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016402
16403 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016404 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16405 image_create_info.pNext = NULL;
16406 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16407 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16408 image_create_info.extent.width = 32;
16409 image_create_info.extent.height = 32;
16410 image_create_info.extent.depth = 1;
16411 image_create_info.mipLevels = 1;
16412 image_create_info.arrayLayers = 1;
16413 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16414 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16415 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16416 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016418 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016419 ASSERT_VK_SUCCESS(err);
16420
Karl Schultzbdb75952016-04-19 11:36:49 -060016421 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16422
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016423 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016424 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016425 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016426 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016427
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016428 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016429 ASSERT_VK_SUCCESS(err);
16430
16431 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016432 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016433 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16434 memAlloc.pNext = NULL;
16435 memAlloc.allocationSize = 0;
16436 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016437
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016438 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016439 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016440 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016441 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016442 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016443 ASSERT_VK_SUCCESS(err);
16444
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016445 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016446 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016447 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016448 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016449 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016450 ASSERT_VK_SUCCESS(err);
16451
16452 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16453 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016454 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016455 ASSERT_VK_SUCCESS(err);
16456
Tony Barbour552f6c02016-12-21 14:34:07 -070016457 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016458 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016459 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016460 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016461 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016462 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016463 copyRegion.srcOffset.x = 0;
16464 copyRegion.srcOffset.y = 0;
16465 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016466 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016467 copyRegion.dstSubresource.mipLevel = 0;
16468 copyRegion.dstSubresource.baseArrayLayer = 0;
16469 copyRegion.dstSubresource.layerCount = 0;
16470 copyRegion.dstOffset.x = 0;
16471 copyRegion.dstOffset.y = 0;
16472 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016473 copyRegion.extent.width = 1;
16474 copyRegion.extent.height = 1;
16475 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016476 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016477 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016478
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016479 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016480
Chia-I Wuf7458c52015-10-26 21:10:41 +080016481 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016482 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016483 vkFreeMemory(m_device->device(), srcMem, NULL);
16484 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016485}
16486
Karl Schultz6addd812016-02-02 17:17:23 -070016487TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16488 VkResult err;
16489 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016490
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16492 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016493
Mike Stroyana3082432015-09-25 13:39:21 -060016494 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016495
16496 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016497 VkImage srcImage;
16498 VkImage dstImage;
16499 VkDeviceMemory srcMem;
16500 VkDeviceMemory destMem;
16501 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016502
16503 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016504 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16505 image_create_info.pNext = NULL;
16506 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16507 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16508 image_create_info.extent.width = 32;
16509 image_create_info.extent.height = 1;
16510 image_create_info.extent.depth = 1;
16511 image_create_info.mipLevels = 1;
16512 image_create_info.arrayLayers = 1;
16513 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16514 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16515 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16516 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016518 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016519 ASSERT_VK_SUCCESS(err);
16520
Karl Schultz6addd812016-02-02 17:17:23 -070016521 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016523 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016524 ASSERT_VK_SUCCESS(err);
16525
16526 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016527 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016528 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16529 memAlloc.pNext = NULL;
16530 memAlloc.allocationSize = 0;
16531 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016532
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016533 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016534 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016535 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016536 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016537 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016538 ASSERT_VK_SUCCESS(err);
16539
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016540 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016541 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016542 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016543 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016544 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016545 ASSERT_VK_SUCCESS(err);
16546
16547 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16548 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016549 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016550 ASSERT_VK_SUCCESS(err);
16551
Tony Barbour552f6c02016-12-21 14:34:07 -070016552 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016553 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016554 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16555 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016556 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016557 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016558 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016559 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016560 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016561 resolveRegion.srcOffset.x = 0;
16562 resolveRegion.srcOffset.y = 0;
16563 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016564 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016565 resolveRegion.dstSubresource.mipLevel = 0;
16566 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016567 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016568 resolveRegion.dstOffset.x = 0;
16569 resolveRegion.dstOffset.y = 0;
16570 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016571 resolveRegion.extent.width = 1;
16572 resolveRegion.extent.height = 1;
16573 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016574 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016575 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016576
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016577 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016578
Chia-I Wuf7458c52015-10-26 21:10:41 +080016579 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016580 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016581 vkFreeMemory(m_device->device(), srcMem, NULL);
16582 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016583}
16584
Karl Schultz6addd812016-02-02 17:17:23 -070016585TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16586 VkResult err;
16587 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16590 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016591
Mike Stroyana3082432015-09-25 13:39:21 -060016592 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016593
Chris Forbesa7530692016-05-08 12:35:39 +120016594 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016595 VkImage srcImage;
16596 VkImage dstImage;
16597 VkDeviceMemory srcMem;
16598 VkDeviceMemory destMem;
16599 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016600
16601 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016602 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16603 image_create_info.pNext = NULL;
16604 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16605 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16606 image_create_info.extent.width = 32;
16607 image_create_info.extent.height = 1;
16608 image_create_info.extent.depth = 1;
16609 image_create_info.mipLevels = 1;
16610 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016611 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016612 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16613 // Note: Some implementations expect color attachment usage for any
16614 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016615 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016616 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016617
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016618 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016619 ASSERT_VK_SUCCESS(err);
16620
Karl Schultz6addd812016-02-02 17:17:23 -070016621 // Note: Some implementations expect color attachment usage for any
16622 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016623 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016625 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016626 ASSERT_VK_SUCCESS(err);
16627
16628 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016629 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016630 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16631 memAlloc.pNext = NULL;
16632 memAlloc.allocationSize = 0;
16633 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016634
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016635 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016636 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016637 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016638 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016639 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016640 ASSERT_VK_SUCCESS(err);
16641
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016642 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016643 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016644 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016645 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016646 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016647 ASSERT_VK_SUCCESS(err);
16648
16649 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16650 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016651 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016652 ASSERT_VK_SUCCESS(err);
16653
Tony Barbour552f6c02016-12-21 14:34:07 -070016654 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016655 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016656 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16657 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016658 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016659 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016660 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016661 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016662 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016663 resolveRegion.srcOffset.x = 0;
16664 resolveRegion.srcOffset.y = 0;
16665 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016666 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016667 resolveRegion.dstSubresource.mipLevel = 0;
16668 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016669 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016670 resolveRegion.dstOffset.x = 0;
16671 resolveRegion.dstOffset.y = 0;
16672 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016673 resolveRegion.extent.width = 1;
16674 resolveRegion.extent.height = 1;
16675 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016676 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016677 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016678
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016679 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016680
Chia-I Wuf7458c52015-10-26 21:10:41 +080016681 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016682 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016683 vkFreeMemory(m_device->device(), srcMem, NULL);
16684 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016685}
16686
Karl Schultz6addd812016-02-02 17:17:23 -070016687TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16688 VkResult err;
16689 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016690
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016692 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016693
Mike Stroyana3082432015-09-25 13:39:21 -060016694 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016695
16696 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016697 VkImage srcImage;
16698 VkImage dstImage;
16699 VkDeviceMemory srcMem;
16700 VkDeviceMemory destMem;
16701 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016702
16703 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016704 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16705 image_create_info.pNext = NULL;
16706 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16707 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16708 image_create_info.extent.width = 32;
16709 image_create_info.extent.height = 1;
16710 image_create_info.extent.depth = 1;
16711 image_create_info.mipLevels = 1;
16712 image_create_info.arrayLayers = 1;
16713 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16714 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16715 // Note: Some implementations expect color attachment usage for any
16716 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016717 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016718 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016719
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016720 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016721 ASSERT_VK_SUCCESS(err);
16722
Karl Schultz6addd812016-02-02 17:17:23 -070016723 // Set format to something other than source image
16724 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16725 // Note: Some implementations expect color attachment usage for any
16726 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016727 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016728 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016729
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016730 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016731 ASSERT_VK_SUCCESS(err);
16732
16733 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016734 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016735 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16736 memAlloc.pNext = NULL;
16737 memAlloc.allocationSize = 0;
16738 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016739
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016740 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016741 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016742 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016743 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016744 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016745 ASSERT_VK_SUCCESS(err);
16746
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016747 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016748 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016749 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016750 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016751 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016752 ASSERT_VK_SUCCESS(err);
16753
16754 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16755 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016756 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016757 ASSERT_VK_SUCCESS(err);
16758
Tony Barbour552f6c02016-12-21 14:34:07 -070016759 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016760 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016761 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16762 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016763 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016764 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016765 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016766 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016767 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016768 resolveRegion.srcOffset.x = 0;
16769 resolveRegion.srcOffset.y = 0;
16770 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016771 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016772 resolveRegion.dstSubresource.mipLevel = 0;
16773 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016774 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016775 resolveRegion.dstOffset.x = 0;
16776 resolveRegion.dstOffset.y = 0;
16777 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016778 resolveRegion.extent.width = 1;
16779 resolveRegion.extent.height = 1;
16780 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016781 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016782 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016783
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016784 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016785
Chia-I Wuf7458c52015-10-26 21:10:41 +080016786 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016787 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016788 vkFreeMemory(m_device->device(), srcMem, NULL);
16789 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016790}
16791
Karl Schultz6addd812016-02-02 17:17:23 -070016792TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16793 VkResult err;
16794 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016795
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016797 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016798
Mike Stroyana3082432015-09-25 13:39:21 -060016799 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016800
16801 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016802 VkImage srcImage;
16803 VkImage dstImage;
16804 VkDeviceMemory srcMem;
16805 VkDeviceMemory destMem;
16806 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016807
16808 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016809 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16810 image_create_info.pNext = NULL;
16811 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16812 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16813 image_create_info.extent.width = 32;
16814 image_create_info.extent.height = 1;
16815 image_create_info.extent.depth = 1;
16816 image_create_info.mipLevels = 1;
16817 image_create_info.arrayLayers = 1;
16818 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16819 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16820 // Note: Some implementations expect color attachment usage for any
16821 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016822 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016823 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016825 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016826 ASSERT_VK_SUCCESS(err);
16827
Karl Schultz6addd812016-02-02 17:17:23 -070016828 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16829 // Note: Some implementations expect color attachment usage for any
16830 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016831 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016832 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016834 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016835 ASSERT_VK_SUCCESS(err);
16836
16837 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016838 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016839 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16840 memAlloc.pNext = NULL;
16841 memAlloc.allocationSize = 0;
16842 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016843
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016844 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016845 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016846 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016847 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016848 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016849 ASSERT_VK_SUCCESS(err);
16850
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016851 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016852 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016853 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016854 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016855 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016856 ASSERT_VK_SUCCESS(err);
16857
16858 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16859 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016860 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016861 ASSERT_VK_SUCCESS(err);
16862
Tony Barbour552f6c02016-12-21 14:34:07 -070016863 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016864 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016865 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16866 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016867 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016868 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016869 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016870 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016871 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016872 resolveRegion.srcOffset.x = 0;
16873 resolveRegion.srcOffset.y = 0;
16874 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016875 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016876 resolveRegion.dstSubresource.mipLevel = 0;
16877 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016878 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016879 resolveRegion.dstOffset.x = 0;
16880 resolveRegion.dstOffset.y = 0;
16881 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016882 resolveRegion.extent.width = 1;
16883 resolveRegion.extent.height = 1;
16884 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016885 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016886 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016887
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016888 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016889
Chia-I Wuf7458c52015-10-26 21:10:41 +080016890 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016891 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016892 vkFreeMemory(m_device->device(), srcMem, NULL);
16893 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016894}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016895
Karl Schultz6addd812016-02-02 17:17:23 -070016896TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016897 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016898 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16899 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016900 // The image format check comes 2nd in validation so we trigger it first,
16901 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016902 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16905 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016906
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016907 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016908
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016909 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016910 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16911 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016912
16913 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016914 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16915 ds_pool_ci.pNext = NULL;
16916 ds_pool_ci.maxSets = 1;
16917 ds_pool_ci.poolSizeCount = 1;
16918 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016919
16920 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016921 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016922 ASSERT_VK_SUCCESS(err);
16923
16924 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016925 dsl_binding.binding = 0;
16926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16927 dsl_binding.descriptorCount = 1;
16928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16929 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016930
16931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16933 ds_layout_ci.pNext = NULL;
16934 ds_layout_ci.bindingCount = 1;
16935 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016936 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016938 ASSERT_VK_SUCCESS(err);
16939
16940 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016941 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016942 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016943 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016944 alloc_info.descriptorPool = ds_pool;
16945 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016946 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016947 ASSERT_VK_SUCCESS(err);
16948
Karl Schultz6addd812016-02-02 17:17:23 -070016949 VkImage image_bad;
16950 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016951 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016952 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016953 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016954 const int32_t tex_width = 32;
16955 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016956
16957 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016958 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16959 image_create_info.pNext = NULL;
16960 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16961 image_create_info.format = tex_format_bad;
16962 image_create_info.extent.width = tex_width;
16963 image_create_info.extent.height = tex_height;
16964 image_create_info.extent.depth = 1;
16965 image_create_info.mipLevels = 1;
16966 image_create_info.arrayLayers = 1;
16967 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16968 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016969 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016970 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016972 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016973 ASSERT_VK_SUCCESS(err);
16974 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016975 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16976 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016977 ASSERT_VK_SUCCESS(err);
16978
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016979 // ---Bind image memory---
16980 VkMemoryRequirements img_mem_reqs;
16981 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
16982 VkMemoryAllocateInfo image_alloc_info = {};
16983 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16984 image_alloc_info.pNext = NULL;
16985 image_alloc_info.memoryTypeIndex = 0;
16986 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016987 bool pass =
16988 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 -070016989 ASSERT_TRUE(pass);
16990 VkDeviceMemory mem;
16991 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
16992 ASSERT_VK_SUCCESS(err);
16993 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
16994 ASSERT_VK_SUCCESS(err);
16995 // -----------------------
16996
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016997 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016998 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016999 image_view_create_info.image = image_bad;
17000 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17001 image_view_create_info.format = tex_format_bad;
17002 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17003 image_view_create_info.subresourceRange.baseMipLevel = 0;
17004 image_view_create_info.subresourceRange.layerCount = 1;
17005 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017006 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017007
17008 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017009 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017010
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017011 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017012
Chia-I Wuf7458c52015-10-26 21:10:41 +080017013 vkDestroyImage(m_device->device(), image_bad, NULL);
17014 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017015 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17016 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017017
17018 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017019}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017020
17021TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017022 TEST_DESCRIPTION(
17023 "Call ClearColorImage w/ a depth|stencil image and "
17024 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017025
17026 ASSERT_NO_FATAL_FAILURE(InitState());
17027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17028
Tony Barbour552f6c02016-12-21 14:34:07 -070017029 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017030
17031 // Color image
17032 VkClearColorValue clear_color;
17033 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17034 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17035 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17036 const int32_t img_width = 32;
17037 const int32_t img_height = 32;
17038 VkImageCreateInfo image_create_info = {};
17039 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17040 image_create_info.pNext = NULL;
17041 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17042 image_create_info.format = color_format;
17043 image_create_info.extent.width = img_width;
17044 image_create_info.extent.height = img_height;
17045 image_create_info.extent.depth = 1;
17046 image_create_info.mipLevels = 1;
17047 image_create_info.arrayLayers = 1;
17048 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17049 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17050 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17051
17052 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017053 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017054
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017055 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017056
17057 // Depth/Stencil image
17058 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017059 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017060 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17061 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17062 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17063 ds_image_create_info.extent.width = 64;
17064 ds_image_create_info.extent.height = 64;
17065 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017066 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 -060017067
17068 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017069 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017071 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 -060017072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017075 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017076 &color_range);
17077
17078 m_errorMonitor->VerifyFound();
17079
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17081 "vkCmdClearColorImage called with "
17082 "image created without "
17083 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017084
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017085 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017086 &color_range);
17087
17088 m_errorMonitor->VerifyFound();
17089
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017090 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17092 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017093
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017094 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17095 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017096
17097 m_errorMonitor->VerifyFound();
17098}
Tobin Ehliscde08892015-09-22 10:11:37 -060017099
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017100// WSI Enabled Tests
17101//
Chris Forbes09368e42016-10-13 11:59:22 +130017102#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017103TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17104
17105#if defined(VK_USE_PLATFORM_XCB_KHR)
17106 VkSurfaceKHR surface = VK_NULL_HANDLE;
17107
17108 VkResult err;
17109 bool pass;
17110 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17111 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17112 // uint32_t swapchain_image_count = 0;
17113 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17114 // uint32_t image_index = 0;
17115 // VkPresentInfoKHR present_info = {};
17116
17117 ASSERT_NO_FATAL_FAILURE(InitState());
17118
17119 // Use the create function from one of the VK_KHR_*_surface extension in
17120 // order to create a surface, testing all known errors in the process,
17121 // before successfully creating a surface:
17122 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17124 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17125 pass = (err != VK_SUCCESS);
17126 ASSERT_TRUE(pass);
17127 m_errorMonitor->VerifyFound();
17128
17129 // Next, try to create a surface with the wrong
17130 // VkXcbSurfaceCreateInfoKHR::sType:
17131 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17132 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17134 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17135 pass = (err != VK_SUCCESS);
17136 ASSERT_TRUE(pass);
17137 m_errorMonitor->VerifyFound();
17138
17139 // Create a native window, and then correctly create a surface:
17140 xcb_connection_t *connection;
17141 xcb_screen_t *screen;
17142 xcb_window_t xcb_window;
17143 xcb_intern_atom_reply_t *atom_wm_delete_window;
17144
17145 const xcb_setup_t *setup;
17146 xcb_screen_iterator_t iter;
17147 int scr;
17148 uint32_t value_mask, value_list[32];
17149 int width = 1;
17150 int height = 1;
17151
17152 connection = xcb_connect(NULL, &scr);
17153 ASSERT_TRUE(connection != NULL);
17154 setup = xcb_get_setup(connection);
17155 iter = xcb_setup_roots_iterator(setup);
17156 while (scr-- > 0)
17157 xcb_screen_next(&iter);
17158 screen = iter.data;
17159
17160 xcb_window = xcb_generate_id(connection);
17161
17162 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17163 value_list[0] = screen->black_pixel;
17164 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17165
17166 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17167 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17168
17169 /* Magic code that will send notification when window is destroyed */
17170 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17171 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17172
17173 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17174 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17175 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17176 free(reply);
17177
17178 xcb_map_window(connection, xcb_window);
17179
17180 // Force the x/y coordinates to 100,100 results are identical in consecutive
17181 // runs
17182 const uint32_t coords[] = { 100, 100 };
17183 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17184
17185 // Finally, try to correctly create a surface:
17186 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17187 xcb_create_info.pNext = NULL;
17188 xcb_create_info.flags = 0;
17189 xcb_create_info.connection = connection;
17190 xcb_create_info.window = xcb_window;
17191 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17192 pass = (err == VK_SUCCESS);
17193 ASSERT_TRUE(pass);
17194
17195 // Check if surface supports presentation:
17196
17197 // 1st, do so without having queried the queue families:
17198 VkBool32 supported = false;
17199 // TODO: Get the following error to come out:
17200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17201 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17202 "function");
17203 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17204 pass = (err != VK_SUCCESS);
17205 // ASSERT_TRUE(pass);
17206 // m_errorMonitor->VerifyFound();
17207
17208 // Next, query a queue family index that's too large:
17209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17210 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17211 pass = (err != VK_SUCCESS);
17212 ASSERT_TRUE(pass);
17213 m_errorMonitor->VerifyFound();
17214
17215 // Finally, do so correctly:
17216 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17217 // SUPPORTED
17218 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17219 pass = (err == VK_SUCCESS);
17220 ASSERT_TRUE(pass);
17221
17222 // Before proceeding, try to create a swapchain without having called
17223 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17224 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17225 swapchain_create_info.pNext = NULL;
17226 swapchain_create_info.flags = 0;
17227 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17228 swapchain_create_info.surface = surface;
17229 swapchain_create_info.imageArrayLayers = 1;
17230 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17231 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17233 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17234 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17235 pass = (err != VK_SUCCESS);
17236 ASSERT_TRUE(pass);
17237 m_errorMonitor->VerifyFound();
17238
17239 // Get the surface capabilities:
17240 VkSurfaceCapabilitiesKHR surface_capabilities;
17241
17242 // Do so correctly (only error logged by this entrypoint is if the
17243 // extension isn't enabled):
17244 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17245 pass = (err == VK_SUCCESS);
17246 ASSERT_TRUE(pass);
17247
17248 // Get the surface formats:
17249 uint32_t surface_format_count;
17250
17251 // First, try without a pointer to surface_format_count:
17252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17253 "specified as NULL");
17254 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17255 pass = (err == VK_SUCCESS);
17256 ASSERT_TRUE(pass);
17257 m_errorMonitor->VerifyFound();
17258
17259 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17260 // correctly done a 1st try (to get the count):
17261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17262 surface_format_count = 0;
17263 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17264 pass = (err == VK_SUCCESS);
17265 ASSERT_TRUE(pass);
17266 m_errorMonitor->VerifyFound();
17267
17268 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17269 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17270 pass = (err == VK_SUCCESS);
17271 ASSERT_TRUE(pass);
17272
17273 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17274 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17275
17276 // Next, do a 2nd try with surface_format_count being set too high:
17277 surface_format_count += 5;
17278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17279 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17280 pass = (err == VK_SUCCESS);
17281 ASSERT_TRUE(pass);
17282 m_errorMonitor->VerifyFound();
17283
17284 // Finally, do a correct 1st and 2nd try:
17285 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17286 pass = (err == VK_SUCCESS);
17287 ASSERT_TRUE(pass);
17288 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17289 pass = (err == VK_SUCCESS);
17290 ASSERT_TRUE(pass);
17291
17292 // Get the surface present modes:
17293 uint32_t surface_present_mode_count;
17294
17295 // First, try without a pointer to surface_format_count:
17296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17297 "specified as NULL");
17298
17299 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17300 pass = (err == VK_SUCCESS);
17301 ASSERT_TRUE(pass);
17302 m_errorMonitor->VerifyFound();
17303
17304 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17305 // correctly done a 1st try (to get the count):
17306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17307 surface_present_mode_count = 0;
17308 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17309 (VkPresentModeKHR *)&surface_present_mode_count);
17310 pass = (err == VK_SUCCESS);
17311 ASSERT_TRUE(pass);
17312 m_errorMonitor->VerifyFound();
17313
17314 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17315 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17316 pass = (err == VK_SUCCESS);
17317 ASSERT_TRUE(pass);
17318
17319 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17320 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17321
17322 // Next, do a 2nd try with surface_format_count being set too high:
17323 surface_present_mode_count += 5;
17324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17325 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17326 pass = (err == VK_SUCCESS);
17327 ASSERT_TRUE(pass);
17328 m_errorMonitor->VerifyFound();
17329
17330 // Finally, do a correct 1st and 2nd try:
17331 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17332 pass = (err == VK_SUCCESS);
17333 ASSERT_TRUE(pass);
17334 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17335 pass = (err == VK_SUCCESS);
17336 ASSERT_TRUE(pass);
17337
17338 // Create a swapchain:
17339
17340 // First, try without a pointer to swapchain_create_info:
17341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17342 "specified as NULL");
17343
17344 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17345 pass = (err != VK_SUCCESS);
17346 ASSERT_TRUE(pass);
17347 m_errorMonitor->VerifyFound();
17348
17349 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17350 // sType:
17351 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17353
17354 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17355 pass = (err != VK_SUCCESS);
17356 ASSERT_TRUE(pass);
17357 m_errorMonitor->VerifyFound();
17358
17359 // Next, call with a NULL swapchain pointer:
17360 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17361 swapchain_create_info.pNext = NULL;
17362 swapchain_create_info.flags = 0;
17363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17364 "specified as NULL");
17365
17366 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17367 pass = (err != VK_SUCCESS);
17368 ASSERT_TRUE(pass);
17369 m_errorMonitor->VerifyFound();
17370
17371 // TODO: Enhance swapchain layer so that
17372 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17373
17374 // Next, call with a queue family index that's too large:
17375 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17376 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17377 swapchain_create_info.queueFamilyIndexCount = 2;
17378 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17380 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17381 pass = (err != VK_SUCCESS);
17382 ASSERT_TRUE(pass);
17383 m_errorMonitor->VerifyFound();
17384
17385 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17386 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17387 swapchain_create_info.queueFamilyIndexCount = 1;
17388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17389 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17390 "pCreateInfo->pQueueFamilyIndices).");
17391 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17392 pass = (err != VK_SUCCESS);
17393 ASSERT_TRUE(pass);
17394 m_errorMonitor->VerifyFound();
17395
17396 // Next, call with an invalid imageSharingMode:
17397 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17398 swapchain_create_info.queueFamilyIndexCount = 1;
17399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17400 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17401 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17402 pass = (err != VK_SUCCESS);
17403 ASSERT_TRUE(pass);
17404 m_errorMonitor->VerifyFound();
17405 // Fix for the future:
17406 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17407 // SUPPORTED
17408 swapchain_create_info.queueFamilyIndexCount = 0;
17409 queueFamilyIndex[0] = 0;
17410 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17411
17412 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17413 // Get the images from a swapchain:
17414 // Acquire an image from a swapchain:
17415 // Present an image to a swapchain:
17416 // Destroy the swapchain:
17417
17418 // TODOs:
17419 //
17420 // - Try destroying the device without first destroying the swapchain
17421 //
17422 // - Try destroying the device without first destroying the surface
17423 //
17424 // - Try destroying the surface without first destroying the swapchain
17425
17426 // Destroy the surface:
17427 vkDestroySurfaceKHR(instance(), surface, NULL);
17428
17429 // Tear down the window:
17430 xcb_destroy_window(connection, xcb_window);
17431 xcb_disconnect(connection);
17432
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017433#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017434 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017435#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017436}
Chris Forbes09368e42016-10-13 11:59:22 +130017437#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017438
17439//
17440// POSITIVE VALIDATION TESTS
17441//
17442// These tests do not expect to encounter ANY validation errors pass only if this is true
17443
Tobin Ehlise0006882016-11-03 10:14:28 -060017444TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017445 TEST_DESCRIPTION(
17446 "Perform an image layout transition in a secondary command buffer followed "
17447 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017448 VkResult err;
17449 m_errorMonitor->ExpectSuccess();
17450 ASSERT_NO_FATAL_FAILURE(InitState());
17451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17452 // Allocate a secondary and primary cmd buffer
17453 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17454 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17455 command_buffer_allocate_info.commandPool = m_commandPool;
17456 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17457 command_buffer_allocate_info.commandBufferCount = 1;
17458
17459 VkCommandBuffer secondary_command_buffer;
17460 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17461 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17462 VkCommandBuffer primary_command_buffer;
17463 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17464 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17465 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17466 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17467 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17468 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17469 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17470
17471 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17472 ASSERT_VK_SUCCESS(err);
17473 VkImageObj image(m_device);
17474 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17475 ASSERT_TRUE(image.initialized());
17476 VkImageMemoryBarrier img_barrier = {};
17477 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17478 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17479 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17480 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17481 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17482 img_barrier.image = image.handle();
17483 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17484 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17485 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17486 img_barrier.subresourceRange.baseArrayLayer = 0;
17487 img_barrier.subresourceRange.baseMipLevel = 0;
17488 img_barrier.subresourceRange.layerCount = 1;
17489 img_barrier.subresourceRange.levelCount = 1;
17490 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17491 0, nullptr, 1, &img_barrier);
17492 err = vkEndCommandBuffer(secondary_command_buffer);
17493 ASSERT_VK_SUCCESS(err);
17494
17495 // Now update primary cmd buffer to execute secondary and transitions image
17496 command_buffer_begin_info.pInheritanceInfo = nullptr;
17497 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17498 ASSERT_VK_SUCCESS(err);
17499 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17500 VkImageMemoryBarrier img_barrier2 = {};
17501 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17502 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17503 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17504 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17505 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17506 img_barrier2.image = image.handle();
17507 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17508 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17509 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17510 img_barrier2.subresourceRange.baseArrayLayer = 0;
17511 img_barrier2.subresourceRange.baseMipLevel = 0;
17512 img_barrier2.subresourceRange.layerCount = 1;
17513 img_barrier2.subresourceRange.levelCount = 1;
17514 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17515 nullptr, 1, &img_barrier2);
17516 err = vkEndCommandBuffer(primary_command_buffer);
17517 ASSERT_VK_SUCCESS(err);
17518 VkSubmitInfo submit_info = {};
17519 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17520 submit_info.commandBufferCount = 1;
17521 submit_info.pCommandBuffers = &primary_command_buffer;
17522 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17523 ASSERT_VK_SUCCESS(err);
17524 m_errorMonitor->VerifyNotFound();
17525 err = vkDeviceWaitIdle(m_device->device());
17526 ASSERT_VK_SUCCESS(err);
17527 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17528 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17529}
17530
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017531// This is a positive test. No failures are expected.
17532TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017533 TEST_DESCRIPTION(
17534 "Ensure that the vkUpdateDescriptorSets validation code "
17535 "is ignoring VkWriteDescriptorSet members that are not "
17536 "related to the descriptor type specified by "
17537 "VkWriteDescriptorSet::descriptorType. Correct "
17538 "validation behavior will result in the test running to "
17539 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017540
17541 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17542
17543 ASSERT_NO_FATAL_FAILURE(InitState());
17544
17545 // Image Case
17546 {
17547 m_errorMonitor->ExpectSuccess();
17548
17549 VkImage image;
17550 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17551 const int32_t tex_width = 32;
17552 const int32_t tex_height = 32;
17553 VkImageCreateInfo image_create_info = {};
17554 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17555 image_create_info.pNext = NULL;
17556 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17557 image_create_info.format = tex_format;
17558 image_create_info.extent.width = tex_width;
17559 image_create_info.extent.height = tex_height;
17560 image_create_info.extent.depth = 1;
17561 image_create_info.mipLevels = 1;
17562 image_create_info.arrayLayers = 1;
17563 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17564 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17565 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17566 image_create_info.flags = 0;
17567 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17568 ASSERT_VK_SUCCESS(err);
17569
17570 VkMemoryRequirements memory_reqs;
17571 VkDeviceMemory image_memory;
17572 bool pass;
17573 VkMemoryAllocateInfo memory_info = {};
17574 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17575 memory_info.pNext = NULL;
17576 memory_info.allocationSize = 0;
17577 memory_info.memoryTypeIndex = 0;
17578 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17579 memory_info.allocationSize = memory_reqs.size;
17580 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17581 ASSERT_TRUE(pass);
17582 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17583 ASSERT_VK_SUCCESS(err);
17584 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17585 ASSERT_VK_SUCCESS(err);
17586
17587 VkImageViewCreateInfo image_view_create_info = {};
17588 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17589 image_view_create_info.image = image;
17590 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17591 image_view_create_info.format = tex_format;
17592 image_view_create_info.subresourceRange.layerCount = 1;
17593 image_view_create_info.subresourceRange.baseMipLevel = 0;
17594 image_view_create_info.subresourceRange.levelCount = 1;
17595 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17596
17597 VkImageView view;
17598 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17599 ASSERT_VK_SUCCESS(err);
17600
17601 VkDescriptorPoolSize ds_type_count = {};
17602 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17603 ds_type_count.descriptorCount = 1;
17604
17605 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17606 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17607 ds_pool_ci.pNext = NULL;
17608 ds_pool_ci.maxSets = 1;
17609 ds_pool_ci.poolSizeCount = 1;
17610 ds_pool_ci.pPoolSizes = &ds_type_count;
17611
17612 VkDescriptorPool ds_pool;
17613 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17614 ASSERT_VK_SUCCESS(err);
17615
17616 VkDescriptorSetLayoutBinding dsl_binding = {};
17617 dsl_binding.binding = 0;
17618 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17619 dsl_binding.descriptorCount = 1;
17620 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17621 dsl_binding.pImmutableSamplers = NULL;
17622
17623 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17624 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17625 ds_layout_ci.pNext = NULL;
17626 ds_layout_ci.bindingCount = 1;
17627 ds_layout_ci.pBindings = &dsl_binding;
17628 VkDescriptorSetLayout ds_layout;
17629 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17630 ASSERT_VK_SUCCESS(err);
17631
17632 VkDescriptorSet descriptor_set;
17633 VkDescriptorSetAllocateInfo alloc_info = {};
17634 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17635 alloc_info.descriptorSetCount = 1;
17636 alloc_info.descriptorPool = ds_pool;
17637 alloc_info.pSetLayouts = &ds_layout;
17638 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17639 ASSERT_VK_SUCCESS(err);
17640
17641 VkDescriptorImageInfo image_info = {};
17642 image_info.imageView = view;
17643 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17644
17645 VkWriteDescriptorSet descriptor_write;
17646 memset(&descriptor_write, 0, sizeof(descriptor_write));
17647 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17648 descriptor_write.dstSet = descriptor_set;
17649 descriptor_write.dstBinding = 0;
17650 descriptor_write.descriptorCount = 1;
17651 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17652 descriptor_write.pImageInfo = &image_info;
17653
17654 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17655 // be
17656 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17657 // This will most likely produce a crash if the parameter_validation
17658 // layer
17659 // does not correctly ignore pBufferInfo.
17660 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17661 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17662
17663 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17664
17665 m_errorMonitor->VerifyNotFound();
17666
17667 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17668 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17669 vkDestroyImageView(m_device->device(), view, NULL);
17670 vkDestroyImage(m_device->device(), image, NULL);
17671 vkFreeMemory(m_device->device(), image_memory, NULL);
17672 }
17673
17674 // Buffer Case
17675 {
17676 m_errorMonitor->ExpectSuccess();
17677
17678 VkBuffer buffer;
17679 uint32_t queue_family_index = 0;
17680 VkBufferCreateInfo buffer_create_info = {};
17681 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17682 buffer_create_info.size = 1024;
17683 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17684 buffer_create_info.queueFamilyIndexCount = 1;
17685 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17686
17687 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17688 ASSERT_VK_SUCCESS(err);
17689
17690 VkMemoryRequirements memory_reqs;
17691 VkDeviceMemory buffer_memory;
17692 bool pass;
17693 VkMemoryAllocateInfo memory_info = {};
17694 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17695 memory_info.pNext = NULL;
17696 memory_info.allocationSize = 0;
17697 memory_info.memoryTypeIndex = 0;
17698
17699 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17700 memory_info.allocationSize = memory_reqs.size;
17701 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17702 ASSERT_TRUE(pass);
17703
17704 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17705 ASSERT_VK_SUCCESS(err);
17706 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17707 ASSERT_VK_SUCCESS(err);
17708
17709 VkDescriptorPoolSize ds_type_count = {};
17710 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17711 ds_type_count.descriptorCount = 1;
17712
17713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17715 ds_pool_ci.pNext = NULL;
17716 ds_pool_ci.maxSets = 1;
17717 ds_pool_ci.poolSizeCount = 1;
17718 ds_pool_ci.pPoolSizes = &ds_type_count;
17719
17720 VkDescriptorPool ds_pool;
17721 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17722 ASSERT_VK_SUCCESS(err);
17723
17724 VkDescriptorSetLayoutBinding dsl_binding = {};
17725 dsl_binding.binding = 0;
17726 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17727 dsl_binding.descriptorCount = 1;
17728 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17729 dsl_binding.pImmutableSamplers = NULL;
17730
17731 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17732 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17733 ds_layout_ci.pNext = NULL;
17734 ds_layout_ci.bindingCount = 1;
17735 ds_layout_ci.pBindings = &dsl_binding;
17736 VkDescriptorSetLayout ds_layout;
17737 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17738 ASSERT_VK_SUCCESS(err);
17739
17740 VkDescriptorSet descriptor_set;
17741 VkDescriptorSetAllocateInfo alloc_info = {};
17742 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17743 alloc_info.descriptorSetCount = 1;
17744 alloc_info.descriptorPool = ds_pool;
17745 alloc_info.pSetLayouts = &ds_layout;
17746 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17747 ASSERT_VK_SUCCESS(err);
17748
17749 VkDescriptorBufferInfo buffer_info = {};
17750 buffer_info.buffer = buffer;
17751 buffer_info.offset = 0;
17752 buffer_info.range = 1024;
17753
17754 VkWriteDescriptorSet descriptor_write;
17755 memset(&descriptor_write, 0, sizeof(descriptor_write));
17756 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17757 descriptor_write.dstSet = descriptor_set;
17758 descriptor_write.dstBinding = 0;
17759 descriptor_write.descriptorCount = 1;
17760 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17761 descriptor_write.pBufferInfo = &buffer_info;
17762
17763 // Set pImageInfo and pTexelBufferView to invalid values, which should
17764 // be
17765 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
17766 // This will most likely produce a crash if the parameter_validation
17767 // layer
17768 // does not correctly ignore pImageInfo.
17769 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17770 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17771
17772 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17773
17774 m_errorMonitor->VerifyNotFound();
17775
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17777 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17778 vkDestroyBuffer(m_device->device(), buffer, NULL);
17779 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17780 }
17781
17782 // Texel Buffer Case
17783 {
17784 m_errorMonitor->ExpectSuccess();
17785
17786 VkBuffer buffer;
17787 uint32_t queue_family_index = 0;
17788 VkBufferCreateInfo buffer_create_info = {};
17789 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17790 buffer_create_info.size = 1024;
17791 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
17792 buffer_create_info.queueFamilyIndexCount = 1;
17793 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17794
17795 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17796 ASSERT_VK_SUCCESS(err);
17797
17798 VkMemoryRequirements memory_reqs;
17799 VkDeviceMemory buffer_memory;
17800 bool pass;
17801 VkMemoryAllocateInfo memory_info = {};
17802 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17803 memory_info.pNext = NULL;
17804 memory_info.allocationSize = 0;
17805 memory_info.memoryTypeIndex = 0;
17806
17807 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17808 memory_info.allocationSize = memory_reqs.size;
17809 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17810 ASSERT_TRUE(pass);
17811
17812 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17813 ASSERT_VK_SUCCESS(err);
17814 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17815 ASSERT_VK_SUCCESS(err);
17816
17817 VkBufferViewCreateInfo buff_view_ci = {};
17818 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
17819 buff_view_ci.buffer = buffer;
17820 buff_view_ci.format = VK_FORMAT_R8_UNORM;
17821 buff_view_ci.range = VK_WHOLE_SIZE;
17822 VkBufferView buffer_view;
17823 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
17824
17825 VkDescriptorPoolSize ds_type_count = {};
17826 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17827 ds_type_count.descriptorCount = 1;
17828
17829 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17830 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17831 ds_pool_ci.pNext = NULL;
17832 ds_pool_ci.maxSets = 1;
17833 ds_pool_ci.poolSizeCount = 1;
17834 ds_pool_ci.pPoolSizes = &ds_type_count;
17835
17836 VkDescriptorPool ds_pool;
17837 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17838 ASSERT_VK_SUCCESS(err);
17839
17840 VkDescriptorSetLayoutBinding dsl_binding = {};
17841 dsl_binding.binding = 0;
17842 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17843 dsl_binding.descriptorCount = 1;
17844 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17845 dsl_binding.pImmutableSamplers = NULL;
17846
17847 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17848 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17849 ds_layout_ci.pNext = NULL;
17850 ds_layout_ci.bindingCount = 1;
17851 ds_layout_ci.pBindings = &dsl_binding;
17852 VkDescriptorSetLayout ds_layout;
17853 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17854 ASSERT_VK_SUCCESS(err);
17855
17856 VkDescriptorSet descriptor_set;
17857 VkDescriptorSetAllocateInfo alloc_info = {};
17858 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17859 alloc_info.descriptorSetCount = 1;
17860 alloc_info.descriptorPool = ds_pool;
17861 alloc_info.pSetLayouts = &ds_layout;
17862 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17863 ASSERT_VK_SUCCESS(err);
17864
17865 VkWriteDescriptorSet descriptor_write;
17866 memset(&descriptor_write, 0, sizeof(descriptor_write));
17867 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17868 descriptor_write.dstSet = descriptor_set;
17869 descriptor_write.dstBinding = 0;
17870 descriptor_write.descriptorCount = 1;
17871 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17872 descriptor_write.pTexelBufferView = &buffer_view;
17873
17874 // Set pImageInfo and pBufferInfo to invalid values, which should be
17875 // ignored for descriptorType ==
17876 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
17877 // This will most likely produce a crash if the parameter_validation
17878 // layer
17879 // does not correctly ignore pImageInfo and pBufferInfo.
17880 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17881 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17882
17883 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17884
17885 m_errorMonitor->VerifyNotFound();
17886
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17889 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
17890 vkDestroyBuffer(m_device->device(), buffer, NULL);
17891 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17892 }
17893}
17894
Tobin Ehlisf7428442016-10-25 07:58:24 -060017895TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
17896 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
17897
17898 ASSERT_NO_FATAL_FAILURE(InitState());
17899 // Create layout where two binding #s are "1"
17900 static const uint32_t NUM_BINDINGS = 3;
17901 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17902 dsl_binding[0].binding = 1;
17903 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17904 dsl_binding[0].descriptorCount = 1;
17905 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17906 dsl_binding[0].pImmutableSamplers = NULL;
17907 dsl_binding[1].binding = 0;
17908 dsl_binding[1].descriptorCount = 1;
17909 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17910 dsl_binding[1].descriptorCount = 1;
17911 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17912 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017913 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060017914 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17915 dsl_binding[2].descriptorCount = 1;
17916 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17917 dsl_binding[2].pImmutableSamplers = NULL;
17918
17919 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17920 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17921 ds_layout_ci.pNext = NULL;
17922 ds_layout_ci.bindingCount = NUM_BINDINGS;
17923 ds_layout_ci.pBindings = dsl_binding;
17924 VkDescriptorSetLayout ds_layout;
17925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
17926 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17927 m_errorMonitor->VerifyFound();
17928}
17929
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017930TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017931 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
17932
17933 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017934
Tony Barbour552f6c02016-12-21 14:34:07 -070017935 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017936
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017937 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
17938
17939 {
17940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
17941 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
17942 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17943 m_errorMonitor->VerifyFound();
17944 }
17945
17946 {
17947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
17948 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
17949 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17950 m_errorMonitor->VerifyFound();
17951 }
17952
17953 {
17954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17955 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
17956 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17957 m_errorMonitor->VerifyFound();
17958 }
17959
17960 {
17961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17962 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
17963 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17964 m_errorMonitor->VerifyFound();
17965 }
17966
17967 {
17968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
17969 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
17970 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17971 m_errorMonitor->VerifyFound();
17972 }
17973
17974 {
17975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
17976 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
17977 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17978 m_errorMonitor->VerifyFound();
17979 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017980
17981 {
17982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17983 VkRect2D scissor = {{-1, 0}, {16, 16}};
17984 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17985 m_errorMonitor->VerifyFound();
17986 }
17987
17988 {
17989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17990 VkRect2D scissor = {{0, -2}, {16, 16}};
17991 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17992 m_errorMonitor->VerifyFound();
17993 }
17994
17995 {
17996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
17997 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17998 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17999 m_errorMonitor->VerifyFound();
18000 }
18001
18002 {
18003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18004 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18005 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18006 m_errorMonitor->VerifyFound();
18007 }
18008
Tony Barbour552f6c02016-12-21 14:34:07 -070018009 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018010}
18011
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018012// This is a positive test. No failures are expected.
18013TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18014 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18015 VkResult err;
18016
18017 ASSERT_NO_FATAL_FAILURE(InitState());
18018 m_errorMonitor->ExpectSuccess();
18019 VkDescriptorPoolSize ds_type_count = {};
18020 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18021 ds_type_count.descriptorCount = 2;
18022
18023 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18024 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18025 ds_pool_ci.pNext = NULL;
18026 ds_pool_ci.maxSets = 1;
18027 ds_pool_ci.poolSizeCount = 1;
18028 ds_pool_ci.pPoolSizes = &ds_type_count;
18029
18030 VkDescriptorPool ds_pool;
18031 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18032 ASSERT_VK_SUCCESS(err);
18033
18034 // Create layout with two uniform buffer descriptors w/ empty binding between them
18035 static const uint32_t NUM_BINDINGS = 3;
18036 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18037 dsl_binding[0].binding = 0;
18038 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18039 dsl_binding[0].descriptorCount = 1;
18040 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18041 dsl_binding[0].pImmutableSamplers = NULL;
18042 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018043 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018044 dsl_binding[2].binding = 2;
18045 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18046 dsl_binding[2].descriptorCount = 1;
18047 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18048 dsl_binding[2].pImmutableSamplers = NULL;
18049
18050 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18051 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18052 ds_layout_ci.pNext = NULL;
18053 ds_layout_ci.bindingCount = NUM_BINDINGS;
18054 ds_layout_ci.pBindings = dsl_binding;
18055 VkDescriptorSetLayout ds_layout;
18056 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18057 ASSERT_VK_SUCCESS(err);
18058
18059 VkDescriptorSet descriptor_set = {};
18060 VkDescriptorSetAllocateInfo alloc_info = {};
18061 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18062 alloc_info.descriptorSetCount = 1;
18063 alloc_info.descriptorPool = ds_pool;
18064 alloc_info.pSetLayouts = &ds_layout;
18065 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18066 ASSERT_VK_SUCCESS(err);
18067
18068 // Create a buffer to be used for update
18069 VkBufferCreateInfo buff_ci = {};
18070 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18071 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18072 buff_ci.size = 256;
18073 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18074 VkBuffer buffer;
18075 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18076 ASSERT_VK_SUCCESS(err);
18077 // Have to bind memory to buffer before descriptor update
18078 VkMemoryAllocateInfo mem_alloc = {};
18079 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18080 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018081 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018082 mem_alloc.memoryTypeIndex = 0;
18083
18084 VkMemoryRequirements mem_reqs;
18085 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18086 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18087 if (!pass) {
18088 vkDestroyBuffer(m_device->device(), buffer, NULL);
18089 return;
18090 }
18091
18092 VkDeviceMemory mem;
18093 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18094 ASSERT_VK_SUCCESS(err);
18095 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18096 ASSERT_VK_SUCCESS(err);
18097
18098 // Only update the descriptor at binding 2
18099 VkDescriptorBufferInfo buff_info = {};
18100 buff_info.buffer = buffer;
18101 buff_info.offset = 0;
18102 buff_info.range = VK_WHOLE_SIZE;
18103 VkWriteDescriptorSet descriptor_write = {};
18104 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18105 descriptor_write.dstBinding = 2;
18106 descriptor_write.descriptorCount = 1;
18107 descriptor_write.pTexelBufferView = nullptr;
18108 descriptor_write.pBufferInfo = &buff_info;
18109 descriptor_write.pImageInfo = nullptr;
18110 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18111 descriptor_write.dstSet = descriptor_set;
18112
18113 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18114
18115 m_errorMonitor->VerifyNotFound();
18116 // Cleanup
18117 vkFreeMemory(m_device->device(), mem, NULL);
18118 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18119 vkDestroyBuffer(m_device->device(), buffer, NULL);
18120 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18121}
18122
18123// This is a positive test. No failures are expected.
18124TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18125 VkResult err;
18126 bool pass;
18127
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018128 TEST_DESCRIPTION(
18129 "Create a buffer, allocate memory, bind memory, destroy "
18130 "the buffer, create an image, and bind the same memory to "
18131 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018132
18133 m_errorMonitor->ExpectSuccess();
18134
18135 ASSERT_NO_FATAL_FAILURE(InitState());
18136
18137 VkBuffer buffer;
18138 VkImage image;
18139 VkDeviceMemory mem;
18140 VkMemoryRequirements mem_reqs;
18141
18142 VkBufferCreateInfo buf_info = {};
18143 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18144 buf_info.pNext = NULL;
18145 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18146 buf_info.size = 256;
18147 buf_info.queueFamilyIndexCount = 0;
18148 buf_info.pQueueFamilyIndices = NULL;
18149 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18150 buf_info.flags = 0;
18151 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18152 ASSERT_VK_SUCCESS(err);
18153
18154 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18155
18156 VkMemoryAllocateInfo alloc_info = {};
18157 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18158 alloc_info.pNext = NULL;
18159 alloc_info.memoryTypeIndex = 0;
18160
18161 // Ensure memory is big enough for both bindings
18162 alloc_info.allocationSize = 0x10000;
18163
18164 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18165 if (!pass) {
18166 vkDestroyBuffer(m_device->device(), buffer, NULL);
18167 return;
18168 }
18169
18170 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18171 ASSERT_VK_SUCCESS(err);
18172
18173 uint8_t *pData;
18174 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18175 ASSERT_VK_SUCCESS(err);
18176
18177 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18178
18179 vkUnmapMemory(m_device->device(), mem);
18180
18181 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18182 ASSERT_VK_SUCCESS(err);
18183
18184 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18185 // memory. In fact, it was never used by the GPU.
18186 // Just be be sure, wait for idle.
18187 vkDestroyBuffer(m_device->device(), buffer, NULL);
18188 vkDeviceWaitIdle(m_device->device());
18189
Tobin Ehlis6a005702016-12-28 15:25:56 -070018190 // Use optimal as some platforms report linear support but then fail image creation
18191 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18192 VkImageFormatProperties image_format_properties;
18193 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18194 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18195 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018196 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018197 vkFreeMemory(m_device->device(), mem, NULL);
18198 return;
18199 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018200 VkImageCreateInfo image_create_info = {};
18201 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18202 image_create_info.pNext = NULL;
18203 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18204 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18205 image_create_info.extent.width = 64;
18206 image_create_info.extent.height = 64;
18207 image_create_info.extent.depth = 1;
18208 image_create_info.mipLevels = 1;
18209 image_create_info.arrayLayers = 1;
18210 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018211 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018212 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18213 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18214 image_create_info.queueFamilyIndexCount = 0;
18215 image_create_info.pQueueFamilyIndices = NULL;
18216 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18217 image_create_info.flags = 0;
18218
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018219 /* Create a mappable image. It will be the texture if linear images are ok
18220 * to be textures or it will be the staging image if they are not.
18221 */
18222 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18223 ASSERT_VK_SUCCESS(err);
18224
18225 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18226
Tobin Ehlis6a005702016-12-28 15:25:56 -070018227 VkMemoryAllocateInfo mem_alloc = {};
18228 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18229 mem_alloc.pNext = NULL;
18230 mem_alloc.allocationSize = 0;
18231 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018232 mem_alloc.allocationSize = mem_reqs.size;
18233
18234 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18235 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018236 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018237 vkDestroyImage(m_device->device(), image, NULL);
18238 return;
18239 }
18240
18241 // VALIDATION FAILURE:
18242 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18243 ASSERT_VK_SUCCESS(err);
18244
18245 m_errorMonitor->VerifyNotFound();
18246
18247 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018248 vkDestroyImage(m_device->device(), image, NULL);
18249}
18250
Tony Barbourab713912017-02-02 14:17:35 -070018251// This is a positive test. No failures are expected.
18252TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18253 VkResult err;
18254
18255 TEST_DESCRIPTION(
18256 "Call all applicable destroy and free routines with NULL"
18257 "handles, expecting no validation errors");
18258
18259 m_errorMonitor->ExpectSuccess();
18260
18261 ASSERT_NO_FATAL_FAILURE(InitState());
18262 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18263 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18264 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18265 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18266 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18267 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18268 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18269 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18270 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18271 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18272 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18273 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18274 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18275 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18276 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18277 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18278 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18279 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18280 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18281 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18282
18283 VkCommandPool command_pool;
18284 VkCommandPoolCreateInfo pool_create_info{};
18285 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18286 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18287 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18288 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18289 VkCommandBuffer command_buffers[3] = {};
18290 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18291 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18292 command_buffer_allocate_info.commandPool = command_pool;
18293 command_buffer_allocate_info.commandBufferCount = 1;
18294 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18295 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18296 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18297 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18298
18299 VkDescriptorPoolSize ds_type_count = {};
18300 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18301 ds_type_count.descriptorCount = 1;
18302
18303 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18304 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18305 ds_pool_ci.pNext = NULL;
18306 ds_pool_ci.maxSets = 1;
18307 ds_pool_ci.poolSizeCount = 1;
18308 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18309 ds_pool_ci.pPoolSizes = &ds_type_count;
18310
18311 VkDescriptorPool ds_pool;
18312 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18313 ASSERT_VK_SUCCESS(err);
18314
18315 VkDescriptorSetLayoutBinding dsl_binding = {};
18316 dsl_binding.binding = 2;
18317 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18318 dsl_binding.descriptorCount = 1;
18319 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18320 dsl_binding.pImmutableSamplers = NULL;
18321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18323 ds_layout_ci.pNext = NULL;
18324 ds_layout_ci.bindingCount = 1;
18325 ds_layout_ci.pBindings = &dsl_binding;
18326 VkDescriptorSetLayout ds_layout;
18327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18328 ASSERT_VK_SUCCESS(err);
18329
18330 VkDescriptorSet descriptor_sets[3] = {};
18331 VkDescriptorSetAllocateInfo alloc_info = {};
18332 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18333 alloc_info.descriptorSetCount = 1;
18334 alloc_info.descriptorPool = ds_pool;
18335 alloc_info.pSetLayouts = &ds_layout;
18336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18337 ASSERT_VK_SUCCESS(err);
18338 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18339 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18340 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18341
18342 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18343
18344 m_errorMonitor->VerifyNotFound();
18345}
18346
Tony Barbour626994c2017-02-08 15:29:37 -070018347TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018348 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018349
18350 m_errorMonitor->ExpectSuccess();
18351
18352 ASSERT_NO_FATAL_FAILURE(InitState());
18353 VkCommandBuffer cmd_bufs[4];
18354 VkCommandBufferAllocateInfo alloc_info;
18355 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18356 alloc_info.pNext = NULL;
18357 alloc_info.commandBufferCount = 4;
18358 alloc_info.commandPool = m_commandPool;
18359 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18360 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18361 VkImageObj image(m_device);
18362 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18363 ASSERT_TRUE(image.initialized());
18364 VkCommandBufferBeginInfo cb_binfo;
18365 cb_binfo.pNext = NULL;
18366 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18367 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18368 cb_binfo.flags = 0;
18369 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18370 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18371 VkImageMemoryBarrier img_barrier = {};
18372 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18373 img_barrier.pNext = NULL;
18374 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18375 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18376 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18377 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18378 img_barrier.image = image.handle();
18379 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18380 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18381 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18382 img_barrier.subresourceRange.baseArrayLayer = 0;
18383 img_barrier.subresourceRange.baseMipLevel = 0;
18384 img_barrier.subresourceRange.layerCount = 1;
18385 img_barrier.subresourceRange.levelCount = 1;
18386 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18387 &img_barrier);
18388 vkEndCommandBuffer(cmd_bufs[0]);
18389 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18390 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18391 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18392 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18393 &img_barrier);
18394 vkEndCommandBuffer(cmd_bufs[1]);
18395 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18396 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18397 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18398 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18399 &img_barrier);
18400 vkEndCommandBuffer(cmd_bufs[2]);
18401 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18402 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18403 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18404 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18405 &img_barrier);
18406 vkEndCommandBuffer(cmd_bufs[3]);
18407
18408 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18409 VkSemaphore semaphore1, semaphore2;
18410 VkSemaphoreCreateInfo semaphore_create_info{};
18411 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18412 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18413 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18414 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18415 VkSubmitInfo submit_info[3];
18416 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18417 submit_info[0].pNext = nullptr;
18418 submit_info[0].commandBufferCount = 1;
18419 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18420 submit_info[0].signalSemaphoreCount = 1;
18421 submit_info[0].pSignalSemaphores = &semaphore1;
18422 submit_info[0].waitSemaphoreCount = 0;
18423 submit_info[0].pWaitDstStageMask = nullptr;
18424 submit_info[0].pWaitDstStageMask = flags;
18425 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18426 submit_info[1].pNext = nullptr;
18427 submit_info[1].commandBufferCount = 1;
18428 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18429 submit_info[1].waitSemaphoreCount = 1;
18430 submit_info[1].pWaitSemaphores = &semaphore1;
18431 submit_info[1].signalSemaphoreCount = 1;
18432 submit_info[1].pSignalSemaphores = &semaphore2;
18433 submit_info[1].pWaitDstStageMask = flags;
18434 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18435 submit_info[2].pNext = nullptr;
18436 submit_info[2].commandBufferCount = 2;
18437 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18438 submit_info[2].waitSemaphoreCount = 1;
18439 submit_info[2].pWaitSemaphores = &semaphore2;
18440 submit_info[2].signalSemaphoreCount = 0;
18441 submit_info[2].pSignalSemaphores = nullptr;
18442 submit_info[2].pWaitDstStageMask = flags;
18443 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18444 vkQueueWaitIdle(m_device->m_queue);
18445
18446 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18447 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18448 m_errorMonitor->VerifyNotFound();
18449}
18450
Tobin Ehlis953e8392016-11-17 10:54:13 -070018451TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18452 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18453 // We previously had a bug where dynamic offset of inactive bindings was still being used
18454 VkResult err;
18455 m_errorMonitor->ExpectSuccess();
18456
18457 ASSERT_NO_FATAL_FAILURE(InitState());
18458 ASSERT_NO_FATAL_FAILURE(InitViewport());
18459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18460
18461 VkDescriptorPoolSize ds_type_count = {};
18462 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18463 ds_type_count.descriptorCount = 3;
18464
18465 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18466 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18467 ds_pool_ci.pNext = NULL;
18468 ds_pool_ci.maxSets = 1;
18469 ds_pool_ci.poolSizeCount = 1;
18470 ds_pool_ci.pPoolSizes = &ds_type_count;
18471
18472 VkDescriptorPool ds_pool;
18473 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18474 ASSERT_VK_SUCCESS(err);
18475
18476 const uint32_t BINDING_COUNT = 3;
18477 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018478 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018479 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18480 dsl_binding[0].descriptorCount = 1;
18481 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18482 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018483 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018484 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18485 dsl_binding[1].descriptorCount = 1;
18486 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18487 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018488 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018489 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18490 dsl_binding[2].descriptorCount = 1;
18491 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18492 dsl_binding[2].pImmutableSamplers = NULL;
18493
18494 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18495 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18496 ds_layout_ci.pNext = NULL;
18497 ds_layout_ci.bindingCount = BINDING_COUNT;
18498 ds_layout_ci.pBindings = dsl_binding;
18499 VkDescriptorSetLayout ds_layout;
18500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18501 ASSERT_VK_SUCCESS(err);
18502
18503 VkDescriptorSet descriptor_set;
18504 VkDescriptorSetAllocateInfo alloc_info = {};
18505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18506 alloc_info.descriptorSetCount = 1;
18507 alloc_info.descriptorPool = ds_pool;
18508 alloc_info.pSetLayouts = &ds_layout;
18509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18510 ASSERT_VK_SUCCESS(err);
18511
18512 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18513 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18514 pipeline_layout_ci.pNext = NULL;
18515 pipeline_layout_ci.setLayoutCount = 1;
18516 pipeline_layout_ci.pSetLayouts = &ds_layout;
18517
18518 VkPipelineLayout pipeline_layout;
18519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18520 ASSERT_VK_SUCCESS(err);
18521
18522 // Create two buffers to update the descriptors with
18523 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18524 uint32_t qfi = 0;
18525 VkBufferCreateInfo buffCI = {};
18526 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18527 buffCI.size = 2048;
18528 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18529 buffCI.queueFamilyIndexCount = 1;
18530 buffCI.pQueueFamilyIndices = &qfi;
18531
18532 VkBuffer dyub1;
18533 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18534 ASSERT_VK_SUCCESS(err);
18535 // buffer2
18536 buffCI.size = 1024;
18537 VkBuffer dyub2;
18538 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18539 ASSERT_VK_SUCCESS(err);
18540 // Allocate memory and bind to buffers
18541 VkMemoryAllocateInfo mem_alloc[2] = {};
18542 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18543 mem_alloc[0].pNext = NULL;
18544 mem_alloc[0].memoryTypeIndex = 0;
18545 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18546 mem_alloc[1].pNext = NULL;
18547 mem_alloc[1].memoryTypeIndex = 0;
18548
18549 VkMemoryRequirements mem_reqs1;
18550 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18551 VkMemoryRequirements mem_reqs2;
18552 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18553 mem_alloc[0].allocationSize = mem_reqs1.size;
18554 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18555 mem_alloc[1].allocationSize = mem_reqs2.size;
18556 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18557 if (!pass) {
18558 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18559 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18560 return;
18561 }
18562
18563 VkDeviceMemory mem1;
18564 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18565 ASSERT_VK_SUCCESS(err);
18566 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18567 ASSERT_VK_SUCCESS(err);
18568 VkDeviceMemory mem2;
18569 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18570 ASSERT_VK_SUCCESS(err);
18571 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18572 ASSERT_VK_SUCCESS(err);
18573 // Update descriptors
18574 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18575 buff_info[0].buffer = dyub1;
18576 buff_info[0].offset = 0;
18577 buff_info[0].range = 256;
18578 buff_info[1].buffer = dyub1;
18579 buff_info[1].offset = 256;
18580 buff_info[1].range = 512;
18581 buff_info[2].buffer = dyub2;
18582 buff_info[2].offset = 0;
18583 buff_info[2].range = 512;
18584
18585 VkWriteDescriptorSet descriptor_write;
18586 memset(&descriptor_write, 0, sizeof(descriptor_write));
18587 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18588 descriptor_write.dstSet = descriptor_set;
18589 descriptor_write.dstBinding = 0;
18590 descriptor_write.descriptorCount = BINDING_COUNT;
18591 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18592 descriptor_write.pBufferInfo = buff_info;
18593
18594 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18595
Tony Barbour552f6c02016-12-21 14:34:07 -070018596 m_commandBuffer->BeginCommandBuffer();
18597 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018598
18599 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018600 char const *vsSource =
18601 "#version 450\n"
18602 "\n"
18603 "out gl_PerVertex { \n"
18604 " vec4 gl_Position;\n"
18605 "};\n"
18606 "void main(){\n"
18607 " gl_Position = vec4(1);\n"
18608 "}\n";
18609 char const *fsSource =
18610 "#version 450\n"
18611 "\n"
18612 "layout(location=0) out vec4 x;\n"
18613 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18614 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18615 "void main(){\n"
18616 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18617 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018618 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18619 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18620 VkPipelineObj pipe(m_device);
18621 pipe.SetViewport(m_viewports);
18622 pipe.SetScissor(m_scissors);
18623 pipe.AddShader(&vs);
18624 pipe.AddShader(&fs);
18625 pipe.AddColorAttachment();
18626 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18627
18628 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18629 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18630 // we used to have a bug in this case.
18631 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18632 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18633 &descriptor_set, BINDING_COUNT, dyn_off);
18634 Draw(1, 0, 0, 0);
18635 m_errorMonitor->VerifyNotFound();
18636
18637 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18638 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18639 vkFreeMemory(m_device->device(), mem1, NULL);
18640 vkFreeMemory(m_device->device(), mem2, NULL);
18641
18642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18645}
18646
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018647TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018648 TEST_DESCRIPTION(
18649 "Ensure that validations handling of non-coherent memory "
18650 "mapping while using VK_WHOLE_SIZE does not cause access "
18651 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018652 VkResult err;
18653 uint8_t *pData;
18654 ASSERT_NO_FATAL_FAILURE(InitState());
18655
18656 VkDeviceMemory mem;
18657 VkMemoryRequirements mem_reqs;
18658 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018659 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018660 VkMemoryAllocateInfo alloc_info = {};
18661 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18662 alloc_info.pNext = NULL;
18663 alloc_info.memoryTypeIndex = 0;
18664
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018665 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018666 alloc_info.allocationSize = allocation_size;
18667
18668 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
18669 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 -070018670 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018671 if (!pass) {
18672 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018673 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
18674 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018675 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018676 pass = m_device->phy().set_memory_type(
18677 mem_reqs.memoryTypeBits, &alloc_info,
18678 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
18679 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018680 if (!pass) {
18681 return;
18682 }
18683 }
18684 }
18685
18686 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18687 ASSERT_VK_SUCCESS(err);
18688
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018689 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018690 m_errorMonitor->ExpectSuccess();
18691 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
18692 ASSERT_VK_SUCCESS(err);
18693 VkMappedMemoryRange mmr = {};
18694 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18695 mmr.memory = mem;
18696 mmr.offset = 0;
18697 mmr.size = VK_WHOLE_SIZE;
18698 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18699 ASSERT_VK_SUCCESS(err);
18700 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18701 ASSERT_VK_SUCCESS(err);
18702 m_errorMonitor->VerifyNotFound();
18703 vkUnmapMemory(m_device->device(), mem);
18704
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018705 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018706 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018707 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018708 ASSERT_VK_SUCCESS(err);
18709 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18710 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018711 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018712 mmr.size = VK_WHOLE_SIZE;
18713 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18714 ASSERT_VK_SUCCESS(err);
18715 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18716 ASSERT_VK_SUCCESS(err);
18717 m_errorMonitor->VerifyNotFound();
18718 vkUnmapMemory(m_device->device(), mem);
18719
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018720 // Map with offset and size
18721 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018722 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018723 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018724 ASSERT_VK_SUCCESS(err);
18725 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18726 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018727 mmr.offset = 4 * atom_size;
18728 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018729 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18730 ASSERT_VK_SUCCESS(err);
18731 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18732 ASSERT_VK_SUCCESS(err);
18733 m_errorMonitor->VerifyNotFound();
18734 vkUnmapMemory(m_device->device(), mem);
18735
18736 // Map without offset and flush WHOLE_SIZE with two separate offsets
18737 m_errorMonitor->ExpectSuccess();
18738 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
18739 ASSERT_VK_SUCCESS(err);
18740 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18741 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018742 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018743 mmr.size = VK_WHOLE_SIZE;
18744 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18745 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018746 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018747 mmr.size = VK_WHOLE_SIZE;
18748 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18749 ASSERT_VK_SUCCESS(err);
18750 m_errorMonitor->VerifyNotFound();
18751 vkUnmapMemory(m_device->device(), mem);
18752
18753 vkFreeMemory(m_device->device(), mem, NULL);
18754}
18755
18756// This is a positive test. We used to expect error in this case but spec now allows it
18757TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
18758 m_errorMonitor->ExpectSuccess();
18759 vk_testing::Fence testFence;
18760 VkFenceCreateInfo fenceInfo = {};
18761 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18762 fenceInfo.pNext = NULL;
18763
18764 ASSERT_NO_FATAL_FAILURE(InitState());
18765 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018766 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018767 VkResult result = vkResetFences(m_device->device(), 1, fences);
18768 ASSERT_VK_SUCCESS(result);
18769
18770 m_errorMonitor->VerifyNotFound();
18771}
18772
18773TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
18774 m_errorMonitor->ExpectSuccess();
18775
18776 ASSERT_NO_FATAL_FAILURE(InitState());
18777 VkResult err;
18778
18779 // Record (empty!) command buffer that can be submitted multiple times
18780 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018781 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
18782 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018783 m_commandBuffer->BeginCommandBuffer(&cbbi);
18784 m_commandBuffer->EndCommandBuffer();
18785
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018786 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018787 VkFence fence;
18788 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
18789 ASSERT_VK_SUCCESS(err);
18790
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018791 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018792 VkSemaphore s1, s2;
18793 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
18794 ASSERT_VK_SUCCESS(err);
18795 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
18796 ASSERT_VK_SUCCESS(err);
18797
18798 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018799 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018800 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
18801 ASSERT_VK_SUCCESS(err);
18802
18803 // Submit CB again, signaling s2.
18804 si.pSignalSemaphores = &s2;
18805 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
18806 ASSERT_VK_SUCCESS(err);
18807
18808 // Wait for fence.
18809 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18810 ASSERT_VK_SUCCESS(err);
18811
18812 // CB is still in flight from second submission, but semaphore s1 is no
18813 // longer in flight. delete it.
18814 vkDestroySemaphore(m_device->device(), s1, nullptr);
18815
18816 m_errorMonitor->VerifyNotFound();
18817
18818 // Force device idle and clean up remaining objects
18819 vkDeviceWaitIdle(m_device->device());
18820 vkDestroySemaphore(m_device->device(), s2, nullptr);
18821 vkDestroyFence(m_device->device(), fence, nullptr);
18822}
18823
18824TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
18825 m_errorMonitor->ExpectSuccess();
18826
18827 ASSERT_NO_FATAL_FAILURE(InitState());
18828 VkResult err;
18829
18830 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018831 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018832 VkFence f1;
18833 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
18834 ASSERT_VK_SUCCESS(err);
18835
18836 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018837 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018838 VkFence f2;
18839 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
18840 ASSERT_VK_SUCCESS(err);
18841
18842 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018843 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018844 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
18845
18846 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018847 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018848 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
18849
18850 // Should have both retired!
18851 vkDestroyFence(m_device->device(), f1, nullptr);
18852 vkDestroyFence(m_device->device(), f2, nullptr);
18853
18854 m_errorMonitor->VerifyNotFound();
18855}
18856
18857TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018858 TEST_DESCRIPTION(
18859 "Verify that creating an image view from an image with valid usage "
18860 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018861
18862 ASSERT_NO_FATAL_FAILURE(InitState());
18863
18864 m_errorMonitor->ExpectSuccess();
18865 // Verify that we can create a view with usage INPUT_ATTACHMENT
18866 VkImageObj image(m_device);
18867 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18868 ASSERT_TRUE(image.initialized());
18869 VkImageView imageView;
18870 VkImageViewCreateInfo ivci = {};
18871 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18872 ivci.image = image.handle();
18873 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
18874 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
18875 ivci.subresourceRange.layerCount = 1;
18876 ivci.subresourceRange.baseMipLevel = 0;
18877 ivci.subresourceRange.levelCount = 1;
18878 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18879
18880 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
18881 m_errorMonitor->VerifyNotFound();
18882 vkDestroyImageView(m_device->device(), imageView, NULL);
18883}
18884
18885// This is a positive test. No failures are expected.
18886TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018887 TEST_DESCRIPTION(
18888 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
18889 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018890
18891 ASSERT_NO_FATAL_FAILURE(InitState());
18892
18893 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018894 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018895
18896 m_errorMonitor->ExpectSuccess();
18897
18898 VkImage image;
18899 VkImageCreateInfo image_create_info = {};
18900 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18901 image_create_info.pNext = NULL;
18902 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18903 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18904 image_create_info.extent.width = 64;
18905 image_create_info.extent.height = 64;
18906 image_create_info.extent.depth = 1;
18907 image_create_info.mipLevels = 1;
18908 image_create_info.arrayLayers = 1;
18909 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18910 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18911 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
18912 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
18913 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18914 ASSERT_VK_SUCCESS(err);
18915
18916 VkMemoryRequirements memory_reqs;
18917 VkDeviceMemory memory_one, memory_two;
18918 bool pass;
18919 VkMemoryAllocateInfo memory_info = {};
18920 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18921 memory_info.pNext = NULL;
18922 memory_info.allocationSize = 0;
18923 memory_info.memoryTypeIndex = 0;
18924 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18925 // Find an image big enough to allow sparse mapping of 2 memory regions
18926 // Increase the image size until it is at least twice the
18927 // size of the required alignment, to ensure we can bind both
18928 // allocated memory blocks to the image on aligned offsets.
18929 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
18930 vkDestroyImage(m_device->device(), image, nullptr);
18931 image_create_info.extent.width *= 2;
18932 image_create_info.extent.height *= 2;
18933 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
18934 ASSERT_VK_SUCCESS(err);
18935 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18936 }
18937 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
18938 // at the end of the first
18939 memory_info.allocationSize = memory_reqs.alignment;
18940 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18941 ASSERT_TRUE(pass);
18942 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
18943 ASSERT_VK_SUCCESS(err);
18944 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
18945 ASSERT_VK_SUCCESS(err);
18946 VkSparseMemoryBind binds[2];
18947 binds[0].flags = 0;
18948 binds[0].memory = memory_one;
18949 binds[0].memoryOffset = 0;
18950 binds[0].resourceOffset = 0;
18951 binds[0].size = memory_info.allocationSize;
18952 binds[1].flags = 0;
18953 binds[1].memory = memory_two;
18954 binds[1].memoryOffset = 0;
18955 binds[1].resourceOffset = memory_info.allocationSize;
18956 binds[1].size = memory_info.allocationSize;
18957
18958 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
18959 opaqueBindInfo.image = image;
18960 opaqueBindInfo.bindCount = 2;
18961 opaqueBindInfo.pBinds = binds;
18962
18963 VkFence fence = VK_NULL_HANDLE;
18964 VkBindSparseInfo bindSparseInfo = {};
18965 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
18966 bindSparseInfo.imageOpaqueBindCount = 1;
18967 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
18968
18969 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
18970 vkQueueWaitIdle(m_device->m_queue);
18971 vkDestroyImage(m_device->device(), image, NULL);
18972 vkFreeMemory(m_device->device(), memory_one, NULL);
18973 vkFreeMemory(m_device->device(), memory_two, NULL);
18974 m_errorMonitor->VerifyNotFound();
18975}
18976
18977TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018978 TEST_DESCRIPTION(
18979 "Ensure that CmdBeginRenderPass with an attachment's "
18980 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
18981 "the command buffer has prior knowledge of that "
18982 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018983
18984 m_errorMonitor->ExpectSuccess();
18985
18986 ASSERT_NO_FATAL_FAILURE(InitState());
18987
18988 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018989 VkAttachmentDescription attachment = {0,
18990 VK_FORMAT_R8G8B8A8_UNORM,
18991 VK_SAMPLE_COUNT_1_BIT,
18992 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18993 VK_ATTACHMENT_STORE_OP_STORE,
18994 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18995 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18996 VK_IMAGE_LAYOUT_UNDEFINED,
18997 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018998
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018999 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019000
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019001 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019002
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019003 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019004
19005 VkRenderPass rp;
19006 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19007 ASSERT_VK_SUCCESS(err);
19008
19009 // A compatible framebuffer.
19010 VkImageObj image(m_device);
19011 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19012 ASSERT_TRUE(image.initialized());
19013
19014 VkImageViewCreateInfo ivci = {
19015 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19016 nullptr,
19017 0,
19018 image.handle(),
19019 VK_IMAGE_VIEW_TYPE_2D,
19020 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019021 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19022 VK_COMPONENT_SWIZZLE_IDENTITY},
19023 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019024 };
19025 VkImageView view;
19026 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19027 ASSERT_VK_SUCCESS(err);
19028
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019029 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019030 VkFramebuffer fb;
19031 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19032 ASSERT_VK_SUCCESS(err);
19033
19034 // Record a single command buffer which uses this renderpass twice. The
19035 // bug is triggered at the beginning of the second renderpass, when the
19036 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019037 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 -070019038 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019039 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19040 vkCmdEndRenderPass(m_commandBuffer->handle());
19041 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19042
19043 m_errorMonitor->VerifyNotFound();
19044
19045 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019046 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019047
19048 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19049 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19050 vkDestroyImageView(m_device->device(), view, nullptr);
19051}
19052
19053TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019054 TEST_DESCRIPTION(
19055 "This test should pass. Create a Framebuffer and "
19056 "command buffer, bind them together, then destroy "
19057 "command pool and framebuffer and verify there are no "
19058 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019059
19060 m_errorMonitor->ExpectSuccess();
19061
19062 ASSERT_NO_FATAL_FAILURE(InitState());
19063
19064 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019065 VkAttachmentDescription attachment = {0,
19066 VK_FORMAT_R8G8B8A8_UNORM,
19067 VK_SAMPLE_COUNT_1_BIT,
19068 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19069 VK_ATTACHMENT_STORE_OP_STORE,
19070 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19071 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19072 VK_IMAGE_LAYOUT_UNDEFINED,
19073 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019074
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019075 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019076
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019077 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019078
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019079 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019080
19081 VkRenderPass rp;
19082 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19083 ASSERT_VK_SUCCESS(err);
19084
19085 // A compatible framebuffer.
19086 VkImageObj image(m_device);
19087 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19088 ASSERT_TRUE(image.initialized());
19089
19090 VkImageViewCreateInfo ivci = {
19091 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19092 nullptr,
19093 0,
19094 image.handle(),
19095 VK_IMAGE_VIEW_TYPE_2D,
19096 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019097 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19098 VK_COMPONENT_SWIZZLE_IDENTITY},
19099 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019100 };
19101 VkImageView view;
19102 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19103 ASSERT_VK_SUCCESS(err);
19104
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019105 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019106 VkFramebuffer fb;
19107 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19108 ASSERT_VK_SUCCESS(err);
19109
19110 // Explicitly create a command buffer to bind the FB to so that we can then
19111 // destroy the command pool in order to implicitly free command buffer
19112 VkCommandPool command_pool;
19113 VkCommandPoolCreateInfo pool_create_info{};
19114 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19115 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19116 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19117 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19118
19119 VkCommandBuffer command_buffer;
19120 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19121 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19122 command_buffer_allocate_info.commandPool = command_pool;
19123 command_buffer_allocate_info.commandBufferCount = 1;
19124 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19125 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19126
19127 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019128 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 -060019129 VkCommandBufferBeginInfo begin_info{};
19130 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19131 vkBeginCommandBuffer(command_buffer, &begin_info);
19132
19133 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19134 vkCmdEndRenderPass(command_buffer);
19135 vkEndCommandBuffer(command_buffer);
19136 vkDestroyImageView(m_device->device(), view, nullptr);
19137 // Destroy command pool to implicitly free command buffer
19138 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19139 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19140 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19141 m_errorMonitor->VerifyNotFound();
19142}
19143
19144TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019145 TEST_DESCRIPTION(
19146 "Ensure that CmdBeginRenderPass applies the layout "
19147 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019148
19149 m_errorMonitor->ExpectSuccess();
19150
19151 ASSERT_NO_FATAL_FAILURE(InitState());
19152
19153 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019154 VkAttachmentDescription attachment = {0,
19155 VK_FORMAT_R8G8B8A8_UNORM,
19156 VK_SAMPLE_COUNT_1_BIT,
19157 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19158 VK_ATTACHMENT_STORE_OP_STORE,
19159 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19160 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19161 VK_IMAGE_LAYOUT_UNDEFINED,
19162 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019163
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019164 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019165
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019166 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019167
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019168 VkSubpassDependency dep = {0,
19169 0,
19170 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19171 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19172 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19173 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19174 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019175
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019176 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019177
19178 VkResult err;
19179 VkRenderPass rp;
19180 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19181 ASSERT_VK_SUCCESS(err);
19182
19183 // A compatible framebuffer.
19184 VkImageObj image(m_device);
19185 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19186 ASSERT_TRUE(image.initialized());
19187
19188 VkImageViewCreateInfo ivci = {
19189 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19190 nullptr,
19191 0,
19192 image.handle(),
19193 VK_IMAGE_VIEW_TYPE_2D,
19194 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019195 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19196 VK_COMPONENT_SWIZZLE_IDENTITY},
19197 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019198 };
19199 VkImageView view;
19200 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19201 ASSERT_VK_SUCCESS(err);
19202
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019203 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019204 VkFramebuffer fb;
19205 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19206 ASSERT_VK_SUCCESS(err);
19207
19208 // Record a single command buffer which issues a pipeline barrier w/
19209 // image memory barrier for the attachment. This detects the previously
19210 // missing tracking of the subpass layout by throwing a validation error
19211 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019212 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 -070019213 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019214 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19215
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019216 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19217 nullptr,
19218 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19219 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19220 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19221 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19222 VK_QUEUE_FAMILY_IGNORED,
19223 VK_QUEUE_FAMILY_IGNORED,
19224 image.handle(),
19225 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019226 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019227 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19228 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019229
19230 vkCmdEndRenderPass(m_commandBuffer->handle());
19231 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019232 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019233
19234 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19235 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19236 vkDestroyImageView(m_device->device(), view, nullptr);
19237}
19238
19239TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019240 TEST_DESCRIPTION(
19241 "Validate that when an imageView of a depth/stencil image "
19242 "is used as a depth/stencil framebuffer attachment, the "
19243 "aspectMask is ignored and both depth and stencil image "
19244 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019245
19246 VkFormatProperties format_properties;
19247 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19248 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19249 return;
19250 }
19251
19252 m_errorMonitor->ExpectSuccess();
19253
19254 ASSERT_NO_FATAL_FAILURE(InitState());
19255
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019256 VkAttachmentDescription attachment = {0,
19257 VK_FORMAT_D32_SFLOAT_S8_UINT,
19258 VK_SAMPLE_COUNT_1_BIT,
19259 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19260 VK_ATTACHMENT_STORE_OP_STORE,
19261 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19262 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19263 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19264 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019265
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019266 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019267
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019268 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019269
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019270 VkSubpassDependency dep = {0,
19271 0,
19272 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19273 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19274 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19275 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19276 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019277
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019278 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019279
19280 VkResult err;
19281 VkRenderPass rp;
19282 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19283 ASSERT_VK_SUCCESS(err);
19284
19285 VkImageObj image(m_device);
19286 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019287 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019288 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019289 ASSERT_TRUE(image.initialized());
19290 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19291
19292 VkImageViewCreateInfo ivci = {
19293 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19294 nullptr,
19295 0,
19296 image.handle(),
19297 VK_IMAGE_VIEW_TYPE_2D,
19298 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019299 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19300 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019301 };
19302 VkImageView view;
19303 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19304 ASSERT_VK_SUCCESS(err);
19305
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019306 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019307 VkFramebuffer fb;
19308 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19309 ASSERT_VK_SUCCESS(err);
19310
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019311 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 -070019312 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019313 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19314
19315 VkImageMemoryBarrier imb = {};
19316 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19317 imb.pNext = nullptr;
19318 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19319 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19320 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19321 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19322 imb.srcQueueFamilyIndex = 0;
19323 imb.dstQueueFamilyIndex = 0;
19324 imb.image = image.handle();
19325 imb.subresourceRange.aspectMask = 0x6;
19326 imb.subresourceRange.baseMipLevel = 0;
19327 imb.subresourceRange.levelCount = 0x1;
19328 imb.subresourceRange.baseArrayLayer = 0;
19329 imb.subresourceRange.layerCount = 0x1;
19330
19331 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019332 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19333 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019334
19335 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019336 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019337 QueueCommandBuffer(false);
19338 m_errorMonitor->VerifyNotFound();
19339
19340 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19341 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19342 vkDestroyImageView(m_device->device(), view, nullptr);
19343}
19344
19345TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019346 TEST_DESCRIPTION(
19347 "Ensure that layout transitions work correctly without "
19348 "errors, when an attachment reference is "
19349 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019350
19351 m_errorMonitor->ExpectSuccess();
19352
19353 ASSERT_NO_FATAL_FAILURE(InitState());
19354
19355 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019356 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019357
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019358 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019359
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019360 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019361
19362 VkRenderPass rp;
19363 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19364 ASSERT_VK_SUCCESS(err);
19365
19366 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019367 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019368 VkFramebuffer fb;
19369 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19370 ASSERT_VK_SUCCESS(err);
19371
19372 // Record a command buffer which just begins and ends the renderpass. The
19373 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019374 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 -070019375 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019376 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19377 vkCmdEndRenderPass(m_commandBuffer->handle());
19378 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019379 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019380
19381 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19382 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19383}
19384
19385// This is a positive test. No errors are expected.
19386TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019387 TEST_DESCRIPTION(
19388 "Create a stencil-only attachment with a LOAD_OP set to "
19389 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019390 VkResult result = VK_SUCCESS;
19391 VkImageFormatProperties formatProps;
19392 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019393 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19394 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019395 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19396 return;
19397 }
19398
19399 ASSERT_NO_FATAL_FAILURE(InitState());
19400 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19401 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019402 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019403 VkAttachmentDescription att = {};
19404 VkAttachmentReference ref = {};
19405 att.format = depth_stencil_fmt;
19406 att.samples = VK_SAMPLE_COUNT_1_BIT;
19407 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19408 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19409 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19410 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19411 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19412 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19413
19414 VkClearValue clear;
19415 clear.depthStencil.depth = 1.0;
19416 clear.depthStencil.stencil = 0;
19417 ref.attachment = 0;
19418 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19419
19420 VkSubpassDescription subpass = {};
19421 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19422 subpass.flags = 0;
19423 subpass.inputAttachmentCount = 0;
19424 subpass.pInputAttachments = NULL;
19425 subpass.colorAttachmentCount = 0;
19426 subpass.pColorAttachments = NULL;
19427 subpass.pResolveAttachments = NULL;
19428 subpass.pDepthStencilAttachment = &ref;
19429 subpass.preserveAttachmentCount = 0;
19430 subpass.pPreserveAttachments = NULL;
19431
19432 VkRenderPass rp;
19433 VkRenderPassCreateInfo rp_info = {};
19434 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19435 rp_info.attachmentCount = 1;
19436 rp_info.pAttachments = &att;
19437 rp_info.subpassCount = 1;
19438 rp_info.pSubpasses = &subpass;
19439 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19440 ASSERT_VK_SUCCESS(result);
19441
19442 VkImageView *depthView = m_depthStencil->BindInfo();
19443 VkFramebufferCreateInfo fb_info = {};
19444 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19445 fb_info.pNext = NULL;
19446 fb_info.renderPass = rp;
19447 fb_info.attachmentCount = 1;
19448 fb_info.pAttachments = depthView;
19449 fb_info.width = 100;
19450 fb_info.height = 100;
19451 fb_info.layers = 1;
19452 VkFramebuffer fb;
19453 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19454 ASSERT_VK_SUCCESS(result);
19455
19456 VkRenderPassBeginInfo rpbinfo = {};
19457 rpbinfo.clearValueCount = 1;
19458 rpbinfo.pClearValues = &clear;
19459 rpbinfo.pNext = NULL;
19460 rpbinfo.renderPass = rp;
19461 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19462 rpbinfo.renderArea.extent.width = 100;
19463 rpbinfo.renderArea.extent.height = 100;
19464 rpbinfo.renderArea.offset.x = 0;
19465 rpbinfo.renderArea.offset.y = 0;
19466 rpbinfo.framebuffer = fb;
19467
19468 VkFence fence = {};
19469 VkFenceCreateInfo fence_ci = {};
19470 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19471 fence_ci.pNext = nullptr;
19472 fence_ci.flags = 0;
19473 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19474 ASSERT_VK_SUCCESS(result);
19475
19476 m_commandBuffer->BeginCommandBuffer();
19477 m_commandBuffer->BeginRenderPass(rpbinfo);
19478 m_commandBuffer->EndRenderPass();
19479 m_commandBuffer->EndCommandBuffer();
19480 m_commandBuffer->QueueCommandBuffer(fence);
19481
19482 VkImageObj destImage(m_device);
19483 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 -070019484 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019485 VkImageMemoryBarrier barrier = {};
19486 VkImageSubresourceRange range;
19487 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19488 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19489 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19490 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19491 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19492 barrier.image = m_depthStencil->handle();
19493 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19494 range.baseMipLevel = 0;
19495 range.levelCount = 1;
19496 range.baseArrayLayer = 0;
19497 range.layerCount = 1;
19498 barrier.subresourceRange = range;
19499 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19500 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19501 cmdbuf.BeginCommandBuffer();
19502 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 -070019503 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019504 barrier.srcAccessMask = 0;
19505 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19506 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19507 barrier.image = destImage.handle();
19508 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19509 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 -070019510 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019511 VkImageCopy cregion;
19512 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19513 cregion.srcSubresource.mipLevel = 0;
19514 cregion.srcSubresource.baseArrayLayer = 0;
19515 cregion.srcSubresource.layerCount = 1;
19516 cregion.srcOffset.x = 0;
19517 cregion.srcOffset.y = 0;
19518 cregion.srcOffset.z = 0;
19519 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19520 cregion.dstSubresource.mipLevel = 0;
19521 cregion.dstSubresource.baseArrayLayer = 0;
19522 cregion.dstSubresource.layerCount = 1;
19523 cregion.dstOffset.x = 0;
19524 cregion.dstOffset.y = 0;
19525 cregion.dstOffset.z = 0;
19526 cregion.extent.width = 100;
19527 cregion.extent.height = 100;
19528 cregion.extent.depth = 1;
19529 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019530 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019531 cmdbuf.EndCommandBuffer();
19532
19533 VkSubmitInfo submit_info;
19534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19535 submit_info.pNext = NULL;
19536 submit_info.waitSemaphoreCount = 0;
19537 submit_info.pWaitSemaphores = NULL;
19538 submit_info.pWaitDstStageMask = NULL;
19539 submit_info.commandBufferCount = 1;
19540 submit_info.pCommandBuffers = &cmdbuf.handle();
19541 submit_info.signalSemaphoreCount = 0;
19542 submit_info.pSignalSemaphores = NULL;
19543
19544 m_errorMonitor->ExpectSuccess();
19545 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19546 m_errorMonitor->VerifyNotFound();
19547
19548 vkQueueWaitIdle(m_device->m_queue);
19549 vkDestroyFence(m_device->device(), fence, nullptr);
19550 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19551 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19552}
19553
19554// This is a positive test. No errors should be generated.
19555TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19556 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19557
19558 m_errorMonitor->ExpectSuccess();
19559 ASSERT_NO_FATAL_FAILURE(InitState());
19560
19561 VkEvent event;
19562 VkEventCreateInfo event_create_info{};
19563 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19564 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19565
19566 VkCommandPool command_pool;
19567 VkCommandPoolCreateInfo pool_create_info{};
19568 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19569 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19570 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19571 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19572
19573 VkCommandBuffer command_buffer;
19574 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19575 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19576 command_buffer_allocate_info.commandPool = command_pool;
19577 command_buffer_allocate_info.commandBufferCount = 1;
19578 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19579 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19580
19581 VkQueue queue = VK_NULL_HANDLE;
19582 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19583
19584 {
19585 VkCommandBufferBeginInfo begin_info{};
19586 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19587 vkBeginCommandBuffer(command_buffer, &begin_info);
19588
19589 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 -070019590 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019591 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19592 vkEndCommandBuffer(command_buffer);
19593 }
19594 {
19595 VkSubmitInfo submit_info{};
19596 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19597 submit_info.commandBufferCount = 1;
19598 submit_info.pCommandBuffers = &command_buffer;
19599 submit_info.signalSemaphoreCount = 0;
19600 submit_info.pSignalSemaphores = nullptr;
19601 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19602 }
19603 { vkSetEvent(m_device->device(), event); }
19604
19605 vkQueueWaitIdle(queue);
19606
19607 vkDestroyEvent(m_device->device(), event, nullptr);
19608 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19609 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19610
19611 m_errorMonitor->VerifyNotFound();
19612}
19613// This is a positive test. No errors should be generated.
19614TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19615 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19616
19617 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019618 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019619
19620 m_errorMonitor->ExpectSuccess();
19621
19622 VkQueryPool query_pool;
19623 VkQueryPoolCreateInfo query_pool_create_info{};
19624 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19625 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19626 query_pool_create_info.queryCount = 1;
19627 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19628
19629 VkCommandPool command_pool;
19630 VkCommandPoolCreateInfo pool_create_info{};
19631 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19632 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19633 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19634 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19635
19636 VkCommandBuffer command_buffer;
19637 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19638 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19639 command_buffer_allocate_info.commandPool = command_pool;
19640 command_buffer_allocate_info.commandBufferCount = 1;
19641 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19642 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19643
19644 VkCommandBuffer secondary_command_buffer;
19645 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19646 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
19647
19648 VkQueue queue = VK_NULL_HANDLE;
19649 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19650
19651 uint32_t qfi = 0;
19652 VkBufferCreateInfo buff_create_info = {};
19653 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19654 buff_create_info.size = 1024;
19655 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19656 buff_create_info.queueFamilyIndexCount = 1;
19657 buff_create_info.pQueueFamilyIndices = &qfi;
19658
19659 VkResult err;
19660 VkBuffer buffer;
19661 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19662 ASSERT_VK_SUCCESS(err);
19663 VkMemoryAllocateInfo mem_alloc = {};
19664 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19665 mem_alloc.pNext = NULL;
19666 mem_alloc.allocationSize = 1024;
19667 mem_alloc.memoryTypeIndex = 0;
19668
19669 VkMemoryRequirements memReqs;
19670 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19671 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19672 if (!pass) {
19673 vkDestroyBuffer(m_device->device(), buffer, NULL);
19674 return;
19675 }
19676
19677 VkDeviceMemory mem;
19678 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19679 ASSERT_VK_SUCCESS(err);
19680 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19681 ASSERT_VK_SUCCESS(err);
19682
19683 VkCommandBufferInheritanceInfo hinfo = {};
19684 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19685 hinfo.renderPass = VK_NULL_HANDLE;
19686 hinfo.subpass = 0;
19687 hinfo.framebuffer = VK_NULL_HANDLE;
19688 hinfo.occlusionQueryEnable = VK_FALSE;
19689 hinfo.queryFlags = 0;
19690 hinfo.pipelineStatistics = 0;
19691
19692 {
19693 VkCommandBufferBeginInfo begin_info{};
19694 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19695 begin_info.pInheritanceInfo = &hinfo;
19696 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
19697
19698 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
19699 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19700
19701 vkEndCommandBuffer(secondary_command_buffer);
19702
19703 begin_info.pInheritanceInfo = nullptr;
19704 vkBeginCommandBuffer(command_buffer, &begin_info);
19705
19706 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
19707 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
19708
19709 vkEndCommandBuffer(command_buffer);
19710 }
19711 {
19712 VkSubmitInfo submit_info{};
19713 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19714 submit_info.commandBufferCount = 1;
19715 submit_info.pCommandBuffers = &command_buffer;
19716 submit_info.signalSemaphoreCount = 0;
19717 submit_info.pSignalSemaphores = nullptr;
19718 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19719 }
19720
19721 vkQueueWaitIdle(queue);
19722
19723 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19724 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19725 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
19726 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19727 vkDestroyBuffer(m_device->device(), buffer, NULL);
19728 vkFreeMemory(m_device->device(), mem, NULL);
19729
19730 m_errorMonitor->VerifyNotFound();
19731}
19732
19733// This is a positive test. No errors should be generated.
19734TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
19735 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
19736
19737 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019738 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019739
19740 m_errorMonitor->ExpectSuccess();
19741
19742 VkQueryPool query_pool;
19743 VkQueryPoolCreateInfo query_pool_create_info{};
19744 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19745 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19746 query_pool_create_info.queryCount = 1;
19747 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19748
19749 VkCommandPool command_pool;
19750 VkCommandPoolCreateInfo pool_create_info{};
19751 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19752 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19753 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19754 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19755
19756 VkCommandBuffer command_buffer[2];
19757 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19758 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19759 command_buffer_allocate_info.commandPool = command_pool;
19760 command_buffer_allocate_info.commandBufferCount = 2;
19761 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19762 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19763
19764 VkQueue queue = VK_NULL_HANDLE;
19765 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19766
19767 uint32_t qfi = 0;
19768 VkBufferCreateInfo buff_create_info = {};
19769 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19770 buff_create_info.size = 1024;
19771 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19772 buff_create_info.queueFamilyIndexCount = 1;
19773 buff_create_info.pQueueFamilyIndices = &qfi;
19774
19775 VkResult err;
19776 VkBuffer buffer;
19777 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19778 ASSERT_VK_SUCCESS(err);
19779 VkMemoryAllocateInfo mem_alloc = {};
19780 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19781 mem_alloc.pNext = NULL;
19782 mem_alloc.allocationSize = 1024;
19783 mem_alloc.memoryTypeIndex = 0;
19784
19785 VkMemoryRequirements memReqs;
19786 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19787 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19788 if (!pass) {
19789 vkDestroyBuffer(m_device->device(), buffer, NULL);
19790 return;
19791 }
19792
19793 VkDeviceMemory mem;
19794 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19795 ASSERT_VK_SUCCESS(err);
19796 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19797 ASSERT_VK_SUCCESS(err);
19798
19799 {
19800 VkCommandBufferBeginInfo begin_info{};
19801 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19802 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19803
19804 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
19805 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19806
19807 vkEndCommandBuffer(command_buffer[0]);
19808
19809 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19810
19811 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
19812
19813 vkEndCommandBuffer(command_buffer[1]);
19814 }
19815 {
19816 VkSubmitInfo submit_info{};
19817 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19818 submit_info.commandBufferCount = 2;
19819 submit_info.pCommandBuffers = command_buffer;
19820 submit_info.signalSemaphoreCount = 0;
19821 submit_info.pSignalSemaphores = nullptr;
19822 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19823 }
19824
19825 vkQueueWaitIdle(queue);
19826
19827 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19828 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
19829 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19830 vkDestroyBuffer(m_device->device(), buffer, NULL);
19831 vkFreeMemory(m_device->device(), mem, NULL);
19832
19833 m_errorMonitor->VerifyNotFound();
19834}
19835
Tony Barbourc46924f2016-11-04 11:49:52 -060019836TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019837 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
19838
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019839 ASSERT_NO_FATAL_FAILURE(InitState());
19840 VkEvent event;
19841 VkEventCreateInfo event_create_info{};
19842 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19843 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19844
19845 VkCommandPool command_pool;
19846 VkCommandPoolCreateInfo pool_create_info{};
19847 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19848 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19849 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19850 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19851
19852 VkCommandBuffer command_buffer;
19853 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19854 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19855 command_buffer_allocate_info.commandPool = command_pool;
19856 command_buffer_allocate_info.commandBufferCount = 1;
19857 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19858 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19859
19860 VkQueue queue = VK_NULL_HANDLE;
19861 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19862
19863 {
19864 VkCommandBufferBeginInfo begin_info{};
19865 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19866 vkBeginCommandBuffer(command_buffer, &begin_info);
19867
19868 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019869 vkEndCommandBuffer(command_buffer);
19870 }
19871 {
19872 VkSubmitInfo submit_info{};
19873 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19874 submit_info.commandBufferCount = 1;
19875 submit_info.pCommandBuffers = &command_buffer;
19876 submit_info.signalSemaphoreCount = 0;
19877 submit_info.pSignalSemaphores = nullptr;
19878 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19879 }
19880 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19882 "that is already in use by a "
19883 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019884 vkSetEvent(m_device->device(), event);
19885 m_errorMonitor->VerifyFound();
19886 }
19887
19888 vkQueueWaitIdle(queue);
19889
19890 vkDestroyEvent(m_device->device(), event, nullptr);
19891 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19892 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19893}
19894
19895// This is a positive test. No errors should be generated.
19896TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019897 TEST_DESCRIPTION(
19898 "Two command buffers with two separate fences are each "
19899 "run through a Submit & WaitForFences cycle 3 times. This "
19900 "previously revealed a bug so running this positive test "
19901 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019902 m_errorMonitor->ExpectSuccess();
19903
19904 ASSERT_NO_FATAL_FAILURE(InitState());
19905 VkQueue queue = VK_NULL_HANDLE;
19906 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19907
19908 static const uint32_t NUM_OBJECTS = 2;
19909 static const uint32_t NUM_FRAMES = 3;
19910 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
19911 VkFence fences[NUM_OBJECTS] = {};
19912
19913 VkCommandPool cmd_pool;
19914 VkCommandPoolCreateInfo cmd_pool_ci = {};
19915 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19916 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
19917 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19918 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
19919 ASSERT_VK_SUCCESS(err);
19920
19921 VkCommandBufferAllocateInfo cmd_buf_info = {};
19922 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19923 cmd_buf_info.commandPool = cmd_pool;
19924 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19925 cmd_buf_info.commandBufferCount = 1;
19926
19927 VkFenceCreateInfo fence_ci = {};
19928 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19929 fence_ci.pNext = nullptr;
19930 fence_ci.flags = 0;
19931
19932 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19933 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
19934 ASSERT_VK_SUCCESS(err);
19935 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
19936 ASSERT_VK_SUCCESS(err);
19937 }
19938
19939 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
19940 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
19941 // Create empty cmd buffer
19942 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
19943 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19944
19945 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
19946 ASSERT_VK_SUCCESS(err);
19947 err = vkEndCommandBuffer(cmd_buffers[obj]);
19948 ASSERT_VK_SUCCESS(err);
19949
19950 VkSubmitInfo submit_info = {};
19951 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19952 submit_info.commandBufferCount = 1;
19953 submit_info.pCommandBuffers = &cmd_buffers[obj];
19954 // Submit cmd buffer and wait for fence
19955 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
19956 ASSERT_VK_SUCCESS(err);
19957 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
19958 ASSERT_VK_SUCCESS(err);
19959 err = vkResetFences(m_device->device(), 1, &fences[obj]);
19960 ASSERT_VK_SUCCESS(err);
19961 }
19962 }
19963 m_errorMonitor->VerifyNotFound();
19964 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
19965 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19966 vkDestroyFence(m_device->device(), fences[i], nullptr);
19967 }
19968}
19969// This is a positive test. No errors should be generated.
19970TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019971 TEST_DESCRIPTION(
19972 "Two command buffers, each in a separate QueueSubmit call "
19973 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019974
19975 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019976 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019977
19978 m_errorMonitor->ExpectSuccess();
19979
19980 VkSemaphore semaphore;
19981 VkSemaphoreCreateInfo semaphore_create_info{};
19982 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19983 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19984
19985 VkCommandPool command_pool;
19986 VkCommandPoolCreateInfo pool_create_info{};
19987 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19988 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19989 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19990 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19991
19992 VkCommandBuffer command_buffer[2];
19993 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19994 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19995 command_buffer_allocate_info.commandPool = command_pool;
19996 command_buffer_allocate_info.commandBufferCount = 2;
19997 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19998 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19999
20000 VkQueue queue = VK_NULL_HANDLE;
20001 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20002
20003 {
20004 VkCommandBufferBeginInfo begin_info{};
20005 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20006 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20007
20008 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 -070020009 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020010
20011 VkViewport viewport{};
20012 viewport.maxDepth = 1.0f;
20013 viewport.minDepth = 0.0f;
20014 viewport.width = 512;
20015 viewport.height = 512;
20016 viewport.x = 0;
20017 viewport.y = 0;
20018 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20019 vkEndCommandBuffer(command_buffer[0]);
20020 }
20021 {
20022 VkCommandBufferBeginInfo begin_info{};
20023 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20024 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20025
20026 VkViewport viewport{};
20027 viewport.maxDepth = 1.0f;
20028 viewport.minDepth = 0.0f;
20029 viewport.width = 512;
20030 viewport.height = 512;
20031 viewport.x = 0;
20032 viewport.y = 0;
20033 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20034 vkEndCommandBuffer(command_buffer[1]);
20035 }
20036 {
20037 VkSubmitInfo submit_info{};
20038 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20039 submit_info.commandBufferCount = 1;
20040 submit_info.pCommandBuffers = &command_buffer[0];
20041 submit_info.signalSemaphoreCount = 1;
20042 submit_info.pSignalSemaphores = &semaphore;
20043 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20044 }
20045 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020046 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020047 VkSubmitInfo submit_info{};
20048 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20049 submit_info.commandBufferCount = 1;
20050 submit_info.pCommandBuffers = &command_buffer[1];
20051 submit_info.waitSemaphoreCount = 1;
20052 submit_info.pWaitSemaphores = &semaphore;
20053 submit_info.pWaitDstStageMask = flags;
20054 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20055 }
20056
20057 vkQueueWaitIdle(m_device->m_queue);
20058
20059 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20060 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20061 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20062
20063 m_errorMonitor->VerifyNotFound();
20064}
20065
20066// This is a positive test. No errors should be generated.
20067TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020068 TEST_DESCRIPTION(
20069 "Two command buffers, each in a separate QueueSubmit call "
20070 "submitted on separate queues, the second having a fence"
20071 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020072
20073 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020074 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020075
20076 m_errorMonitor->ExpectSuccess();
20077
20078 VkFence fence;
20079 VkFenceCreateInfo fence_create_info{};
20080 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20081 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20082
20083 VkSemaphore semaphore;
20084 VkSemaphoreCreateInfo semaphore_create_info{};
20085 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20086 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20087
20088 VkCommandPool command_pool;
20089 VkCommandPoolCreateInfo pool_create_info{};
20090 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20091 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20092 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20093 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20094
20095 VkCommandBuffer command_buffer[2];
20096 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20097 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20098 command_buffer_allocate_info.commandPool = command_pool;
20099 command_buffer_allocate_info.commandBufferCount = 2;
20100 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20101 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20102
20103 VkQueue queue = VK_NULL_HANDLE;
20104 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20105
20106 {
20107 VkCommandBufferBeginInfo begin_info{};
20108 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20109 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20110
20111 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 -070020112 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020113
20114 VkViewport viewport{};
20115 viewport.maxDepth = 1.0f;
20116 viewport.minDepth = 0.0f;
20117 viewport.width = 512;
20118 viewport.height = 512;
20119 viewport.x = 0;
20120 viewport.y = 0;
20121 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20122 vkEndCommandBuffer(command_buffer[0]);
20123 }
20124 {
20125 VkCommandBufferBeginInfo begin_info{};
20126 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20127 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20128
20129 VkViewport viewport{};
20130 viewport.maxDepth = 1.0f;
20131 viewport.minDepth = 0.0f;
20132 viewport.width = 512;
20133 viewport.height = 512;
20134 viewport.x = 0;
20135 viewport.y = 0;
20136 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20137 vkEndCommandBuffer(command_buffer[1]);
20138 }
20139 {
20140 VkSubmitInfo submit_info{};
20141 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20142 submit_info.commandBufferCount = 1;
20143 submit_info.pCommandBuffers = &command_buffer[0];
20144 submit_info.signalSemaphoreCount = 1;
20145 submit_info.pSignalSemaphores = &semaphore;
20146 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20147 }
20148 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020149 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020150 VkSubmitInfo submit_info{};
20151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20152 submit_info.commandBufferCount = 1;
20153 submit_info.pCommandBuffers = &command_buffer[1];
20154 submit_info.waitSemaphoreCount = 1;
20155 submit_info.pWaitSemaphores = &semaphore;
20156 submit_info.pWaitDstStageMask = flags;
20157 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20158 }
20159
20160 vkQueueWaitIdle(m_device->m_queue);
20161
20162 vkDestroyFence(m_device->device(), fence, nullptr);
20163 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20164 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20165 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20166
20167 m_errorMonitor->VerifyNotFound();
20168}
20169
20170// This is a positive test. No errors should be generated.
20171TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020172 TEST_DESCRIPTION(
20173 "Two command buffers, each in a separate QueueSubmit call "
20174 "submitted on separate queues, the second having a fence"
20175 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020176
20177 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020178 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020179
20180 m_errorMonitor->ExpectSuccess();
20181
20182 VkFence fence;
20183 VkFenceCreateInfo fence_create_info{};
20184 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20185 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20186
20187 VkSemaphore semaphore;
20188 VkSemaphoreCreateInfo semaphore_create_info{};
20189 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20190 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20191
20192 VkCommandPool command_pool;
20193 VkCommandPoolCreateInfo pool_create_info{};
20194 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20195 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20196 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20197 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20198
20199 VkCommandBuffer command_buffer[2];
20200 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20201 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20202 command_buffer_allocate_info.commandPool = command_pool;
20203 command_buffer_allocate_info.commandBufferCount = 2;
20204 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20205 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20206
20207 VkQueue queue = VK_NULL_HANDLE;
20208 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20209
20210 {
20211 VkCommandBufferBeginInfo begin_info{};
20212 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20213 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20214
20215 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 -070020216 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020217
20218 VkViewport viewport{};
20219 viewport.maxDepth = 1.0f;
20220 viewport.minDepth = 0.0f;
20221 viewport.width = 512;
20222 viewport.height = 512;
20223 viewport.x = 0;
20224 viewport.y = 0;
20225 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20226 vkEndCommandBuffer(command_buffer[0]);
20227 }
20228 {
20229 VkCommandBufferBeginInfo begin_info{};
20230 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20231 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20232
20233 VkViewport viewport{};
20234 viewport.maxDepth = 1.0f;
20235 viewport.minDepth = 0.0f;
20236 viewport.width = 512;
20237 viewport.height = 512;
20238 viewport.x = 0;
20239 viewport.y = 0;
20240 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20241 vkEndCommandBuffer(command_buffer[1]);
20242 }
20243 {
20244 VkSubmitInfo submit_info{};
20245 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20246 submit_info.commandBufferCount = 1;
20247 submit_info.pCommandBuffers = &command_buffer[0];
20248 submit_info.signalSemaphoreCount = 1;
20249 submit_info.pSignalSemaphores = &semaphore;
20250 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20251 }
20252 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020253 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020254 VkSubmitInfo submit_info{};
20255 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20256 submit_info.commandBufferCount = 1;
20257 submit_info.pCommandBuffers = &command_buffer[1];
20258 submit_info.waitSemaphoreCount = 1;
20259 submit_info.pWaitSemaphores = &semaphore;
20260 submit_info.pWaitDstStageMask = flags;
20261 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20262 }
20263
20264 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20265 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20266
20267 vkDestroyFence(m_device->device(), fence, nullptr);
20268 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20269 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20270 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20271
20272 m_errorMonitor->VerifyNotFound();
20273}
20274
20275TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020276 ASSERT_NO_FATAL_FAILURE(InitState());
20277 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020278 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020279 return;
20280 }
20281
20282 VkResult err;
20283
20284 m_errorMonitor->ExpectSuccess();
20285
20286 VkQueue q0 = m_device->m_queue;
20287 VkQueue q1 = nullptr;
20288 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20289 ASSERT_NE(q1, nullptr);
20290
20291 // An (empty) command buffer. We must have work in the first submission --
20292 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020293 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020294 VkCommandPool pool;
20295 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20296 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020297 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20298 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020299 VkCommandBuffer cb;
20300 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20301 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020302 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020303 err = vkBeginCommandBuffer(cb, &cbbi);
20304 ASSERT_VK_SUCCESS(err);
20305 err = vkEndCommandBuffer(cb);
20306 ASSERT_VK_SUCCESS(err);
20307
20308 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020309 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020310 VkSemaphore s;
20311 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20312 ASSERT_VK_SUCCESS(err);
20313
20314 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020315 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020316
20317 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20318 ASSERT_VK_SUCCESS(err);
20319
20320 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020321 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020322 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020323
20324 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20325 ASSERT_VK_SUCCESS(err);
20326
20327 // Wait for q0 idle
20328 err = vkQueueWaitIdle(q0);
20329 ASSERT_VK_SUCCESS(err);
20330
20331 // Command buffer should have been completed (it was on q0); reset the pool.
20332 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20333
20334 m_errorMonitor->VerifyNotFound();
20335
20336 // Force device completely idle and clean up resources
20337 vkDeviceWaitIdle(m_device->device());
20338 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20339 vkDestroySemaphore(m_device->device(), s, nullptr);
20340}
20341
20342// This is a positive test. No errors should be generated.
20343TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020344 TEST_DESCRIPTION(
20345 "Two command buffers, each in a separate QueueSubmit call "
20346 "submitted on separate queues, the second having a fence, "
20347 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020348
20349 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020350 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020351
20352 m_errorMonitor->ExpectSuccess();
20353
20354 ASSERT_NO_FATAL_FAILURE(InitState());
20355 VkFence fence;
20356 VkFenceCreateInfo fence_create_info{};
20357 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20358 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20359
20360 VkSemaphore semaphore;
20361 VkSemaphoreCreateInfo semaphore_create_info{};
20362 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20363 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20364
20365 VkCommandPool command_pool;
20366 VkCommandPoolCreateInfo pool_create_info{};
20367 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20368 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20369 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20370 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20371
20372 VkCommandBuffer command_buffer[2];
20373 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20374 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20375 command_buffer_allocate_info.commandPool = command_pool;
20376 command_buffer_allocate_info.commandBufferCount = 2;
20377 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20378 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20379
20380 VkQueue queue = VK_NULL_HANDLE;
20381 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20382
20383 {
20384 VkCommandBufferBeginInfo begin_info{};
20385 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20386 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20387
20388 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 -070020389 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020390
20391 VkViewport viewport{};
20392 viewport.maxDepth = 1.0f;
20393 viewport.minDepth = 0.0f;
20394 viewport.width = 512;
20395 viewport.height = 512;
20396 viewport.x = 0;
20397 viewport.y = 0;
20398 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20399 vkEndCommandBuffer(command_buffer[0]);
20400 }
20401 {
20402 VkCommandBufferBeginInfo begin_info{};
20403 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20404 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20405
20406 VkViewport viewport{};
20407 viewport.maxDepth = 1.0f;
20408 viewport.minDepth = 0.0f;
20409 viewport.width = 512;
20410 viewport.height = 512;
20411 viewport.x = 0;
20412 viewport.y = 0;
20413 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20414 vkEndCommandBuffer(command_buffer[1]);
20415 }
20416 {
20417 VkSubmitInfo submit_info{};
20418 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20419 submit_info.commandBufferCount = 1;
20420 submit_info.pCommandBuffers = &command_buffer[0];
20421 submit_info.signalSemaphoreCount = 1;
20422 submit_info.pSignalSemaphores = &semaphore;
20423 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20424 }
20425 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020426 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020427 VkSubmitInfo submit_info{};
20428 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20429 submit_info.commandBufferCount = 1;
20430 submit_info.pCommandBuffers = &command_buffer[1];
20431 submit_info.waitSemaphoreCount = 1;
20432 submit_info.pWaitSemaphores = &semaphore;
20433 submit_info.pWaitDstStageMask = flags;
20434 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20435 }
20436
20437 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20438
20439 vkDestroyFence(m_device->device(), fence, nullptr);
20440 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20441 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20442 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20443
20444 m_errorMonitor->VerifyNotFound();
20445}
20446
20447// This is a positive test. No errors should be generated.
20448TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020449 TEST_DESCRIPTION(
20450 "Two command buffers, each in a separate QueueSubmit call "
20451 "on the same queue, sharing a signal/wait semaphore, the "
20452 "second having a fence, "
20453 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020454
20455 m_errorMonitor->ExpectSuccess();
20456
20457 ASSERT_NO_FATAL_FAILURE(InitState());
20458 VkFence fence;
20459 VkFenceCreateInfo fence_create_info{};
20460 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20461 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20462
20463 VkSemaphore semaphore;
20464 VkSemaphoreCreateInfo semaphore_create_info{};
20465 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20466 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20467
20468 VkCommandPool command_pool;
20469 VkCommandPoolCreateInfo pool_create_info{};
20470 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20471 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20472 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20473 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20474
20475 VkCommandBuffer command_buffer[2];
20476 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20477 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20478 command_buffer_allocate_info.commandPool = command_pool;
20479 command_buffer_allocate_info.commandBufferCount = 2;
20480 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20481 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20482
20483 {
20484 VkCommandBufferBeginInfo begin_info{};
20485 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20486 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20487
20488 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 -070020489 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020490
20491 VkViewport viewport{};
20492 viewport.maxDepth = 1.0f;
20493 viewport.minDepth = 0.0f;
20494 viewport.width = 512;
20495 viewport.height = 512;
20496 viewport.x = 0;
20497 viewport.y = 0;
20498 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20499 vkEndCommandBuffer(command_buffer[0]);
20500 }
20501 {
20502 VkCommandBufferBeginInfo begin_info{};
20503 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20504 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20505
20506 VkViewport viewport{};
20507 viewport.maxDepth = 1.0f;
20508 viewport.minDepth = 0.0f;
20509 viewport.width = 512;
20510 viewport.height = 512;
20511 viewport.x = 0;
20512 viewport.y = 0;
20513 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20514 vkEndCommandBuffer(command_buffer[1]);
20515 }
20516 {
20517 VkSubmitInfo submit_info{};
20518 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20519 submit_info.commandBufferCount = 1;
20520 submit_info.pCommandBuffers = &command_buffer[0];
20521 submit_info.signalSemaphoreCount = 1;
20522 submit_info.pSignalSemaphores = &semaphore;
20523 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20524 }
20525 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020526 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020527 VkSubmitInfo submit_info{};
20528 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20529 submit_info.commandBufferCount = 1;
20530 submit_info.pCommandBuffers = &command_buffer[1];
20531 submit_info.waitSemaphoreCount = 1;
20532 submit_info.pWaitSemaphores = &semaphore;
20533 submit_info.pWaitDstStageMask = flags;
20534 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20535 }
20536
20537 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20538
20539 vkDestroyFence(m_device->device(), fence, nullptr);
20540 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20541 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20542 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20543
20544 m_errorMonitor->VerifyNotFound();
20545}
20546
20547// This is a positive test. No errors should be generated.
20548TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020549 TEST_DESCRIPTION(
20550 "Two command buffers, each in a separate QueueSubmit call "
20551 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20552 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020553
20554 m_errorMonitor->ExpectSuccess();
20555
20556 ASSERT_NO_FATAL_FAILURE(InitState());
20557 VkFence fence;
20558 VkFenceCreateInfo fence_create_info{};
20559 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20560 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20561
20562 VkCommandPool command_pool;
20563 VkCommandPoolCreateInfo pool_create_info{};
20564 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20565 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20566 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20567 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20568
20569 VkCommandBuffer command_buffer[2];
20570 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20571 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20572 command_buffer_allocate_info.commandPool = command_pool;
20573 command_buffer_allocate_info.commandBufferCount = 2;
20574 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20575 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20576
20577 {
20578 VkCommandBufferBeginInfo begin_info{};
20579 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20580 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20581
20582 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 -070020583 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020584
20585 VkViewport viewport{};
20586 viewport.maxDepth = 1.0f;
20587 viewport.minDepth = 0.0f;
20588 viewport.width = 512;
20589 viewport.height = 512;
20590 viewport.x = 0;
20591 viewport.y = 0;
20592 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20593 vkEndCommandBuffer(command_buffer[0]);
20594 }
20595 {
20596 VkCommandBufferBeginInfo begin_info{};
20597 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20598 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20599
20600 VkViewport viewport{};
20601 viewport.maxDepth = 1.0f;
20602 viewport.minDepth = 0.0f;
20603 viewport.width = 512;
20604 viewport.height = 512;
20605 viewport.x = 0;
20606 viewport.y = 0;
20607 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20608 vkEndCommandBuffer(command_buffer[1]);
20609 }
20610 {
20611 VkSubmitInfo submit_info{};
20612 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20613 submit_info.commandBufferCount = 1;
20614 submit_info.pCommandBuffers = &command_buffer[0];
20615 submit_info.signalSemaphoreCount = 0;
20616 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20617 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20618 }
20619 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020620 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020621 VkSubmitInfo submit_info{};
20622 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20623 submit_info.commandBufferCount = 1;
20624 submit_info.pCommandBuffers = &command_buffer[1];
20625 submit_info.waitSemaphoreCount = 0;
20626 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20627 submit_info.pWaitDstStageMask = flags;
20628 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20629 }
20630
20631 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20632
20633 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20634 ASSERT_VK_SUCCESS(err);
20635
20636 vkDestroyFence(m_device->device(), fence, nullptr);
20637 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20638 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20639
20640 m_errorMonitor->VerifyNotFound();
20641}
20642
20643// This is a positive test. No errors should be generated.
20644TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020645 TEST_DESCRIPTION(
20646 "Two command buffers, each in a separate QueueSubmit call "
20647 "on the same queue, the second having a fence, followed "
20648 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020649
20650 m_errorMonitor->ExpectSuccess();
20651
20652 ASSERT_NO_FATAL_FAILURE(InitState());
20653 VkFence fence;
20654 VkFenceCreateInfo fence_create_info{};
20655 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20656 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20657
20658 VkCommandPool command_pool;
20659 VkCommandPoolCreateInfo pool_create_info{};
20660 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20661 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20662 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20663 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20664
20665 VkCommandBuffer command_buffer[2];
20666 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20667 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20668 command_buffer_allocate_info.commandPool = command_pool;
20669 command_buffer_allocate_info.commandBufferCount = 2;
20670 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20671 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20672
20673 {
20674 VkCommandBufferBeginInfo begin_info{};
20675 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20676 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20677
20678 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 -070020679 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020680
20681 VkViewport viewport{};
20682 viewport.maxDepth = 1.0f;
20683 viewport.minDepth = 0.0f;
20684 viewport.width = 512;
20685 viewport.height = 512;
20686 viewport.x = 0;
20687 viewport.y = 0;
20688 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20689 vkEndCommandBuffer(command_buffer[0]);
20690 }
20691 {
20692 VkCommandBufferBeginInfo begin_info{};
20693 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20694 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20695
20696 VkViewport viewport{};
20697 viewport.maxDepth = 1.0f;
20698 viewport.minDepth = 0.0f;
20699 viewport.width = 512;
20700 viewport.height = 512;
20701 viewport.x = 0;
20702 viewport.y = 0;
20703 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20704 vkEndCommandBuffer(command_buffer[1]);
20705 }
20706 {
20707 VkSubmitInfo submit_info{};
20708 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20709 submit_info.commandBufferCount = 1;
20710 submit_info.pCommandBuffers = &command_buffer[0];
20711 submit_info.signalSemaphoreCount = 0;
20712 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20713 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20714 }
20715 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020716 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020717 VkSubmitInfo submit_info{};
20718 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20719 submit_info.commandBufferCount = 1;
20720 submit_info.pCommandBuffers = &command_buffer[1];
20721 submit_info.waitSemaphoreCount = 0;
20722 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20723 submit_info.pWaitDstStageMask = flags;
20724 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20725 }
20726
20727 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20728
20729 vkDestroyFence(m_device->device(), fence, nullptr);
20730 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20731 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20732
20733 m_errorMonitor->VerifyNotFound();
20734}
20735
20736// This is a positive test. No errors should be generated.
20737TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020738 TEST_DESCRIPTION(
20739 "Two command buffers each in a separate SubmitInfo sent in a single "
20740 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020741 ASSERT_NO_FATAL_FAILURE(InitState());
20742
20743 m_errorMonitor->ExpectSuccess();
20744
20745 VkFence fence;
20746 VkFenceCreateInfo fence_create_info{};
20747 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20748 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20749
20750 VkSemaphore semaphore;
20751 VkSemaphoreCreateInfo semaphore_create_info{};
20752 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20753 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20754
20755 VkCommandPool command_pool;
20756 VkCommandPoolCreateInfo pool_create_info{};
20757 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20758 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20759 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20760 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20761
20762 VkCommandBuffer command_buffer[2];
20763 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20764 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20765 command_buffer_allocate_info.commandPool = command_pool;
20766 command_buffer_allocate_info.commandBufferCount = 2;
20767 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20768 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20769
20770 {
20771 VkCommandBufferBeginInfo begin_info{};
20772 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20773 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20774
20775 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 -070020776 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020777
20778 VkViewport viewport{};
20779 viewport.maxDepth = 1.0f;
20780 viewport.minDepth = 0.0f;
20781 viewport.width = 512;
20782 viewport.height = 512;
20783 viewport.x = 0;
20784 viewport.y = 0;
20785 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20786 vkEndCommandBuffer(command_buffer[0]);
20787 }
20788 {
20789 VkCommandBufferBeginInfo begin_info{};
20790 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20791 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20792
20793 VkViewport viewport{};
20794 viewport.maxDepth = 1.0f;
20795 viewport.minDepth = 0.0f;
20796 viewport.width = 512;
20797 viewport.height = 512;
20798 viewport.x = 0;
20799 viewport.y = 0;
20800 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20801 vkEndCommandBuffer(command_buffer[1]);
20802 }
20803 {
20804 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020805 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020806
20807 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20808 submit_info[0].pNext = NULL;
20809 submit_info[0].commandBufferCount = 1;
20810 submit_info[0].pCommandBuffers = &command_buffer[0];
20811 submit_info[0].signalSemaphoreCount = 1;
20812 submit_info[0].pSignalSemaphores = &semaphore;
20813 submit_info[0].waitSemaphoreCount = 0;
20814 submit_info[0].pWaitSemaphores = NULL;
20815 submit_info[0].pWaitDstStageMask = 0;
20816
20817 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20818 submit_info[1].pNext = NULL;
20819 submit_info[1].commandBufferCount = 1;
20820 submit_info[1].pCommandBuffers = &command_buffer[1];
20821 submit_info[1].waitSemaphoreCount = 1;
20822 submit_info[1].pWaitSemaphores = &semaphore;
20823 submit_info[1].pWaitDstStageMask = flags;
20824 submit_info[1].signalSemaphoreCount = 0;
20825 submit_info[1].pSignalSemaphores = NULL;
20826 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
20827 }
20828
20829 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20830
20831 vkDestroyFence(m_device->device(), fence, nullptr);
20832 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20833 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20834 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20835
20836 m_errorMonitor->VerifyNotFound();
20837}
20838
20839TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
20840 m_errorMonitor->ExpectSuccess();
20841
20842 ASSERT_NO_FATAL_FAILURE(InitState());
20843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20844
Tony Barbour552f6c02016-12-21 14:34:07 -070020845 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020846
20847 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
20848 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20849 m_errorMonitor->VerifyNotFound();
20850 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
20851 m_errorMonitor->VerifyNotFound();
20852 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20853 m_errorMonitor->VerifyNotFound();
20854
20855 m_commandBuffer->EndCommandBuffer();
20856 m_errorMonitor->VerifyNotFound();
20857}
20858
20859TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020860 TEST_DESCRIPTION(
20861 "Positive test where we create a renderpass with an "
20862 "attachment that uses LOAD_OP_CLEAR, the first subpass "
20863 "has a valid layout, and a second subpass then uses a "
20864 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020865 m_errorMonitor->ExpectSuccess();
20866 ASSERT_NO_FATAL_FAILURE(InitState());
20867
20868 VkAttachmentReference attach[2] = {};
20869 attach[0].attachment = 0;
20870 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20871 attach[1].attachment = 0;
20872 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20873 VkSubpassDescription subpasses[2] = {};
20874 // First subpass clears DS attach on load
20875 subpasses[0].pDepthStencilAttachment = &attach[0];
20876 // 2nd subpass reads in DS as input attachment
20877 subpasses[1].inputAttachmentCount = 1;
20878 subpasses[1].pInputAttachments = &attach[1];
20879 VkAttachmentDescription attach_desc = {};
20880 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
20881 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
20882 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
20883 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20884 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20885 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20886 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20887 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20888 VkRenderPassCreateInfo rpci = {};
20889 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20890 rpci.attachmentCount = 1;
20891 rpci.pAttachments = &attach_desc;
20892 rpci.subpassCount = 2;
20893 rpci.pSubpasses = subpasses;
20894
20895 // Now create RenderPass and verify no errors
20896 VkRenderPass rp;
20897 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
20898 m_errorMonitor->VerifyNotFound();
20899
20900 vkDestroyRenderPass(m_device->device(), rp, NULL);
20901}
20902
20903TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020904 TEST_DESCRIPTION(
20905 "Test that pipeline validation accepts matrices passed "
20906 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020907 m_errorMonitor->ExpectSuccess();
20908
20909 ASSERT_NO_FATAL_FAILURE(InitState());
20910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20911
20912 VkVertexInputBindingDescription input_binding;
20913 memset(&input_binding, 0, sizeof(input_binding));
20914
20915 VkVertexInputAttributeDescription input_attribs[2];
20916 memset(input_attribs, 0, sizeof(input_attribs));
20917
20918 for (int i = 0; i < 2; i++) {
20919 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20920 input_attribs[i].location = i;
20921 }
20922
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020923 char const *vsSource =
20924 "#version 450\n"
20925 "\n"
20926 "layout(location=0) in mat2x4 x;\n"
20927 "out gl_PerVertex {\n"
20928 " vec4 gl_Position;\n"
20929 "};\n"
20930 "void main(){\n"
20931 " gl_Position = x[0] + x[1];\n"
20932 "}\n";
20933 char const *fsSource =
20934 "#version 450\n"
20935 "\n"
20936 "layout(location=0) out vec4 color;\n"
20937 "void main(){\n"
20938 " color = vec4(1);\n"
20939 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020940
20941 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20942 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20943
20944 VkPipelineObj pipe(m_device);
20945 pipe.AddColorAttachment();
20946 pipe.AddShader(&vs);
20947 pipe.AddShader(&fs);
20948
20949 pipe.AddVertexInputBindings(&input_binding, 1);
20950 pipe.AddVertexInputAttribs(input_attribs, 2);
20951
20952 VkDescriptorSetObj descriptorSet(m_device);
20953 descriptorSet.AppendDummy();
20954 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20955
20956 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20957
20958 /* expect success */
20959 m_errorMonitor->VerifyNotFound();
20960}
20961
20962TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
20963 m_errorMonitor->ExpectSuccess();
20964
20965 ASSERT_NO_FATAL_FAILURE(InitState());
20966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20967
20968 VkVertexInputBindingDescription input_binding;
20969 memset(&input_binding, 0, sizeof(input_binding));
20970
20971 VkVertexInputAttributeDescription input_attribs[2];
20972 memset(input_attribs, 0, sizeof(input_attribs));
20973
20974 for (int i = 0; i < 2; i++) {
20975 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20976 input_attribs[i].location = i;
20977 }
20978
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020979 char const *vsSource =
20980 "#version 450\n"
20981 "\n"
20982 "layout(location=0) in vec4 x[2];\n"
20983 "out gl_PerVertex {\n"
20984 " vec4 gl_Position;\n"
20985 "};\n"
20986 "void main(){\n"
20987 " gl_Position = x[0] + x[1];\n"
20988 "}\n";
20989 char const *fsSource =
20990 "#version 450\n"
20991 "\n"
20992 "layout(location=0) out vec4 color;\n"
20993 "void main(){\n"
20994 " color = vec4(1);\n"
20995 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020996
20997 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20998 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20999
21000 VkPipelineObj pipe(m_device);
21001 pipe.AddColorAttachment();
21002 pipe.AddShader(&vs);
21003 pipe.AddShader(&fs);
21004
21005 pipe.AddVertexInputBindings(&input_binding, 1);
21006 pipe.AddVertexInputAttribs(input_attribs, 2);
21007
21008 VkDescriptorSetObj descriptorSet(m_device);
21009 descriptorSet.AppendDummy();
21010 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21011
21012 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21013
21014 m_errorMonitor->VerifyNotFound();
21015}
21016
21017TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021018 TEST_DESCRIPTION(
21019 "Test that pipeline validation accepts consuming a vertex attribute "
21020 "through multiple vertex shader inputs, each consuming a different "
21021 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021022 m_errorMonitor->ExpectSuccess();
21023
21024 ASSERT_NO_FATAL_FAILURE(InitState());
21025 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21026
21027 VkVertexInputBindingDescription input_binding;
21028 memset(&input_binding, 0, sizeof(input_binding));
21029
21030 VkVertexInputAttributeDescription input_attribs[3];
21031 memset(input_attribs, 0, sizeof(input_attribs));
21032
21033 for (int i = 0; i < 3; i++) {
21034 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21035 input_attribs[i].location = i;
21036 }
21037
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021038 char const *vsSource =
21039 "#version 450\n"
21040 "\n"
21041 "layout(location=0) in vec4 x;\n"
21042 "layout(location=1) in vec3 y1;\n"
21043 "layout(location=1, component=3) in float y2;\n"
21044 "layout(location=2) in vec4 z;\n"
21045 "out gl_PerVertex {\n"
21046 " vec4 gl_Position;\n"
21047 "};\n"
21048 "void main(){\n"
21049 " gl_Position = x + vec4(y1, y2) + z;\n"
21050 "}\n";
21051 char const *fsSource =
21052 "#version 450\n"
21053 "\n"
21054 "layout(location=0) out vec4 color;\n"
21055 "void main(){\n"
21056 " color = vec4(1);\n"
21057 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021058
21059 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21060 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21061
21062 VkPipelineObj pipe(m_device);
21063 pipe.AddColorAttachment();
21064 pipe.AddShader(&vs);
21065 pipe.AddShader(&fs);
21066
21067 pipe.AddVertexInputBindings(&input_binding, 1);
21068 pipe.AddVertexInputAttribs(input_attribs, 3);
21069
21070 VkDescriptorSetObj descriptorSet(m_device);
21071 descriptorSet.AppendDummy();
21072 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21073
21074 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21075
21076 m_errorMonitor->VerifyNotFound();
21077}
21078
21079TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21080 m_errorMonitor->ExpectSuccess();
21081
21082 ASSERT_NO_FATAL_FAILURE(InitState());
21083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21084
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021085 char const *vsSource =
21086 "#version 450\n"
21087 "out gl_PerVertex {\n"
21088 " vec4 gl_Position;\n"
21089 "};\n"
21090 "void main(){\n"
21091 " gl_Position = vec4(0);\n"
21092 "}\n";
21093 char const *fsSource =
21094 "#version 450\n"
21095 "\n"
21096 "layout(location=0) out vec4 color;\n"
21097 "void main(){\n"
21098 " color = vec4(1);\n"
21099 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021100
21101 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21102 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21103
21104 VkPipelineObj pipe(m_device);
21105 pipe.AddColorAttachment();
21106 pipe.AddShader(&vs);
21107 pipe.AddShader(&fs);
21108
21109 VkDescriptorSetObj descriptorSet(m_device);
21110 descriptorSet.AppendDummy();
21111 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21112
21113 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21114
21115 m_errorMonitor->VerifyNotFound();
21116}
21117
21118TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021119 TEST_DESCRIPTION(
21120 "Test that pipeline validation accepts the relaxed type matching rules "
21121 "set out in 14.1.3: fundamental type must match, and producer side must "
21122 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021123 m_errorMonitor->ExpectSuccess();
21124
21125 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21126
21127 ASSERT_NO_FATAL_FAILURE(InitState());
21128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21129
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021130 char const *vsSource =
21131 "#version 450\n"
21132 "out gl_PerVertex {\n"
21133 " vec4 gl_Position;\n"
21134 "};\n"
21135 "layout(location=0) out vec3 x;\n"
21136 "layout(location=1) out ivec3 y;\n"
21137 "layout(location=2) out vec3 z;\n"
21138 "void main(){\n"
21139 " gl_Position = vec4(0);\n"
21140 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21141 "}\n";
21142 char const *fsSource =
21143 "#version 450\n"
21144 "\n"
21145 "layout(location=0) out vec4 color;\n"
21146 "layout(location=0) in float x;\n"
21147 "layout(location=1) flat in int y;\n"
21148 "layout(location=2) in vec2 z;\n"
21149 "void main(){\n"
21150 " color = vec4(1 + x + y + z.x);\n"
21151 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021152
21153 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21154 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21155
21156 VkPipelineObj pipe(m_device);
21157 pipe.AddColorAttachment();
21158 pipe.AddShader(&vs);
21159 pipe.AddShader(&fs);
21160
21161 VkDescriptorSetObj descriptorSet(m_device);
21162 descriptorSet.AppendDummy();
21163 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21164
21165 VkResult err = VK_SUCCESS;
21166 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21167 ASSERT_VK_SUCCESS(err);
21168
21169 m_errorMonitor->VerifyNotFound();
21170}
21171
21172TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021173 TEST_DESCRIPTION(
21174 "Test that pipeline validation accepts per-vertex variables "
21175 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021176 m_errorMonitor->ExpectSuccess();
21177
21178 ASSERT_NO_FATAL_FAILURE(InitState());
21179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21180
21181 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021182 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021183 return;
21184 }
21185
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021186 char const *vsSource =
21187 "#version 450\n"
21188 "void main(){}\n";
21189 char const *tcsSource =
21190 "#version 450\n"
21191 "layout(location=0) out int x[];\n"
21192 "layout(vertices=3) out;\n"
21193 "void main(){\n"
21194 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21195 " gl_TessLevelInner[0] = 1;\n"
21196 " x[gl_InvocationID] = gl_InvocationID;\n"
21197 "}\n";
21198 char const *tesSource =
21199 "#version 450\n"
21200 "layout(triangles, equal_spacing, cw) in;\n"
21201 "layout(location=0) in int x[];\n"
21202 "out gl_PerVertex { vec4 gl_Position; };\n"
21203 "void main(){\n"
21204 " gl_Position.xyz = gl_TessCoord;\n"
21205 " gl_Position.w = x[0] + x[1] + x[2];\n"
21206 "}\n";
21207 char const *fsSource =
21208 "#version 450\n"
21209 "layout(location=0) out vec4 color;\n"
21210 "void main(){\n"
21211 " color = vec4(1);\n"
21212 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021213
21214 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21215 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21216 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21217 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21218
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021219 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21220 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021221
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021222 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021223
21224 VkPipelineObj pipe(m_device);
21225 pipe.SetInputAssembly(&iasci);
21226 pipe.SetTessellation(&tsci);
21227 pipe.AddColorAttachment();
21228 pipe.AddShader(&vs);
21229 pipe.AddShader(&tcs);
21230 pipe.AddShader(&tes);
21231 pipe.AddShader(&fs);
21232
21233 VkDescriptorSetObj descriptorSet(m_device);
21234 descriptorSet.AppendDummy();
21235 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21236
21237 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21238
21239 m_errorMonitor->VerifyNotFound();
21240}
21241
21242TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021243 TEST_DESCRIPTION(
21244 "Test that pipeline validation accepts a user-defined "
21245 "interface block passed into the geometry shader. This "
21246 "is interesting because the 'extra' array level is not "
21247 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021248 m_errorMonitor->ExpectSuccess();
21249
21250 ASSERT_NO_FATAL_FAILURE(InitState());
21251 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21252
21253 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021254 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021255 return;
21256 }
21257
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021258 char const *vsSource =
21259 "#version 450\n"
21260 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21261 "void main(){\n"
21262 " vs_out.x = vec4(1);\n"
21263 "}\n";
21264 char const *gsSource =
21265 "#version 450\n"
21266 "layout(triangles) in;\n"
21267 "layout(triangle_strip, max_vertices=3) out;\n"
21268 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21269 "out gl_PerVertex { vec4 gl_Position; };\n"
21270 "void main() {\n"
21271 " gl_Position = gs_in[0].x;\n"
21272 " EmitVertex();\n"
21273 "}\n";
21274 char const *fsSource =
21275 "#version 450\n"
21276 "layout(location=0) out vec4 color;\n"
21277 "void main(){\n"
21278 " color = vec4(1);\n"
21279 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021280
21281 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21282 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21283 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21284
21285 VkPipelineObj pipe(m_device);
21286 pipe.AddColorAttachment();
21287 pipe.AddShader(&vs);
21288 pipe.AddShader(&gs);
21289 pipe.AddShader(&fs);
21290
21291 VkDescriptorSetObj descriptorSet(m_device);
21292 descriptorSet.AppendDummy();
21293 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21294
21295 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21296
21297 m_errorMonitor->VerifyNotFound();
21298}
21299
21300TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021301 TEST_DESCRIPTION(
21302 "Test that pipeline validation accepts basic use of 64bit vertex "
21303 "attributes. This is interesting because they consume multiple "
21304 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021305 m_errorMonitor->ExpectSuccess();
21306
21307 ASSERT_NO_FATAL_FAILURE(InitState());
21308 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21309
21310 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021311 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021312 return;
21313 }
21314
21315 VkVertexInputBindingDescription input_bindings[1];
21316 memset(input_bindings, 0, sizeof(input_bindings));
21317
21318 VkVertexInputAttributeDescription input_attribs[4];
21319 memset(input_attribs, 0, sizeof(input_attribs));
21320 input_attribs[0].location = 0;
21321 input_attribs[0].offset = 0;
21322 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21323 input_attribs[1].location = 2;
21324 input_attribs[1].offset = 32;
21325 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21326 input_attribs[2].location = 4;
21327 input_attribs[2].offset = 64;
21328 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21329 input_attribs[3].location = 6;
21330 input_attribs[3].offset = 96;
21331 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21332
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021333 char const *vsSource =
21334 "#version 450\n"
21335 "\n"
21336 "layout(location=0) in dmat4 x;\n"
21337 "out gl_PerVertex {\n"
21338 " vec4 gl_Position;\n"
21339 "};\n"
21340 "void main(){\n"
21341 " gl_Position = vec4(x[0][0]);\n"
21342 "}\n";
21343 char const *fsSource =
21344 "#version 450\n"
21345 "\n"
21346 "layout(location=0) out vec4 color;\n"
21347 "void main(){\n"
21348 " color = vec4(1);\n"
21349 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021350
21351 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21352 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21353
21354 VkPipelineObj pipe(m_device);
21355 pipe.AddColorAttachment();
21356 pipe.AddShader(&vs);
21357 pipe.AddShader(&fs);
21358
21359 pipe.AddVertexInputBindings(input_bindings, 1);
21360 pipe.AddVertexInputAttribs(input_attribs, 4);
21361
21362 VkDescriptorSetObj descriptorSet(m_device);
21363 descriptorSet.AppendDummy();
21364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21365
21366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21367
21368 m_errorMonitor->VerifyNotFound();
21369}
21370
21371TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21372 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21373 m_errorMonitor->ExpectSuccess();
21374
21375 ASSERT_NO_FATAL_FAILURE(InitState());
21376
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021377 char const *vsSource =
21378 "#version 450\n"
21379 "\n"
21380 "out gl_PerVertex {\n"
21381 " vec4 gl_Position;\n"
21382 "};\n"
21383 "void main(){\n"
21384 " gl_Position = vec4(1);\n"
21385 "}\n";
21386 char const *fsSource =
21387 "#version 450\n"
21388 "\n"
21389 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21390 "layout(location=0) out vec4 color;\n"
21391 "void main() {\n"
21392 " color = subpassLoad(x);\n"
21393 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021394
21395 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21396 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21397
21398 VkPipelineObj pipe(m_device);
21399 pipe.AddShader(&vs);
21400 pipe.AddShader(&fs);
21401 pipe.AddColorAttachment();
21402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21403
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021404 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21405 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021406 VkDescriptorSetLayout dsl;
21407 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21408 ASSERT_VK_SUCCESS(err);
21409
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021410 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021411 VkPipelineLayout pl;
21412 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21413 ASSERT_VK_SUCCESS(err);
21414
21415 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021416 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21417 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21418 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21419 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21420 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 -060021421 };
21422 VkAttachmentReference color = {
21423 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21424 };
21425 VkAttachmentReference input = {
21426 1, VK_IMAGE_LAYOUT_GENERAL,
21427 };
21428
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021429 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021430
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021431 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021432 VkRenderPass rp;
21433 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21434 ASSERT_VK_SUCCESS(err);
21435
21436 // should be OK. would go wrong here if it's going to...
21437 pipe.CreateVKPipeline(pl, rp);
21438
21439 m_errorMonitor->VerifyNotFound();
21440
21441 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21442 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21443 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21444}
21445
21446TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021447 TEST_DESCRIPTION(
21448 "Test that pipeline validation accepts a compute pipeline which declares a "
21449 "descriptor-backed resource which is not provided, but the shader does not "
21450 "statically use it. This is interesting because it requires compute pipelines "
21451 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021452 m_errorMonitor->ExpectSuccess();
21453
21454 ASSERT_NO_FATAL_FAILURE(InitState());
21455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021456 char const *csSource =
21457 "#version 450\n"
21458 "\n"
21459 "layout(local_size_x=1) in;\n"
21460 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21461 "void main(){\n"
21462 " // x is not used.\n"
21463 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021464
21465 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21466
21467 VkDescriptorSetObj descriptorSet(m_device);
21468 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21469
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021470 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21471 nullptr,
21472 0,
21473 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21474 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21475 descriptorSet.GetPipelineLayout(),
21476 VK_NULL_HANDLE,
21477 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021478
21479 VkPipeline pipe;
21480 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21481
21482 m_errorMonitor->VerifyNotFound();
21483
21484 if (err == VK_SUCCESS) {
21485 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21486 }
21487}
21488
21489TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021490 TEST_DESCRIPTION(
21491 "Test that pipeline validation accepts a shader consuming only the "
21492 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021493 m_errorMonitor->ExpectSuccess();
21494
21495 ASSERT_NO_FATAL_FAILURE(InitState());
21496
21497 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021498 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21499 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21500 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021501 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021502 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021503 VkDescriptorSetLayout dsl;
21504 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21505 ASSERT_VK_SUCCESS(err);
21506
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021507 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021508 VkPipelineLayout pl;
21509 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21510 ASSERT_VK_SUCCESS(err);
21511
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021512 char const *csSource =
21513 "#version 450\n"
21514 "\n"
21515 "layout(local_size_x=1) in;\n"
21516 "layout(set=0, binding=0) uniform sampler s;\n"
21517 "layout(set=0, binding=1) uniform texture2D t;\n"
21518 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21519 "void main() {\n"
21520 " x = texture(sampler2D(t, s), vec2(0));\n"
21521 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021522 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21523
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021524 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21525 nullptr,
21526 0,
21527 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21528 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21529 pl,
21530 VK_NULL_HANDLE,
21531 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021532
21533 VkPipeline pipe;
21534 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21535
21536 m_errorMonitor->VerifyNotFound();
21537
21538 if (err == VK_SUCCESS) {
21539 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21540 }
21541
21542 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21543 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21544}
21545
21546TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021547 TEST_DESCRIPTION(
21548 "Test that pipeline validation accepts a shader consuming only the "
21549 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021550 m_errorMonitor->ExpectSuccess();
21551
21552 ASSERT_NO_FATAL_FAILURE(InitState());
21553
21554 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021555 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21556 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21557 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021558 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021559 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021560 VkDescriptorSetLayout dsl;
21561 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21562 ASSERT_VK_SUCCESS(err);
21563
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021564 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021565 VkPipelineLayout pl;
21566 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21567 ASSERT_VK_SUCCESS(err);
21568
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021569 char const *csSource =
21570 "#version 450\n"
21571 "\n"
21572 "layout(local_size_x=1) in;\n"
21573 "layout(set=0, binding=0) uniform texture2D t;\n"
21574 "layout(set=0, binding=1) uniform sampler s;\n"
21575 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21576 "void main() {\n"
21577 " x = texture(sampler2D(t, s), vec2(0));\n"
21578 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021579 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21580
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021581 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21582 nullptr,
21583 0,
21584 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21585 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21586 pl,
21587 VK_NULL_HANDLE,
21588 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021589
21590 VkPipeline pipe;
21591 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21592
21593 m_errorMonitor->VerifyNotFound();
21594
21595 if (err == VK_SUCCESS) {
21596 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21597 }
21598
21599 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21600 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21601}
21602
21603TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021604 TEST_DESCRIPTION(
21605 "Test that pipeline validation accepts a shader consuming "
21606 "both the sampler and the image of a combined image+sampler "
21607 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021608 m_errorMonitor->ExpectSuccess();
21609
21610 ASSERT_NO_FATAL_FAILURE(InitState());
21611
21612 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021613 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21614 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021615 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021616 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021617 VkDescriptorSetLayout dsl;
21618 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21619 ASSERT_VK_SUCCESS(err);
21620
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021621 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021622 VkPipelineLayout pl;
21623 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21624 ASSERT_VK_SUCCESS(err);
21625
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021626 char const *csSource =
21627 "#version 450\n"
21628 "\n"
21629 "layout(local_size_x=1) in;\n"
21630 "layout(set=0, binding=0) uniform texture2D t;\n"
21631 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
21632 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
21633 "void main() {\n"
21634 " x = texture(sampler2D(t, s), vec2(0));\n"
21635 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021636 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21637
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021638 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21639 nullptr,
21640 0,
21641 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21642 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21643 pl,
21644 VK_NULL_HANDLE,
21645 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021646
21647 VkPipeline pipe;
21648 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21649
21650 m_errorMonitor->VerifyNotFound();
21651
21652 if (err == VK_SUCCESS) {
21653 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21654 }
21655
21656 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21657 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21658}
21659
21660TEST_F(VkPositiveLayerTest, ValidStructPNext) {
21661 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
21662
21663 ASSERT_NO_FATAL_FAILURE(InitState());
21664
21665 // Positive test to check parameter_validation and unique_objects support
21666 // for NV_dedicated_allocation
21667 uint32_t extension_count = 0;
21668 bool supports_nv_dedicated_allocation = false;
21669 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
21670 ASSERT_VK_SUCCESS(err);
21671
21672 if (extension_count > 0) {
21673 std::vector<VkExtensionProperties> available_extensions(extension_count);
21674
21675 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
21676 ASSERT_VK_SUCCESS(err);
21677
21678 for (const auto &extension_props : available_extensions) {
21679 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
21680 supports_nv_dedicated_allocation = true;
21681 }
21682 }
21683 }
21684
21685 if (supports_nv_dedicated_allocation) {
21686 m_errorMonitor->ExpectSuccess();
21687
21688 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
21689 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
21690 dedicated_buffer_create_info.pNext = nullptr;
21691 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
21692
21693 uint32_t queue_family_index = 0;
21694 VkBufferCreateInfo buffer_create_info = {};
21695 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21696 buffer_create_info.pNext = &dedicated_buffer_create_info;
21697 buffer_create_info.size = 1024;
21698 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
21699 buffer_create_info.queueFamilyIndexCount = 1;
21700 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
21701
21702 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070021703 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021704 ASSERT_VK_SUCCESS(err);
21705
21706 VkMemoryRequirements memory_reqs;
21707 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
21708
21709 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
21710 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
21711 dedicated_memory_info.pNext = nullptr;
21712 dedicated_memory_info.buffer = buffer;
21713 dedicated_memory_info.image = VK_NULL_HANDLE;
21714
21715 VkMemoryAllocateInfo memory_info = {};
21716 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21717 memory_info.pNext = &dedicated_memory_info;
21718 memory_info.allocationSize = memory_reqs.size;
21719
21720 bool pass;
21721 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
21722 ASSERT_TRUE(pass);
21723
21724 VkDeviceMemory buffer_memory;
21725 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
21726 ASSERT_VK_SUCCESS(err);
21727
21728 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
21729 ASSERT_VK_SUCCESS(err);
21730
21731 vkDestroyBuffer(m_device->device(), buffer, NULL);
21732 vkFreeMemory(m_device->device(), buffer_memory, NULL);
21733
21734 m_errorMonitor->VerifyNotFound();
21735 }
21736}
21737
21738TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
21739 VkResult err;
21740
21741 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
21742
21743 ASSERT_NO_FATAL_FAILURE(InitState());
21744 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21745
21746 std::vector<const char *> device_extension_names;
21747 auto features = m_device->phy().features();
21748 // Artificially disable support for non-solid fill modes
21749 features.fillModeNonSolid = false;
21750 // The sacrificial device object
21751 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
21752
21753 VkRenderpassObj render_pass(&test_device);
21754
21755 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21756 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21757 pipeline_layout_ci.setLayoutCount = 0;
21758 pipeline_layout_ci.pSetLayouts = NULL;
21759
21760 VkPipelineLayout pipeline_layout;
21761 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21762 ASSERT_VK_SUCCESS(err);
21763
21764 VkPipelineRasterizationStateCreateInfo rs_ci = {};
21765 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
21766 rs_ci.pNext = nullptr;
21767 rs_ci.lineWidth = 1.0f;
21768 rs_ci.rasterizerDiscardEnable = true;
21769
21770 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
21771 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21772
21773 // Set polygonMode=FILL. No error is expected
21774 m_errorMonitor->ExpectSuccess();
21775 {
21776 VkPipelineObj pipe(&test_device);
21777 pipe.AddShader(&vs);
21778 pipe.AddShader(&fs);
21779 pipe.AddColorAttachment();
21780 // Set polygonMode to a good value
21781 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
21782 pipe.SetRasterization(&rs_ci);
21783 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
21784 }
21785 m_errorMonitor->VerifyNotFound();
21786
21787 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
21788}
21789
21790TEST_F(VkPositiveLayerTest, ValidPushConstants) {
21791 VkResult err;
21792 ASSERT_NO_FATAL_FAILURE(InitState());
21793 ASSERT_NO_FATAL_FAILURE(InitViewport());
21794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21795
21796 VkPipelineLayout pipeline_layout;
21797 VkPushConstantRange pc_range = {};
21798 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21799 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21800 pipeline_layout_ci.pushConstantRangeCount = 1;
21801 pipeline_layout_ci.pPushConstantRanges = &pc_range;
21802
21803 //
21804 // Check for invalid push constant ranges in pipeline layouts.
21805 //
21806 struct PipelineLayoutTestCase {
21807 VkPushConstantRange const range;
21808 char const *msg;
21809 };
21810
21811 // Check for overlapping ranges
21812 const uint32_t ranges_per_test = 5;
21813 struct OverlappingRangeTestCase {
21814 VkPushConstantRange const ranges[ranges_per_test];
21815 char const *msg;
21816 };
21817
21818 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021819 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
21820 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
21821 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
21822 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
21823 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
21824 ""},
21825 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
21826 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
21827 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
21828 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
21829 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
21830 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021831 for (const auto &iter : overlapping_range_tests_pos) {
21832 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
21833 m_errorMonitor->ExpectSuccess();
21834 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21835 m_errorMonitor->VerifyNotFound();
21836 if (VK_SUCCESS == err) {
21837 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21838 }
21839 }
21840
21841 //
21842 // CmdPushConstants tests
21843 //
21844 const uint8_t dummy_values[100] = {};
21845
Tony Barbour552f6c02016-12-21 14:34:07 -070021846 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021847
21848 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021849 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
21850 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
21851 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
21852 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
21853 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
21854 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021855
21856 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
21857 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021858 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
21859 {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 -060021860 };
21861
21862 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
21863 pipeline_layout_ci.pPushConstantRanges = pc_range4;
21864 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21865 ASSERT_VK_SUCCESS(err);
21866 for (const auto &iter : cmd_overlap_tests_pos) {
21867 m_errorMonitor->ExpectSuccess();
21868 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021869 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021870 m_errorMonitor->VerifyNotFound();
21871 }
21872 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21873
Tony Barbour552f6c02016-12-21 14:34:07 -070021874 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021875}
21876
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021877#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021878TEST_F(VkPositiveLayerTest, LongFenceChain)
21879{
21880 m_errorMonitor->ExpectSuccess();
21881
21882 ASSERT_NO_FATAL_FAILURE(InitState());
21883 VkResult err;
21884
21885 std::vector<VkFence> fences;
21886
21887 const int chainLength = 32768;
21888
21889 for (int i = 0; i < chainLength; i++) {
21890 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
21891 VkFence fence;
21892 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21893 ASSERT_VK_SUCCESS(err);
21894
21895 fences.push_back(fence);
21896
21897 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
21898 0, nullptr, 0, nullptr };
21899 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21900 ASSERT_VK_SUCCESS(err);
21901
21902 }
21903
21904 // BOOM, stack overflow.
21905 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
21906
21907 for (auto fence : fences)
21908 vkDestroyFence(m_device->device(), fence, nullptr);
21909
21910 m_errorMonitor->VerifyNotFound();
21911}
21912#endif
21913
Cody Northrop1242dfd2016-07-13 17:24:59 -060021914#if defined(ANDROID) && defined(VALIDATION_APK)
21915static bool initialized = false;
21916static bool active = false;
21917
21918// Convert Intents to argv
21919// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021920std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021921 std::vector<std::string> args;
21922 JavaVM &vm = *app.activity->vm;
21923 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021924 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021925
21926 JNIEnv &env = *p_env;
21927 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021928 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021929 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021930 jmethodID get_string_extra_method =
21931 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021932 jvalue get_string_extra_args;
21933 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021934 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060021935
21936 std::string args_str;
21937 if (extra_str) {
21938 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
21939 args_str = extra_utf;
21940 env.ReleaseStringUTFChars(extra_str, extra_utf);
21941 env.DeleteLocalRef(extra_str);
21942 }
21943
21944 env.DeleteLocalRef(get_string_extra_args.l);
21945 env.DeleteLocalRef(intent);
21946 vm.DetachCurrentThread();
21947
21948 // split args_str
21949 std::stringstream ss(args_str);
21950 std::string arg;
21951 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021952 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021953 }
21954
21955 return args;
21956}
21957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021958static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021960static void processCommand(struct android_app *app, int32_t cmd) {
21961 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021962 case APP_CMD_INIT_WINDOW: {
21963 if (app->window) {
21964 initialized = true;
21965 }
21966 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021967 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021968 case APP_CMD_GAINED_FOCUS: {
21969 active = true;
21970 break;
21971 }
21972 case APP_CMD_LOST_FOCUS: {
21973 active = false;
21974 break;
21975 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021976 }
21977}
21978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021979void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021980 app_dummy();
21981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021982 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060021983
21984 int vulkanSupport = InitVulkan();
21985 if (vulkanSupport == 0) {
21986 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
21987 return;
21988 }
21989
21990 app->onAppCmd = processCommand;
21991 app->onInputEvent = processInput;
21992
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021993 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021994 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021995 struct android_poll_source *source;
21996 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021997 if (source) {
21998 source->process(app, source);
21999 }
22000
22001 if (app->destroyRequested != 0) {
22002 VkTestFramework::Finish();
22003 return;
22004 }
22005 }
22006
22007 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022008 // Use the following key to send arguments to gtest, i.e.
22009 // --es args "--gtest_filter=-VkLayerTest.foo"
22010 const char key[] = "args";
22011 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022013 std::string filter = "";
22014 if (args.size() > 0) {
22015 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22016 filter += args[0];
22017 } else {
22018 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22019 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022021 int argc = 2;
22022 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22023 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022025 // Route output to files until we can override the gtest output
22026 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22027 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022029 ::testing::InitGoogleTest(&argc, argv);
22030 VkTestFramework::InitArgs(&argc, argv);
22031 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022033 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022035 if (result != 0) {
22036 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22037 } else {
22038 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22039 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022041 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022043 fclose(stdout);
22044 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022046 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022048 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022049 }
22050 }
22051}
22052#endif
22053
Tony Barbour300a6082015-04-07 13:44:53 -060022054int main(int argc, char **argv) {
22055 int result;
22056
Cody Northrop8e54a402016-03-08 22:25:52 -070022057#ifdef ANDROID
22058 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022059 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022060#endif
22061
Tony Barbour300a6082015-04-07 13:44:53 -060022062 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022063 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022064
22065 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22066
22067 result = RUN_ALL_TESTS();
22068
Tony Barbour6918cd52015-04-09 12:58:51 -060022069 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022070 return result;
22071}