blob: 5db9d9b9656a2284271e766f4c3f1a99d4a5bc5f [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) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002733 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);
Cort Strattonccc90e32017-02-04 13:47:42 -08002742 }
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) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002747 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);
Cort Strattonccc90e32017-02-04 13:47:42 -08002756 }
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 Ehlis17b2e7b2016-07-21 09:43:29 -06009053 VkDepthStencilObj s_image(m_device);
9054 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9055 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009056 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009057 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009058 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009059 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9061 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009062 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 {
Dave Houlton584d51e2017-02-16 12:52:54 -070011868 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011869 return;
11870 }
11871
11872 VkDescriptorPoolSize ds_type = {};
11873 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11874 ds_type.descriptorCount = 1;
11875
11876 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11877 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11878 ds_pool_ci.maxSets = 1;
11879 ds_pool_ci.poolSizeCount = 1;
11880 ds_pool_ci.pPoolSizes = &ds_type;
11881 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11882
11883 VkDescriptorPool ds_pool;
11884 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11885 ASSERT_VK_SUCCESS(err);
11886
11887 VkDescriptorSetLayoutBinding dsl_binding = {};
11888 dsl_binding.binding = 0;
11889 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11890 dsl_binding.descriptorCount = 1;
11891 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11892 dsl_binding.pImmutableSamplers = NULL;
11893
11894 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11895 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11896 ds_layout_ci.pNext = NULL;
11897 ds_layout_ci.bindingCount = 1;
11898 ds_layout_ci.pBindings = &dsl_binding;
11899
11900 VkDescriptorSetLayout ds_layout;
11901 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11902 ASSERT_VK_SUCCESS(err);
11903
11904 VkDescriptorSetAllocateInfo alloc_info = {};
11905 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11906 alloc_info.descriptorSetCount = 1;
11907 alloc_info.descriptorPool = ds_pool;
11908 alloc_info.pSetLayouts = &ds_layout;
11909 VkDescriptorSet descriptor_set;
11910 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11911 ASSERT_VK_SUCCESS(err);
11912
11913 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11914 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11915 pipeline_layout_ci.pNext = NULL;
11916 pipeline_layout_ci.setLayoutCount = 1;
11917 pipeline_layout_ci.pSetLayouts = &ds_layout;
11918 VkPipelineLayout pipeline_layout;
11919 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11920 ASSERT_VK_SUCCESS(err);
11921
11922 VkImageObj image(m_device);
11923 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11924 ASSERT_TRUE(image.initialized());
11925 VkImageView view = image.targetView(tex_format);
11926
11927 VkDescriptorImageInfo image_info = {};
11928 image_info.imageView = view;
11929 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11930
11931 VkWriteDescriptorSet descriptor_write = {};
11932 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11933 descriptor_write.dstSet = descriptor_set;
11934 descriptor_write.dstBinding = 0;
11935 descriptor_write.descriptorCount = 1;
11936 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11937 descriptor_write.pImageInfo = &image_info;
11938
11939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11940 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11941 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11942 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11943 m_errorMonitor->VerifyFound();
11944
11945 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11947 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11949}
11950
Mark Mueller93b938f2016-08-18 10:27:40 -060011951TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011952 TEST_DESCRIPTION(
11953 "Use vkCmdExecuteCommands with invalid state "
11954 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011955
11956 ASSERT_NO_FATAL_FAILURE(InitState());
11957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11958
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011959 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011960 const char *simultaneous_use_message2 =
11961 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11962 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011963
11964 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011965 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011966 command_buffer_allocate_info.commandPool = m_commandPool;
11967 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11968 command_buffer_allocate_info.commandBufferCount = 1;
11969
11970 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011971 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011972 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11973 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011974 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011975 command_buffer_inheritance_info.renderPass = m_renderPass;
11976 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011977
Mark Mueller93b938f2016-08-18 10:27:40 -060011978 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011979 command_buffer_begin_info.flags =
11980 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011981 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11982
11983 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11984 vkEndCommandBuffer(secondary_command_buffer);
11985
Mark Mueller93b938f2016-08-18 10:27:40 -060011986 VkSubmitInfo submit_info = {};
11987 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11988 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011989 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011990
Mark Mueller4042b652016-09-05 22:52:21 -060011991 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011992 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11994 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011995 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011996 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011997 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11998 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011999
Dave Houltonfbf52152017-01-06 12:55:29 -070012000 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012001 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012002 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012003
Mark Mueller4042b652016-09-05 22:52:21 -060012004 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012005 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12006 m_errorMonitor->SetUnexpectedError(
12007 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12008 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012009 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012010 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12013 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012014 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012015 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12016 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012017
12018 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012019
12020 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012021}
12022
Tony Barbour626994c2017-02-08 15:29:37 -070012023TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12024 TEST_DESCRIPTION(
12025 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12026 "errors");
12027 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12028 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12029 ASSERT_NO_FATAL_FAILURE(InitState());
12030
12031 VkCommandBuffer cmd_bufs[2];
12032 VkCommandBufferAllocateInfo alloc_info;
12033 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12034 alloc_info.pNext = NULL;
12035 alloc_info.commandBufferCount = 2;
12036 alloc_info.commandPool = m_commandPool;
12037 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12038 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12039
12040 VkCommandBufferBeginInfo cb_binfo;
12041 cb_binfo.pNext = NULL;
12042 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12043 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12044 cb_binfo.flags = 0;
12045 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12046 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12047 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12048 vkEndCommandBuffer(cmd_bufs[0]);
12049 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12050
12051 VkSubmitInfo submit_info = {};
12052 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12053 submit_info.commandBufferCount = 2;
12054 submit_info.pCommandBuffers = duplicates;
12055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12056 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12057 m_errorMonitor->VerifyFound();
12058 vkQueueWaitIdle(m_device->m_queue);
12059
12060 // Set one time use and now look for one time submit
12061 duplicates[0] = duplicates[1] = cmd_bufs[1];
12062 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12063 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12064 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12065 vkEndCommandBuffer(cmd_bufs[1]);
12066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12067 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12068 m_errorMonitor->VerifyFound();
12069 vkQueueWaitIdle(m_device->m_queue);
12070}
12071
Tobin Ehlisb093da82017-01-19 12:05:27 -070012072TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012073 TEST_DESCRIPTION(
12074 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12075 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012076
12077 ASSERT_NO_FATAL_FAILURE(InitState());
12078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12079
12080 std::vector<const char *> device_extension_names;
12081 auto features = m_device->phy().features();
12082 // Make sure gs & ts are disabled
12083 features.geometryShader = false;
12084 features.tessellationShader = false;
12085 // The sacrificial device object
12086 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12087
12088 VkCommandPoolCreateInfo pool_create_info{};
12089 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12090 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12091
12092 VkCommandPool command_pool;
12093 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12094
12095 VkCommandBufferAllocateInfo cmd = {};
12096 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12097 cmd.pNext = NULL;
12098 cmd.commandPool = command_pool;
12099 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12100 cmd.commandBufferCount = 1;
12101
12102 VkCommandBuffer cmd_buffer;
12103 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12104 ASSERT_VK_SUCCESS(err);
12105
12106 VkEvent event;
12107 VkEventCreateInfo evci = {};
12108 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12109 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12110 ASSERT_VK_SUCCESS(result);
12111
12112 VkCommandBufferBeginInfo cbbi = {};
12113 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12114 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12116 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12117 m_errorMonitor->VerifyFound();
12118
12119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12120 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12121 m_errorMonitor->VerifyFound();
12122
12123 vkDestroyEvent(test_device.handle(), event, NULL);
12124 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12125}
12126
Mark Mueller917f6bc2016-08-30 10:57:19 -060012127TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012128 TEST_DESCRIPTION(
12129 "Use vkCmdExecuteCommands with invalid state "
12130 "in primary and secondary command buffers. "
12131 "Delete objects that are inuse. Call VkQueueSubmit "
12132 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012133
12134 ASSERT_NO_FATAL_FAILURE(InitState());
12135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12136
Tony Barbour552f6c02016-12-21 14:34:07 -070012137 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012138
12139 VkEvent event;
12140 VkEventCreateInfo event_create_info = {};
12141 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12142 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012143 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012144
Tony Barbour552f6c02016-12-21 14:34:07 -070012145 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012146 vkDestroyEvent(m_device->device(), event, nullptr);
12147
12148 VkSubmitInfo submit_info = {};
12149 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12150 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012151 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070012152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012154 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12155 m_errorMonitor->VerifyFound();
12156
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012157 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012158 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12159
12160 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12161
Mark Mueller917f6bc2016-08-30 10:57:19 -060012162 VkSemaphoreCreateInfo semaphore_create_info = {};
12163 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12164 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012165 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012166 VkFenceCreateInfo fence_create_info = {};
12167 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12168 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012169 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012170
12171 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012172 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012173 descriptor_pool_type_count.descriptorCount = 1;
12174
12175 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12176 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12177 descriptor_pool_create_info.maxSets = 1;
12178 descriptor_pool_create_info.poolSizeCount = 1;
12179 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012180 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012181
12182 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012183 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012184
12185 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012186 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012187 descriptorset_layout_binding.descriptorCount = 1;
12188 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12189
12190 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012191 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012192 descriptorset_layout_create_info.bindingCount = 1;
12193 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12194
12195 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012196 ASSERT_VK_SUCCESS(
12197 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012198
12199 VkDescriptorSet descriptorset;
12200 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012201 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012202 descriptorset_allocate_info.descriptorSetCount = 1;
12203 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12204 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012205 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012206
Mark Mueller4042b652016-09-05 22:52:21 -060012207 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12208
12209 VkDescriptorBufferInfo buffer_info = {};
12210 buffer_info.buffer = buffer_test.GetBuffer();
12211 buffer_info.offset = 0;
12212 buffer_info.range = 1024;
12213
12214 VkWriteDescriptorSet write_descriptor_set = {};
12215 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12216 write_descriptor_set.dstSet = descriptorset;
12217 write_descriptor_set.descriptorCount = 1;
12218 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12219 write_descriptor_set.pBufferInfo = &buffer_info;
12220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012221 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12224 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012225
12226 VkPipelineObj pipe(m_device);
12227 pipe.AddColorAttachment();
12228 pipe.AddShader(&vs);
12229 pipe.AddShader(&fs);
12230
12231 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012232 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012233 pipeline_layout_create_info.setLayoutCount = 1;
12234 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12235
12236 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012237 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012238
12239 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12240
Tony Barbour552f6c02016-12-21 14:34:07 -070012241 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012242 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012244 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12245 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12246 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012247
Tony Barbour552f6c02016-12-21 14:34:07 -070012248 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012249
Mark Mueller917f6bc2016-08-30 10:57:19 -060012250 submit_info.signalSemaphoreCount = 1;
12251 submit_info.pSignalSemaphores = &semaphore;
12252 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012253 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012254
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012256 vkDestroyEvent(m_device->device(), event, nullptr);
12257 m_errorMonitor->VerifyFound();
12258
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012260 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12261 m_errorMonitor->VerifyFound();
12262
Jeremy Hayes08369882017-02-02 10:31:06 -070012263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012264 vkDestroyFence(m_device->device(), fence, nullptr);
12265 m_errorMonitor->VerifyFound();
12266
Tobin Ehlis122207b2016-09-01 08:50:06 -070012267 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012268 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12269 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012270 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012271 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12272 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012273 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012274 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12275 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012276 vkDestroyEvent(m_device->device(), event, nullptr);
12277 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012278 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012279 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12280}
12281
Tobin Ehlis2adda372016-09-01 08:51:06 -070012282TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12283 TEST_DESCRIPTION("Delete in-use query pool.");
12284
12285 ASSERT_NO_FATAL_FAILURE(InitState());
12286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12287
12288 VkQueryPool query_pool;
12289 VkQueryPoolCreateInfo query_pool_ci{};
12290 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12291 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12292 query_pool_ci.queryCount = 1;
12293 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012294 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012295 // Reset query pool to create binding with cmd buffer
12296 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12297
Tony Barbour552f6c02016-12-21 14:34:07 -070012298 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012299
12300 VkSubmitInfo submit_info = {};
12301 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12302 submit_info.commandBufferCount = 1;
12303 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12304 // Submit cmd buffer and then destroy query pool while in-flight
12305 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12306
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012308 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12309 m_errorMonitor->VerifyFound();
12310
12311 vkQueueWaitIdle(m_device->m_queue);
12312 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012313 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12314 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012315 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12316}
12317
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012318TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12319 TEST_DESCRIPTION("Delete in-use pipeline.");
12320
12321 ASSERT_NO_FATAL_FAILURE(InitState());
12322 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12323
12324 // Empty pipeline layout used for binding PSO
12325 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12326 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12327 pipeline_layout_ci.setLayoutCount = 0;
12328 pipeline_layout_ci.pSetLayouts = NULL;
12329
12330 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012331 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012332 ASSERT_VK_SUCCESS(err);
12333
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012335 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012336 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12337 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012338 // Store pipeline handle so we can actually delete it before test finishes
12339 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012340 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012341 VkPipelineObj pipe(m_device);
12342 pipe.AddShader(&vs);
12343 pipe.AddShader(&fs);
12344 pipe.AddColorAttachment();
12345 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12346 delete_this_pipeline = pipe.handle();
12347
Tony Barbour552f6c02016-12-21 14:34:07 -070012348 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012349 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012350 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012351
Tony Barbour552f6c02016-12-21 14:34:07 -070012352 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012353
12354 VkSubmitInfo submit_info = {};
12355 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12356 submit_info.commandBufferCount = 1;
12357 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12358 // Submit cmd buffer and then pipeline destroyed while in-flight
12359 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012360 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012361 m_errorMonitor->VerifyFound();
12362 // Make sure queue finished and then actually delete pipeline
12363 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012364 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12365 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012366 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12367 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12368}
12369
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012370TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12371 TEST_DESCRIPTION("Delete in-use imageView.");
12372
12373 ASSERT_NO_FATAL_FAILURE(InitState());
12374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12375
12376 VkDescriptorPoolSize ds_type_count;
12377 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12378 ds_type_count.descriptorCount = 1;
12379
12380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12382 ds_pool_ci.maxSets = 1;
12383 ds_pool_ci.poolSizeCount = 1;
12384 ds_pool_ci.pPoolSizes = &ds_type_count;
12385
12386 VkDescriptorPool ds_pool;
12387 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12388 ASSERT_VK_SUCCESS(err);
12389
12390 VkSamplerCreateInfo sampler_ci = {};
12391 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12392 sampler_ci.pNext = NULL;
12393 sampler_ci.magFilter = VK_FILTER_NEAREST;
12394 sampler_ci.minFilter = VK_FILTER_NEAREST;
12395 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12396 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12397 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12398 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12399 sampler_ci.mipLodBias = 1.0;
12400 sampler_ci.anisotropyEnable = VK_FALSE;
12401 sampler_ci.maxAnisotropy = 1;
12402 sampler_ci.compareEnable = VK_FALSE;
12403 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12404 sampler_ci.minLod = 1.0;
12405 sampler_ci.maxLod = 1.0;
12406 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12407 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12408 VkSampler sampler;
12409
12410 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12411 ASSERT_VK_SUCCESS(err);
12412
12413 VkDescriptorSetLayoutBinding layout_binding;
12414 layout_binding.binding = 0;
12415 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12416 layout_binding.descriptorCount = 1;
12417 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12418 layout_binding.pImmutableSamplers = NULL;
12419
12420 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12421 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12422 ds_layout_ci.bindingCount = 1;
12423 ds_layout_ci.pBindings = &layout_binding;
12424 VkDescriptorSetLayout ds_layout;
12425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12426 ASSERT_VK_SUCCESS(err);
12427
12428 VkDescriptorSetAllocateInfo alloc_info = {};
12429 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12430 alloc_info.descriptorSetCount = 1;
12431 alloc_info.descriptorPool = ds_pool;
12432 alloc_info.pSetLayouts = &ds_layout;
12433 VkDescriptorSet descriptor_set;
12434 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12435 ASSERT_VK_SUCCESS(err);
12436
12437 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12438 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12439 pipeline_layout_ci.pNext = NULL;
12440 pipeline_layout_ci.setLayoutCount = 1;
12441 pipeline_layout_ci.pSetLayouts = &ds_layout;
12442
12443 VkPipelineLayout pipeline_layout;
12444 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12445 ASSERT_VK_SUCCESS(err);
12446
12447 VkImageObj image(m_device);
12448 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12449 ASSERT_TRUE(image.initialized());
12450
12451 VkImageView view;
12452 VkImageViewCreateInfo ivci = {};
12453 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12454 ivci.image = image.handle();
12455 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12456 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12457 ivci.subresourceRange.layerCount = 1;
12458 ivci.subresourceRange.baseMipLevel = 0;
12459 ivci.subresourceRange.levelCount = 1;
12460 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12461
12462 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12463 ASSERT_VK_SUCCESS(err);
12464
12465 VkDescriptorImageInfo image_info{};
12466 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12467 image_info.imageView = view;
12468 image_info.sampler = sampler;
12469
12470 VkWriteDescriptorSet descriptor_write = {};
12471 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12472 descriptor_write.dstSet = descriptor_set;
12473 descriptor_write.dstBinding = 0;
12474 descriptor_write.descriptorCount = 1;
12475 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12476 descriptor_write.pImageInfo = &image_info;
12477
12478 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12479
12480 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012481 char const *vsSource =
12482 "#version 450\n"
12483 "\n"
12484 "out gl_PerVertex { \n"
12485 " vec4 gl_Position;\n"
12486 "};\n"
12487 "void main(){\n"
12488 " gl_Position = vec4(1);\n"
12489 "}\n";
12490 char const *fsSource =
12491 "#version 450\n"
12492 "\n"
12493 "layout(set=0, binding=0) uniform sampler2D s;\n"
12494 "layout(location=0) out vec4 x;\n"
12495 "void main(){\n"
12496 " x = texture(s, vec2(1));\n"
12497 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012498 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12499 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12500 VkPipelineObj pipe(m_device);
12501 pipe.AddShader(&vs);
12502 pipe.AddShader(&fs);
12503 pipe.AddColorAttachment();
12504 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12505
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012507
Tony Barbour552f6c02016-12-21 14:34:07 -070012508 m_commandBuffer->BeginCommandBuffer();
12509 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012510 // Bind pipeline to cmd buffer
12511 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12512 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12513 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012514
12515 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12516 VkRect2D scissor = {{0, 0}, {16, 16}};
12517 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12518 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12519
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012520 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012521 m_commandBuffer->EndRenderPass();
12522 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012523 // Submit cmd buffer then destroy sampler
12524 VkSubmitInfo submit_info = {};
12525 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12526 submit_info.commandBufferCount = 1;
12527 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12528 // Submit cmd buffer and then destroy imageView while in-flight
12529 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12530
12531 vkDestroyImageView(m_device->device(), view, nullptr);
12532 m_errorMonitor->VerifyFound();
12533 vkQueueWaitIdle(m_device->m_queue);
12534 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012535 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12536 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012537 vkDestroyImageView(m_device->device(), view, NULL);
12538 vkDestroySampler(m_device->device(), sampler, nullptr);
12539 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12540 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12541 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12542}
12543
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012544TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12545 TEST_DESCRIPTION("Delete in-use bufferView.");
12546
12547 ASSERT_NO_FATAL_FAILURE(InitState());
12548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12549
12550 VkDescriptorPoolSize ds_type_count;
12551 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12552 ds_type_count.descriptorCount = 1;
12553
12554 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12555 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12556 ds_pool_ci.maxSets = 1;
12557 ds_pool_ci.poolSizeCount = 1;
12558 ds_pool_ci.pPoolSizes = &ds_type_count;
12559
12560 VkDescriptorPool ds_pool;
12561 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12562 ASSERT_VK_SUCCESS(err);
12563
12564 VkDescriptorSetLayoutBinding layout_binding;
12565 layout_binding.binding = 0;
12566 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12567 layout_binding.descriptorCount = 1;
12568 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12569 layout_binding.pImmutableSamplers = NULL;
12570
12571 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12572 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12573 ds_layout_ci.bindingCount = 1;
12574 ds_layout_ci.pBindings = &layout_binding;
12575 VkDescriptorSetLayout ds_layout;
12576 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12577 ASSERT_VK_SUCCESS(err);
12578
12579 VkDescriptorSetAllocateInfo alloc_info = {};
12580 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12581 alloc_info.descriptorSetCount = 1;
12582 alloc_info.descriptorPool = ds_pool;
12583 alloc_info.pSetLayouts = &ds_layout;
12584 VkDescriptorSet descriptor_set;
12585 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12586 ASSERT_VK_SUCCESS(err);
12587
12588 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12589 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12590 pipeline_layout_ci.pNext = NULL;
12591 pipeline_layout_ci.setLayoutCount = 1;
12592 pipeline_layout_ci.pSetLayouts = &ds_layout;
12593
12594 VkPipelineLayout pipeline_layout;
12595 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12596 ASSERT_VK_SUCCESS(err);
12597
12598 VkBuffer buffer;
12599 uint32_t queue_family_index = 0;
12600 VkBufferCreateInfo buffer_create_info = {};
12601 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12602 buffer_create_info.size = 1024;
12603 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12604 buffer_create_info.queueFamilyIndexCount = 1;
12605 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12606
12607 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12608 ASSERT_VK_SUCCESS(err);
12609
12610 VkMemoryRequirements memory_reqs;
12611 VkDeviceMemory buffer_memory;
12612
12613 VkMemoryAllocateInfo memory_info = {};
12614 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12615 memory_info.allocationSize = 0;
12616 memory_info.memoryTypeIndex = 0;
12617
12618 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12619 memory_info.allocationSize = memory_reqs.size;
12620 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12621 ASSERT_TRUE(pass);
12622
12623 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12624 ASSERT_VK_SUCCESS(err);
12625 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12626 ASSERT_VK_SUCCESS(err);
12627
12628 VkBufferView view;
12629 VkBufferViewCreateInfo bvci = {};
12630 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12631 bvci.buffer = buffer;
12632 bvci.format = VK_FORMAT_R8_UNORM;
12633 bvci.range = VK_WHOLE_SIZE;
12634
12635 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12636 ASSERT_VK_SUCCESS(err);
12637
12638 VkWriteDescriptorSet descriptor_write = {};
12639 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12640 descriptor_write.dstSet = descriptor_set;
12641 descriptor_write.dstBinding = 0;
12642 descriptor_write.descriptorCount = 1;
12643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12644 descriptor_write.pTexelBufferView = &view;
12645
12646 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12647
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012648 char const *vsSource =
12649 "#version 450\n"
12650 "\n"
12651 "out gl_PerVertex { \n"
12652 " vec4 gl_Position;\n"
12653 "};\n"
12654 "void main(){\n"
12655 " gl_Position = vec4(1);\n"
12656 "}\n";
12657 char const *fsSource =
12658 "#version 450\n"
12659 "\n"
12660 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12661 "layout(location=0) out vec4 x;\n"
12662 "void main(){\n"
12663 " x = imageLoad(s, 0);\n"
12664 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012665 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12666 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12667 VkPipelineObj pipe(m_device);
12668 pipe.AddShader(&vs);
12669 pipe.AddShader(&fs);
12670 pipe.AddColorAttachment();
12671 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12672
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012674
Tony Barbour552f6c02016-12-21 14:34:07 -070012675 m_commandBuffer->BeginCommandBuffer();
12676 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012677 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12678 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12679 VkRect2D scissor = {{0, 0}, {16, 16}};
12680 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12681 // Bind pipeline to cmd buffer
12682 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12683 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12684 &descriptor_set, 0, nullptr);
12685 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012686 m_commandBuffer->EndRenderPass();
12687 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012688
12689 VkSubmitInfo submit_info = {};
12690 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12691 submit_info.commandBufferCount = 1;
12692 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12693 // Submit cmd buffer and then destroy bufferView while in-flight
12694 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12695
12696 vkDestroyBufferView(m_device->device(), view, nullptr);
12697 m_errorMonitor->VerifyFound();
12698 vkQueueWaitIdle(m_device->m_queue);
12699 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012700 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12701 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012702 vkDestroyBufferView(m_device->device(), view, NULL);
12703 vkDestroyBuffer(m_device->device(), buffer, NULL);
12704 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12705 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12706 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12707 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12708}
12709
Tobin Ehlis209532e2016-09-07 13:52:18 -060012710TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12711 TEST_DESCRIPTION("Delete in-use sampler.");
12712
12713 ASSERT_NO_FATAL_FAILURE(InitState());
12714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12715
12716 VkDescriptorPoolSize ds_type_count;
12717 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12718 ds_type_count.descriptorCount = 1;
12719
12720 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12721 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12722 ds_pool_ci.maxSets = 1;
12723 ds_pool_ci.poolSizeCount = 1;
12724 ds_pool_ci.pPoolSizes = &ds_type_count;
12725
12726 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012727 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012728 ASSERT_VK_SUCCESS(err);
12729
12730 VkSamplerCreateInfo sampler_ci = {};
12731 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12732 sampler_ci.pNext = NULL;
12733 sampler_ci.magFilter = VK_FILTER_NEAREST;
12734 sampler_ci.minFilter = VK_FILTER_NEAREST;
12735 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12736 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12737 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12738 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12739 sampler_ci.mipLodBias = 1.0;
12740 sampler_ci.anisotropyEnable = VK_FALSE;
12741 sampler_ci.maxAnisotropy = 1;
12742 sampler_ci.compareEnable = VK_FALSE;
12743 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12744 sampler_ci.minLod = 1.0;
12745 sampler_ci.maxLod = 1.0;
12746 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12747 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12748 VkSampler sampler;
12749
12750 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12751 ASSERT_VK_SUCCESS(err);
12752
12753 VkDescriptorSetLayoutBinding layout_binding;
12754 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012755 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012756 layout_binding.descriptorCount = 1;
12757 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12758 layout_binding.pImmutableSamplers = NULL;
12759
12760 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12761 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12762 ds_layout_ci.bindingCount = 1;
12763 ds_layout_ci.pBindings = &layout_binding;
12764 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012766 ASSERT_VK_SUCCESS(err);
12767
12768 VkDescriptorSetAllocateInfo alloc_info = {};
12769 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12770 alloc_info.descriptorSetCount = 1;
12771 alloc_info.descriptorPool = ds_pool;
12772 alloc_info.pSetLayouts = &ds_layout;
12773 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012774 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012775 ASSERT_VK_SUCCESS(err);
12776
12777 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12778 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12779 pipeline_layout_ci.pNext = NULL;
12780 pipeline_layout_ci.setLayoutCount = 1;
12781 pipeline_layout_ci.pSetLayouts = &ds_layout;
12782
12783 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012784 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012785 ASSERT_VK_SUCCESS(err);
12786
12787 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012788 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 -060012789 ASSERT_TRUE(image.initialized());
12790
12791 VkImageView view;
12792 VkImageViewCreateInfo ivci = {};
12793 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12794 ivci.image = image.handle();
12795 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12796 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12797 ivci.subresourceRange.layerCount = 1;
12798 ivci.subresourceRange.baseMipLevel = 0;
12799 ivci.subresourceRange.levelCount = 1;
12800 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12801
12802 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12803 ASSERT_VK_SUCCESS(err);
12804
12805 VkDescriptorImageInfo image_info{};
12806 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12807 image_info.imageView = view;
12808 image_info.sampler = sampler;
12809
12810 VkWriteDescriptorSet descriptor_write = {};
12811 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12812 descriptor_write.dstSet = descriptor_set;
12813 descriptor_write.dstBinding = 0;
12814 descriptor_write.descriptorCount = 1;
12815 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12816 descriptor_write.pImageInfo = &image_info;
12817
12818 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12819
12820 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012821 char const *vsSource =
12822 "#version 450\n"
12823 "\n"
12824 "out gl_PerVertex { \n"
12825 " vec4 gl_Position;\n"
12826 "};\n"
12827 "void main(){\n"
12828 " gl_Position = vec4(1);\n"
12829 "}\n";
12830 char const *fsSource =
12831 "#version 450\n"
12832 "\n"
12833 "layout(set=0, binding=0) uniform sampler2D s;\n"
12834 "layout(location=0) out vec4 x;\n"
12835 "void main(){\n"
12836 " x = texture(s, vec2(1));\n"
12837 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12839 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12840 VkPipelineObj pipe(m_device);
12841 pipe.AddShader(&vs);
12842 pipe.AddShader(&fs);
12843 pipe.AddColorAttachment();
12844 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12845
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012847
Tony Barbour552f6c02016-12-21 14:34:07 -070012848 m_commandBuffer->BeginCommandBuffer();
12849 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012850 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012851 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12852 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12853 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012854
12855 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12856 VkRect2D scissor = {{0, 0}, {16, 16}};
12857 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12858 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12859
Tobin Ehlis209532e2016-09-07 13:52:18 -060012860 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012861 m_commandBuffer->EndRenderPass();
12862 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012863 // Submit cmd buffer then destroy sampler
12864 VkSubmitInfo submit_info = {};
12865 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12866 submit_info.commandBufferCount = 1;
12867 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12868 // Submit cmd buffer and then destroy sampler while in-flight
12869 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12870
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012871 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012872 m_errorMonitor->VerifyFound();
12873 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012874
Tobin Ehlis209532e2016-09-07 13:52:18 -060012875 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012876 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12877 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012878 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012879 vkDestroyImageView(m_device->device(), view, NULL);
12880 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12881 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12882 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12883}
12884
Mark Mueller1cd9f412016-08-25 13:23:52 -060012885TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012886 TEST_DESCRIPTION(
12887 "Call VkQueueSubmit with a semaphore that is already "
12888 "signaled but not waited on by the queue. Wait on a "
12889 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012890
12891 ASSERT_NO_FATAL_FAILURE(InitState());
12892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012894 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 -070012895 const char *invalid_fence_wait_message =
12896 " which has not been submitted on a Queue or during "
12897 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012898
Tony Barbour552f6c02016-12-21 14:34:07 -070012899 m_commandBuffer->BeginCommandBuffer();
12900 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012901
12902 VkSemaphoreCreateInfo semaphore_create_info = {};
12903 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12904 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012905 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012906 VkSubmitInfo submit_info = {};
12907 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12908 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012909 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012910 submit_info.signalSemaphoreCount = 1;
12911 submit_info.pSignalSemaphores = &semaphore;
12912 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012913 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012914 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012915 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012916 m_commandBuffer->BeginCommandBuffer();
12917 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012919 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12920 m_errorMonitor->VerifyFound();
12921
Mark Mueller1cd9f412016-08-25 13:23:52 -060012922 VkFenceCreateInfo fence_create_info = {};
12923 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12924 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012925 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012928 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12929 m_errorMonitor->VerifyFound();
12930
Mark Mueller4042b652016-09-05 22:52:21 -060012931 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012932 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012933 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12934}
12935
Tobin Ehlis4af23302016-07-19 10:50:30 -060012936TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012937 TEST_DESCRIPTION(
12938 "Bind a secondary command buffer with with a framebuffer "
12939 "that does not match the framebuffer for the active "
12940 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012941 ASSERT_NO_FATAL_FAILURE(InitState());
12942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12943
12944 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012945 VkAttachmentDescription attachment = {0,
12946 VK_FORMAT_B8G8R8A8_UNORM,
12947 VK_SAMPLE_COUNT_1_BIT,
12948 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12949 VK_ATTACHMENT_STORE_OP_STORE,
12950 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12951 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12952 VK_IMAGE_LAYOUT_UNDEFINED,
12953 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012955 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012959 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012960
12961 VkRenderPass rp;
12962 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12963 ASSERT_VK_SUCCESS(err);
12964
12965 // A compatible framebuffer.
12966 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012967 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 -060012968 ASSERT_TRUE(image.initialized());
12969
12970 VkImageViewCreateInfo ivci = {
12971 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12972 nullptr,
12973 0,
12974 image.handle(),
12975 VK_IMAGE_VIEW_TYPE_2D,
12976 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012977 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12978 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012979 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12980 };
12981 VkImageView view;
12982 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12983 ASSERT_VK_SUCCESS(err);
12984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012985 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012986 VkFramebuffer fb;
12987 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12988 ASSERT_VK_SUCCESS(err);
12989
12990 VkCommandBufferAllocateInfo cbai = {};
12991 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12992 cbai.commandPool = m_commandPool;
12993 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12994 cbai.commandBufferCount = 1;
12995
12996 VkCommandBuffer sec_cb;
12997 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12998 ASSERT_VK_SUCCESS(err);
12999 VkCommandBufferBeginInfo cbbi = {};
13000 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013001 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013002 cbii.renderPass = renderPass();
13003 cbii.framebuffer = fb;
13004 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13005 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013006 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 -060013007 cbbi.pInheritanceInfo = &cbii;
13008 vkBeginCommandBuffer(sec_cb, &cbbi);
13009 vkEndCommandBuffer(sec_cb);
13010
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013011 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013012 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13013 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013016 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013017 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13018 m_errorMonitor->VerifyFound();
13019 // Cleanup
13020 vkDestroyImageView(m_device->device(), view, NULL);
13021 vkDestroyRenderPass(m_device->device(), rp, NULL);
13022 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13023}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013024
13025TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013026 TEST_DESCRIPTION(
13027 "If logicOp is available on the device, set it to an "
13028 "invalid value. If logicOp is not available, attempt to "
13029 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013030 ASSERT_NO_FATAL_FAILURE(InitState());
13031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13032
13033 auto features = m_device->phy().features();
13034 // Set the expected error depending on whether or not logicOp available
13035 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13037 "If logic operations feature not "
13038 "enabled, logicOpEnable must be "
13039 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013040 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013042 }
13043 // Create a pipeline using logicOp
13044 VkResult err;
13045
13046 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13047 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13048
13049 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013050 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013051 ASSERT_VK_SUCCESS(err);
13052
13053 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13054 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13055 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013056 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013057 vp_state_ci.pViewports = &vp;
13058 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013059 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013060 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013061
13062 VkPipelineShaderStageCreateInfo shaderStages[2];
13063 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13064
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013065 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13066 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013067 shaderStages[0] = vs.GetStageCreateInfo();
13068 shaderStages[1] = fs.GetStageCreateInfo();
13069
13070 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13071 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13072
13073 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13074 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13075 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13076
13077 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13078 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013079 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013080
13081 VkPipelineColorBlendAttachmentState att = {};
13082 att.blendEnable = VK_FALSE;
13083 att.colorWriteMask = 0xf;
13084
13085 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13086 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13087 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13088 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013089 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013090 cb_ci.attachmentCount = 1;
13091 cb_ci.pAttachments = &att;
13092
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013093 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13094 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13095 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13096
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013097 VkGraphicsPipelineCreateInfo gp_ci = {};
13098 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13099 gp_ci.stageCount = 2;
13100 gp_ci.pStages = shaderStages;
13101 gp_ci.pVertexInputState = &vi_ci;
13102 gp_ci.pInputAssemblyState = &ia_ci;
13103 gp_ci.pViewportState = &vp_state_ci;
13104 gp_ci.pRasterizationState = &rs_ci;
13105 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013106 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013107 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13108 gp_ci.layout = pipeline_layout;
13109 gp_ci.renderPass = renderPass();
13110
13111 VkPipelineCacheCreateInfo pc_ci = {};
13112 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13113
13114 VkPipeline pipeline;
13115 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013116 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013117 ASSERT_VK_SUCCESS(err);
13118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013119 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013120 m_errorMonitor->VerifyFound();
13121 if (VK_SUCCESS == err) {
13122 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13123 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013124 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13125 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13126}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013127
Mike Stroyanaccf7692015-05-12 16:00:45 -060013128#if GTEST_IS_THREADSAFE
13129struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013130 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013131 VkEvent event;
13132 bool bailout;
13133};
13134
Karl Schultz6addd812016-02-02 17:17:23 -070013135extern "C" void *AddToCommandBuffer(void *arg) {
13136 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013137
Mike Stroyana6d14942016-07-13 15:10:05 -060013138 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013139 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013140 if (data->bailout) {
13141 break;
13142 }
13143 }
13144 return NULL;
13145}
13146
Karl Schultz6addd812016-02-02 17:17:23 -070013147TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013148 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013151
Mike Stroyanaccf7692015-05-12 16:00:45 -060013152 ASSERT_NO_FATAL_FAILURE(InitState());
13153 ASSERT_NO_FATAL_FAILURE(InitViewport());
13154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13155
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013156 // Calls AllocateCommandBuffers
13157 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013158
13159 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013160 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013161
13162 VkEventCreateInfo event_info;
13163 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013164 VkResult err;
13165
13166 memset(&event_info, 0, sizeof(event_info));
13167 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13168
Chia-I Wuf7458c52015-10-26 21:10:41 +080013169 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013170 ASSERT_VK_SUCCESS(err);
13171
Mike Stroyanaccf7692015-05-12 16:00:45 -060013172 err = vkResetEvent(device(), event);
13173 ASSERT_VK_SUCCESS(err);
13174
13175 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013176 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013177 data.event = event;
13178 data.bailout = false;
13179 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013180
13181 // First do some correct operations using multiple threads.
13182 // Add many entries to command buffer from another thread.
13183 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13184 // Make non-conflicting calls from this thread at the same time.
13185 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013186 uint32_t count;
13187 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013188 }
13189 test_platform_thread_join(thread, NULL);
13190
13191 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013192 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013193 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013194 // Add many entries to command buffer from this thread at the same time.
13195 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013196
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013197 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013198 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013199
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013200 m_errorMonitor->SetBailout(NULL);
13201
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013202 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013203
Chia-I Wuf7458c52015-10-26 21:10:41 +080013204 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013205}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013206#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013207
Karl Schultz6addd812016-02-02 17:17:23 -070013208TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013209 TEST_DESCRIPTION(
13210 "Test that an error is produced for a spirv module "
13211 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013212
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013214
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013215 ASSERT_NO_FATAL_FAILURE(InitState());
13216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13217
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013218 VkShaderModule module;
13219 VkShaderModuleCreateInfo moduleCreateInfo;
13220 struct icd_spv_header spv;
13221
13222 spv.magic = ICD_SPV_MAGIC;
13223 spv.version = ICD_SPV_VERSION;
13224 spv.gen_magic = 0;
13225
13226 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13227 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013228 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013229 moduleCreateInfo.codeSize = 4;
13230 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013231 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013232
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013233 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013234}
13235
Karl Schultz6addd812016-02-02 17:17:23 -070013236TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013237 TEST_DESCRIPTION(
13238 "Test that an error is produced for a spirv module "
13239 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013242
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013243 ASSERT_NO_FATAL_FAILURE(InitState());
13244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13245
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013246 VkShaderModule module;
13247 VkShaderModuleCreateInfo moduleCreateInfo;
13248 struct icd_spv_header spv;
13249
13250 spv.magic = ~ICD_SPV_MAGIC;
13251 spv.version = ICD_SPV_VERSION;
13252 spv.gen_magic = 0;
13253
13254 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13255 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013256 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013257 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13258 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013259 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013260
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013261 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013262}
13263
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013264#if 0
13265// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013266TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013268 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013269
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013270 ASSERT_NO_FATAL_FAILURE(InitState());
13271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13272
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013273 VkShaderModule module;
13274 VkShaderModuleCreateInfo moduleCreateInfo;
13275 struct icd_spv_header spv;
13276
13277 spv.magic = ICD_SPV_MAGIC;
13278 spv.version = ~ICD_SPV_VERSION;
13279 spv.gen_magic = 0;
13280
13281 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13282 moduleCreateInfo.pNext = NULL;
13283
Karl Schultz6addd812016-02-02 17:17:23 -070013284 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013285 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13286 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013287 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013288
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013289 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013291#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013292
Karl Schultz6addd812016-02-02 17:17:23 -070013293TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013294 TEST_DESCRIPTION(
13295 "Test that a warning is produced for a vertex output that "
13296 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013298
Chris Forbes9f7ff632015-05-25 11:13:08 +120013299 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013301
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013302 char const *vsSource =
13303 "#version 450\n"
13304 "\n"
13305 "layout(location=0) out float x;\n"
13306 "out gl_PerVertex {\n"
13307 " vec4 gl_Position;\n"
13308 "};\n"
13309 "void main(){\n"
13310 " gl_Position = vec4(1);\n"
13311 " x = 0;\n"
13312 "}\n";
13313 char const *fsSource =
13314 "#version 450\n"
13315 "\n"
13316 "layout(location=0) out vec4 color;\n"
13317 "void main(){\n"
13318 " color = vec4(1);\n"
13319 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013320
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013321 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13322 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013323
13324 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013325 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013326 pipe.AddShader(&vs);
13327 pipe.AddShader(&fs);
13328
Chris Forbes9f7ff632015-05-25 11:13:08 +120013329 VkDescriptorSetObj descriptorSet(m_device);
13330 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013331 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013332
Tony Barbour5781e8f2015-08-04 16:23:11 -060013333 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013334
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013335 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013336}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013337
Mark Mueller098c9cb2016-09-08 09:01:57 -060013338TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13339 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13340
13341 ASSERT_NO_FATAL_FAILURE(InitState());
13342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13343
13344 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013345 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013346
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013347 char const *vsSource =
13348 "#version 450\n"
13349 "\n"
13350 "out gl_PerVertex {\n"
13351 " vec4 gl_Position;\n"
13352 "};\n"
13353 "void main(){\n"
13354 " gl_Position = vec4(1);\n"
13355 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013356
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013357 char const *fsSource =
13358 "#version 450\n"
13359 "\n"
13360 "layout (constant_id = 0) const float r = 0.0f;\n"
13361 "layout(location = 0) out vec4 uFragColor;\n"
13362 "void main(){\n"
13363 " uFragColor = vec4(r,1,0,1);\n"
13364 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013365
13366 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13367 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13368
13369 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13370 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13371
13372 VkPipelineLayout pipeline_layout;
13373 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13374
13375 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13376 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13377 vp_state_create_info.viewportCount = 1;
13378 VkViewport viewport = {};
13379 vp_state_create_info.pViewports = &viewport;
13380 vp_state_create_info.scissorCount = 1;
13381 VkRect2D scissors = {};
13382 vp_state_create_info.pScissors = &scissors;
13383
13384 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13385
13386 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13387 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13388 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13389 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13390
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013391 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013392
13393 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13394 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13395
13396 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13397 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13398 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13399
13400 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13401 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13402 rasterization_state_create_info.pNext = nullptr;
13403 rasterization_state_create_info.lineWidth = 1.0f;
13404 rasterization_state_create_info.rasterizerDiscardEnable = true;
13405
13406 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13407 color_blend_attachment_state.blendEnable = VK_FALSE;
13408 color_blend_attachment_state.colorWriteMask = 0xf;
13409
13410 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13411 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13412 color_blend_state_create_info.attachmentCount = 1;
13413 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13414
13415 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13416 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13417 graphicspipe_create_info.stageCount = 2;
13418 graphicspipe_create_info.pStages = shader_stage_create_info;
13419 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13420 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13421 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13422 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13423 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13424 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13425 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13426 graphicspipe_create_info.layout = pipeline_layout;
13427 graphicspipe_create_info.renderPass = renderPass();
13428
13429 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13430 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13431
13432 VkPipelineCache pipelineCache;
13433 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13434
13435 // This structure maps constant ids to data locations.
13436 const VkSpecializationMapEntry entry =
13437 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013438 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013439
13440 uint32_t data = 1;
13441
13442 // Set up the info describing spec map and data
13443 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013444 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013445 };
13446 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13447
13448 VkPipeline pipeline;
13449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13450 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13451 m_errorMonitor->VerifyFound();
13452
13453 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13454 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13455}
13456
13457TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13458 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13459
13460 ASSERT_NO_FATAL_FAILURE(InitState());
13461 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13462
13463 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13464
13465 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13466 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13467 descriptor_pool_type_count[0].descriptorCount = 1;
13468 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13469 descriptor_pool_type_count[1].descriptorCount = 1;
13470
13471 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13472 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13473 descriptor_pool_create_info.maxSets = 1;
13474 descriptor_pool_create_info.poolSizeCount = 2;
13475 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13476 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13477
13478 VkDescriptorPool descriptorset_pool;
13479 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13480
13481 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13482 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13483 descriptorset_layout_binding.descriptorCount = 1;
13484 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13485
13486 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13487 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13488 descriptorset_layout_create_info.bindingCount = 1;
13489 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13490
13491 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013492 ASSERT_VK_SUCCESS(
13493 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013494
13495 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13496 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13497 descriptorset_allocate_info.descriptorSetCount = 1;
13498 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13499 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13500 VkDescriptorSet descriptorset;
13501 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13502
13503 // Challenge core_validation with a non uniform buffer type.
13504 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13505
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013506 char const *vsSource =
13507 "#version 450\n"
13508 "\n"
13509 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13510 " mat4 mvp;\n"
13511 "} ubuf;\n"
13512 "out gl_PerVertex {\n"
13513 " vec4 gl_Position;\n"
13514 "};\n"
13515 "void main(){\n"
13516 " gl_Position = ubuf.mvp * vec4(1);\n"
13517 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013518
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013519 char const *fsSource =
13520 "#version 450\n"
13521 "\n"
13522 "layout(location = 0) out vec4 uFragColor;\n"
13523 "void main(){\n"
13524 " uFragColor = vec4(0,1,0,1);\n"
13525 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013526
13527 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13528 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13529
13530 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13531 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13532 pipeline_layout_create_info.setLayoutCount = 1;
13533 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13534
13535 VkPipelineLayout pipeline_layout;
13536 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13537
13538 VkPipelineObj pipe(m_device);
13539 pipe.AddColorAttachment();
13540 pipe.AddShader(&vs);
13541 pipe.AddShader(&fs);
13542
13543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13544 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13545 m_errorMonitor->VerifyFound();
13546
13547 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13548 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13549 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13550}
13551
13552TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13553 TEST_DESCRIPTION(
13554 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13555
13556 ASSERT_NO_FATAL_FAILURE(InitState());
13557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13558
13559 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13560
13561 VkDescriptorPoolSize descriptor_pool_type_count = {};
13562 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13563 descriptor_pool_type_count.descriptorCount = 1;
13564
13565 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13566 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13567 descriptor_pool_create_info.maxSets = 1;
13568 descriptor_pool_create_info.poolSizeCount = 1;
13569 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13570 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13571
13572 VkDescriptorPool descriptorset_pool;
13573 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13574
13575 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13576 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13577 descriptorset_layout_binding.descriptorCount = 1;
13578 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13579 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13580
13581 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13582 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13583 descriptorset_layout_create_info.bindingCount = 1;
13584 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13585
13586 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013587 ASSERT_VK_SUCCESS(
13588 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013589
13590 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13591 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13592 descriptorset_allocate_info.descriptorSetCount = 1;
13593 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13594 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13595 VkDescriptorSet descriptorset;
13596 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13597
13598 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13599
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013600 char const *vsSource =
13601 "#version 450\n"
13602 "\n"
13603 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13604 " mat4 mvp;\n"
13605 "} ubuf;\n"
13606 "out gl_PerVertex {\n"
13607 " vec4 gl_Position;\n"
13608 "};\n"
13609 "void main(){\n"
13610 " gl_Position = ubuf.mvp * vec4(1);\n"
13611 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013612
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013613 char const *fsSource =
13614 "#version 450\n"
13615 "\n"
13616 "layout(location = 0) out vec4 uFragColor;\n"
13617 "void main(){\n"
13618 " uFragColor = vec4(0,1,0,1);\n"
13619 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013620
13621 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13622 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13623
13624 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13625 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13626 pipeline_layout_create_info.setLayoutCount = 1;
13627 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13628
13629 VkPipelineLayout pipeline_layout;
13630 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13631
13632 VkPipelineObj pipe(m_device);
13633 pipe.AddColorAttachment();
13634 pipe.AddShader(&vs);
13635 pipe.AddShader(&fs);
13636
13637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13638 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13639 m_errorMonitor->VerifyFound();
13640
13641 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13642 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13643 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13644}
13645
13646TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013647 TEST_DESCRIPTION(
13648 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13649 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013650
13651 ASSERT_NO_FATAL_FAILURE(InitState());
13652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13653
13654 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013655 "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 -060013656
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013657 char const *vsSource =
13658 "#version 450\n"
13659 "\n"
13660 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13661 "out gl_PerVertex {\n"
13662 " vec4 gl_Position;\n"
13663 "};\n"
13664 "void main(){\n"
13665 " gl_Position = vec4(consts.x);\n"
13666 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013667
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013668 char const *fsSource =
13669 "#version 450\n"
13670 "\n"
13671 "layout(location = 0) out vec4 uFragColor;\n"
13672 "void main(){\n"
13673 " uFragColor = vec4(0,1,0,1);\n"
13674 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013675
13676 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13677 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13678
13679 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13680 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13681
13682 // Set up a push constant range
13683 VkPushConstantRange push_constant_ranges = {};
13684 // Set to the wrong stage to challenge core_validation
13685 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13686 push_constant_ranges.size = 4;
13687
13688 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13689 pipeline_layout_create_info.pushConstantRangeCount = 1;
13690
13691 VkPipelineLayout pipeline_layout;
13692 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13693
13694 VkPipelineObj pipe(m_device);
13695 pipe.AddColorAttachment();
13696 pipe.AddShader(&vs);
13697 pipe.AddShader(&fs);
13698
13699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13700 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13701 m_errorMonitor->VerifyFound();
13702
13703 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13704}
13705
13706TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13707 TEST_DESCRIPTION(
13708 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13709
13710 ASSERT_NO_FATAL_FAILURE(InitState());
13711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13712
13713 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013714 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013715
13716 // Some awkward steps are required to test with custom device features.
13717 std::vector<const char *> device_extension_names;
13718 auto features = m_device->phy().features();
13719 // Disable support for 64 bit floats
13720 features.shaderFloat64 = false;
13721 // The sacrificial device object
13722 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13723
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013724 char const *vsSource =
13725 "#version 450\n"
13726 "\n"
13727 "out gl_PerVertex {\n"
13728 " vec4 gl_Position;\n"
13729 "};\n"
13730 "void main(){\n"
13731 " gl_Position = vec4(1);\n"
13732 "}\n";
13733 char const *fsSource =
13734 "#version 450\n"
13735 "\n"
13736 "layout(location=0) out vec4 color;\n"
13737 "void main(){\n"
13738 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13739 " color = vec4(green);\n"
13740 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013741
13742 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13743 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13744
13745 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013746
13747 VkPipelineObj pipe(&test_device);
13748 pipe.AddColorAttachment();
13749 pipe.AddShader(&vs);
13750 pipe.AddShader(&fs);
13751
13752 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13753 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13754 VkPipelineLayout pipeline_layout;
13755 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13756
13757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13758 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13759 m_errorMonitor->VerifyFound();
13760
13761 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13762}
13763
13764TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13765 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13766
13767 ASSERT_NO_FATAL_FAILURE(InitState());
13768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13769
13770 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13771
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013772 char const *vsSource =
13773 "#version 450\n"
13774 "\n"
13775 "out gl_PerVertex {\n"
13776 " vec4 gl_Position;\n"
13777 "};\n"
13778 "layout(xfb_buffer = 1) out;"
13779 "void main(){\n"
13780 " gl_Position = vec4(1);\n"
13781 "}\n";
13782 char const *fsSource =
13783 "#version 450\n"
13784 "\n"
13785 "layout(location=0) out vec4 color;\n"
13786 "void main(){\n"
13787 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13788 " color = vec4(green);\n"
13789 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013790
13791 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13792 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13793
13794 VkPipelineObj pipe(m_device);
13795 pipe.AddColorAttachment();
13796 pipe.AddShader(&vs);
13797 pipe.AddShader(&fs);
13798
13799 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13800 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13801 VkPipelineLayout pipeline_layout;
13802 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13803
13804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13805 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13806 m_errorMonitor->VerifyFound();
13807
13808 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13809}
13810
Karl Schultz6addd812016-02-02 17:17:23 -070013811TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013812 TEST_DESCRIPTION(
13813 "Test that an error is produced for a fragment shader input "
13814 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013817
Chris Forbes59cb88d2015-05-25 11:13:13 +120013818 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013820
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013821 char const *vsSource =
13822 "#version 450\n"
13823 "\n"
13824 "out gl_PerVertex {\n"
13825 " vec4 gl_Position;\n"
13826 "};\n"
13827 "void main(){\n"
13828 " gl_Position = vec4(1);\n"
13829 "}\n";
13830 char const *fsSource =
13831 "#version 450\n"
13832 "\n"
13833 "layout(location=0) in float x;\n"
13834 "layout(location=0) out vec4 color;\n"
13835 "void main(){\n"
13836 " color = vec4(x);\n"
13837 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013838
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013839 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13840 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013841
13842 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013843 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013844 pipe.AddShader(&vs);
13845 pipe.AddShader(&fs);
13846
Chris Forbes59cb88d2015-05-25 11:13:13 +120013847 VkDescriptorSetObj descriptorSet(m_device);
13848 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013849 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013850
Tony Barbour5781e8f2015-08-04 16:23:11 -060013851 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013852
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013853 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013854}
13855
Karl Schultz6addd812016-02-02 17:17:23 -070013856TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013857 TEST_DESCRIPTION(
13858 "Test that an error is produced for a fragment shader input "
13859 "within an interace block, which is not present in the outputs "
13860 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013862
13863 ASSERT_NO_FATAL_FAILURE(InitState());
13864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13865
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013866 char const *vsSource =
13867 "#version 450\n"
13868 "\n"
13869 "out gl_PerVertex {\n"
13870 " vec4 gl_Position;\n"
13871 "};\n"
13872 "void main(){\n"
13873 " gl_Position = vec4(1);\n"
13874 "}\n";
13875 char const *fsSource =
13876 "#version 450\n"
13877 "\n"
13878 "in block { layout(location=0) float x; } ins;\n"
13879 "layout(location=0) out vec4 color;\n"
13880 "void main(){\n"
13881 " color = vec4(ins.x);\n"
13882 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013883
13884 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13885 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13886
13887 VkPipelineObj pipe(m_device);
13888 pipe.AddColorAttachment();
13889 pipe.AddShader(&vs);
13890 pipe.AddShader(&fs);
13891
13892 VkDescriptorSetObj descriptorSet(m_device);
13893 descriptorSet.AppendDummy();
13894 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13895
13896 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13897
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013898 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013899}
13900
Karl Schultz6addd812016-02-02 17:17:23 -070013901TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013902 TEST_DESCRIPTION(
13903 "Test that an error is produced for mismatched array sizes "
13904 "across the vertex->fragment shader interface");
13905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13906 "Type mismatch on location 0.0: 'ptr to "
13907 "output arr[2] of float32' vs 'ptr to "
13908 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013909
13910 ASSERT_NO_FATAL_FAILURE(InitState());
13911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13912
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013913 char const *vsSource =
13914 "#version 450\n"
13915 "\n"
13916 "layout(location=0) out float x[2];\n"
13917 "out gl_PerVertex {\n"
13918 " vec4 gl_Position;\n"
13919 "};\n"
13920 "void main(){\n"
13921 " x[0] = 0; x[1] = 0;\n"
13922 " gl_Position = vec4(1);\n"
13923 "}\n";
13924 char const *fsSource =
13925 "#version 450\n"
13926 "\n"
13927 "layout(location=0) in float x[1];\n"
13928 "layout(location=0) out vec4 color;\n"
13929 "void main(){\n"
13930 " color = vec4(x[0]);\n"
13931 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013932
13933 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13934 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13935
13936 VkPipelineObj pipe(m_device);
13937 pipe.AddColorAttachment();
13938 pipe.AddShader(&vs);
13939 pipe.AddShader(&fs);
13940
13941 VkDescriptorSetObj descriptorSet(m_device);
13942 descriptorSet.AppendDummy();
13943 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13944
13945 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13946
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013947 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013948}
13949
Karl Schultz6addd812016-02-02 17:17:23 -070013950TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013951 TEST_DESCRIPTION(
13952 "Test that an error is produced for mismatched types across "
13953 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013955
Chris Forbesb56af562015-05-25 11:13:17 +120013956 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013958
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013959 char const *vsSource =
13960 "#version 450\n"
13961 "\n"
13962 "layout(location=0) out int x;\n"
13963 "out gl_PerVertex {\n"
13964 " vec4 gl_Position;\n"
13965 "};\n"
13966 "void main(){\n"
13967 " x = 0;\n"
13968 " gl_Position = vec4(1);\n"
13969 "}\n";
13970 char const *fsSource =
13971 "#version 450\n"
13972 "\n"
13973 "layout(location=0) in float x;\n" /* VS writes int */
13974 "layout(location=0) out vec4 color;\n"
13975 "void main(){\n"
13976 " color = vec4(x);\n"
13977 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013978
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013981
13982 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013983 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013984 pipe.AddShader(&vs);
13985 pipe.AddShader(&fs);
13986
Chris Forbesb56af562015-05-25 11:13:17 +120013987 VkDescriptorSetObj descriptorSet(m_device);
13988 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013990
Tony Barbour5781e8f2015-08-04 16:23:11 -060013991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013992
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013993 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013994}
13995
Karl Schultz6addd812016-02-02 17:17:23 -070013996TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013997 TEST_DESCRIPTION(
13998 "Test that an error is produced for mismatched types across "
13999 "the vertex->fragment shader interface, when the variable is contained within "
14000 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014002
14003 ASSERT_NO_FATAL_FAILURE(InitState());
14004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14005
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014006 char const *vsSource =
14007 "#version 450\n"
14008 "\n"
14009 "out block { layout(location=0) int x; } outs;\n"
14010 "out gl_PerVertex {\n"
14011 " vec4 gl_Position;\n"
14012 "};\n"
14013 "void main(){\n"
14014 " outs.x = 0;\n"
14015 " gl_Position = vec4(1);\n"
14016 "}\n";
14017 char const *fsSource =
14018 "#version 450\n"
14019 "\n"
14020 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14021 "layout(location=0) out vec4 color;\n"
14022 "void main(){\n"
14023 " color = vec4(ins.x);\n"
14024 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014025
14026 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14027 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14028
14029 VkPipelineObj pipe(m_device);
14030 pipe.AddColorAttachment();
14031 pipe.AddShader(&vs);
14032 pipe.AddShader(&fs);
14033
14034 VkDescriptorSetObj descriptorSet(m_device);
14035 descriptorSet.AppendDummy();
14036 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14037
14038 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14039
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014040 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014041}
14042
14043TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014044 TEST_DESCRIPTION(
14045 "Test that an error is produced for location mismatches across "
14046 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14047 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014048 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 +130014049
14050 ASSERT_NO_FATAL_FAILURE(InitState());
14051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14052
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014053 char const *vsSource =
14054 "#version 450\n"
14055 "\n"
14056 "out block { layout(location=1) float x; } outs;\n"
14057 "out gl_PerVertex {\n"
14058 " vec4 gl_Position;\n"
14059 "};\n"
14060 "void main(){\n"
14061 " outs.x = 0;\n"
14062 " gl_Position = vec4(1);\n"
14063 "}\n";
14064 char const *fsSource =
14065 "#version 450\n"
14066 "\n"
14067 "in block { layout(location=0) float x; } ins;\n"
14068 "layout(location=0) out vec4 color;\n"
14069 "void main(){\n"
14070 " color = vec4(ins.x);\n"
14071 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014072
14073 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14074 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14075
14076 VkPipelineObj pipe(m_device);
14077 pipe.AddColorAttachment();
14078 pipe.AddShader(&vs);
14079 pipe.AddShader(&fs);
14080
14081 VkDescriptorSetObj descriptorSet(m_device);
14082 descriptorSet.AppendDummy();
14083 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14084
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014085 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014086 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14087
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014088 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014089}
14090
14091TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014092 TEST_DESCRIPTION(
14093 "Test that an error is produced for component mismatches across the "
14094 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14095 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014096 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 +130014097
14098 ASSERT_NO_FATAL_FAILURE(InitState());
14099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14100
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014101 char const *vsSource =
14102 "#version 450\n"
14103 "\n"
14104 "out block { layout(location=0, component=0) float x; } outs;\n"
14105 "out gl_PerVertex {\n"
14106 " vec4 gl_Position;\n"
14107 "};\n"
14108 "void main(){\n"
14109 " outs.x = 0;\n"
14110 " gl_Position = vec4(1);\n"
14111 "}\n";
14112 char const *fsSource =
14113 "#version 450\n"
14114 "\n"
14115 "in block { layout(location=0, component=1) float x; } ins;\n"
14116 "layout(location=0) out vec4 color;\n"
14117 "void main(){\n"
14118 " color = vec4(ins.x);\n"
14119 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014120
14121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14123
14124 VkPipelineObj pipe(m_device);
14125 pipe.AddColorAttachment();
14126 pipe.AddShader(&vs);
14127 pipe.AddShader(&fs);
14128
14129 VkDescriptorSetObj descriptorSet(m_device);
14130 descriptorSet.AppendDummy();
14131 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14132
14133 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014135 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014136}
14137
Chris Forbes1f3b0152016-11-30 12:48:40 +130014138TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14139 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14140
14141 ASSERT_NO_FATAL_FAILURE(InitState());
14142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14143
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014144 char const *vsSource =
14145 "#version 450\n"
14146 "layout(location=0) out mediump float x;\n"
14147 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14148 char const *fsSource =
14149 "#version 450\n"
14150 "layout(location=0) in highp float x;\n"
14151 "layout(location=0) out vec4 color;\n"
14152 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014153
14154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14156
14157 VkPipelineObj pipe(m_device);
14158 pipe.AddColorAttachment();
14159 pipe.AddShader(&vs);
14160 pipe.AddShader(&fs);
14161
14162 VkDescriptorSetObj descriptorSet(m_device);
14163 descriptorSet.AppendDummy();
14164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14165
14166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14167
14168 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14169
14170 m_errorMonitor->VerifyFound();
14171}
14172
Chris Forbes870a39e2016-11-30 12:55:56 +130014173TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14174 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14175
14176 ASSERT_NO_FATAL_FAILURE(InitState());
14177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14178
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014179 char const *vsSource =
14180 "#version 450\n"
14181 "out block { layout(location=0) mediump float x; };\n"
14182 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14183 char const *fsSource =
14184 "#version 450\n"
14185 "in block { layout(location=0) highp float x; };\n"
14186 "layout(location=0) out vec4 color;\n"
14187 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014188
14189 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14190 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14191
14192 VkPipelineObj pipe(m_device);
14193 pipe.AddColorAttachment();
14194 pipe.AddShader(&vs);
14195 pipe.AddShader(&fs);
14196
14197 VkDescriptorSetObj descriptorSet(m_device);
14198 descriptorSet.AppendDummy();
14199 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14200
14201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14202
14203 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14204
14205 m_errorMonitor->VerifyFound();
14206}
14207
Karl Schultz6addd812016-02-02 17:17:23 -070014208TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014209 TEST_DESCRIPTION(
14210 "Test that a warning is produced for a vertex attribute which is "
14211 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014213
Chris Forbesde136e02015-05-25 11:13:28 +120014214 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014216
14217 VkVertexInputBindingDescription input_binding;
14218 memset(&input_binding, 0, sizeof(input_binding));
14219
14220 VkVertexInputAttributeDescription input_attrib;
14221 memset(&input_attrib, 0, sizeof(input_attrib));
14222 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14223
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014224 char const *vsSource =
14225 "#version 450\n"
14226 "\n"
14227 "out gl_PerVertex {\n"
14228 " vec4 gl_Position;\n"
14229 "};\n"
14230 "void main(){\n"
14231 " gl_Position = vec4(1);\n"
14232 "}\n";
14233 char const *fsSource =
14234 "#version 450\n"
14235 "\n"
14236 "layout(location=0) out vec4 color;\n"
14237 "void main(){\n"
14238 " color = vec4(1);\n"
14239 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014240
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014241 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14242 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014243
14244 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014245 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014246 pipe.AddShader(&vs);
14247 pipe.AddShader(&fs);
14248
14249 pipe.AddVertexInputBindings(&input_binding, 1);
14250 pipe.AddVertexInputAttribs(&input_attrib, 1);
14251
Chris Forbesde136e02015-05-25 11:13:28 +120014252 VkDescriptorSetObj descriptorSet(m_device);
14253 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014255
Tony Barbour5781e8f2015-08-04 16:23:11 -060014256 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014258 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014259}
14260
Karl Schultz6addd812016-02-02 17:17:23 -070014261TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014262 TEST_DESCRIPTION(
14263 "Test that a warning is produced for a location mismatch on "
14264 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014266
14267 ASSERT_NO_FATAL_FAILURE(InitState());
14268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14269
14270 VkVertexInputBindingDescription input_binding;
14271 memset(&input_binding, 0, sizeof(input_binding));
14272
14273 VkVertexInputAttributeDescription input_attrib;
14274 memset(&input_attrib, 0, sizeof(input_attrib));
14275 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14276
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014277 char const *vsSource =
14278 "#version 450\n"
14279 "\n"
14280 "layout(location=1) in float x;\n"
14281 "out gl_PerVertex {\n"
14282 " vec4 gl_Position;\n"
14283 "};\n"
14284 "void main(){\n"
14285 " gl_Position = vec4(x);\n"
14286 "}\n";
14287 char const *fsSource =
14288 "#version 450\n"
14289 "\n"
14290 "layout(location=0) out vec4 color;\n"
14291 "void main(){\n"
14292 " color = vec4(1);\n"
14293 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014294
14295 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14296 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14297
14298 VkPipelineObj pipe(m_device);
14299 pipe.AddColorAttachment();
14300 pipe.AddShader(&vs);
14301 pipe.AddShader(&fs);
14302
14303 pipe.AddVertexInputBindings(&input_binding, 1);
14304 pipe.AddVertexInputAttribs(&input_attrib, 1);
14305
14306 VkDescriptorSetObj descriptorSet(m_device);
14307 descriptorSet.AppendDummy();
14308 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14309
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014310 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014311 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14312
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014313 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014314}
14315
Karl Schultz6addd812016-02-02 17:17:23 -070014316TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014317 TEST_DESCRIPTION(
14318 "Test that an error is produced for a vertex shader input which is not "
14319 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14321 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014322
Chris Forbes62e8e502015-05-25 11:13:29 +120014323 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014325
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014326 char const *vsSource =
14327 "#version 450\n"
14328 "\n"
14329 "layout(location=0) in vec4 x;\n" /* not provided */
14330 "out gl_PerVertex {\n"
14331 " vec4 gl_Position;\n"
14332 "};\n"
14333 "void main(){\n"
14334 " gl_Position = x;\n"
14335 "}\n";
14336 char const *fsSource =
14337 "#version 450\n"
14338 "\n"
14339 "layout(location=0) out vec4 color;\n"
14340 "void main(){\n"
14341 " color = vec4(1);\n"
14342 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014343
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014344 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14345 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014346
14347 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014348 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014349 pipe.AddShader(&vs);
14350 pipe.AddShader(&fs);
14351
Chris Forbes62e8e502015-05-25 11:13:29 +120014352 VkDescriptorSetObj descriptorSet(m_device);
14353 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014354 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014355
Tony Barbour5781e8f2015-08-04 16:23:11 -060014356 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014357
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014358 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014359}
14360
Karl Schultz6addd812016-02-02 17:17:23 -070014361TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014362 TEST_DESCRIPTION(
14363 "Test that an error is produced for a mismatch between the "
14364 "fundamental type (float/int/uint) of an attribute and the "
14365 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014366 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 -060014367
Chris Forbesc97d98e2015-05-25 11:13:31 +120014368 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014370
14371 VkVertexInputBindingDescription input_binding;
14372 memset(&input_binding, 0, sizeof(input_binding));
14373
14374 VkVertexInputAttributeDescription input_attrib;
14375 memset(&input_attrib, 0, sizeof(input_attrib));
14376 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14377
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014378 char const *vsSource =
14379 "#version 450\n"
14380 "\n"
14381 "layout(location=0) in int x;\n" /* attrib provided float */
14382 "out gl_PerVertex {\n"
14383 " vec4 gl_Position;\n"
14384 "};\n"
14385 "void main(){\n"
14386 " gl_Position = vec4(x);\n"
14387 "}\n";
14388 char const *fsSource =
14389 "#version 450\n"
14390 "\n"
14391 "layout(location=0) out vec4 color;\n"
14392 "void main(){\n"
14393 " color = vec4(1);\n"
14394 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014395
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014396 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14397 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014398
14399 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014400 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014401 pipe.AddShader(&vs);
14402 pipe.AddShader(&fs);
14403
14404 pipe.AddVertexInputBindings(&input_binding, 1);
14405 pipe.AddVertexInputAttribs(&input_attrib, 1);
14406
Chris Forbesc97d98e2015-05-25 11:13:31 +120014407 VkDescriptorSetObj descriptorSet(m_device);
14408 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014409 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014410
Tony Barbour5781e8f2015-08-04 16:23:11 -060014411 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014412
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014413 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014414}
14415
Chris Forbesc68b43c2016-04-06 11:18:47 +120014416TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014417 TEST_DESCRIPTION(
14418 "Test that an error is produced for a pipeline containing multiple "
14419 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14421 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014422
14423 ASSERT_NO_FATAL_FAILURE(InitState());
14424 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14425
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014426 char const *vsSource =
14427 "#version 450\n"
14428 "\n"
14429 "out gl_PerVertex {\n"
14430 " vec4 gl_Position;\n"
14431 "};\n"
14432 "void main(){\n"
14433 " gl_Position = vec4(1);\n"
14434 "}\n";
14435 char const *fsSource =
14436 "#version 450\n"
14437 "\n"
14438 "layout(location=0) out vec4 color;\n"
14439 "void main(){\n"
14440 " color = vec4(1);\n"
14441 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014442
14443 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14444 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14445
14446 VkPipelineObj pipe(m_device);
14447 pipe.AddColorAttachment();
14448 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014449 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014450 pipe.AddShader(&fs);
14451
14452 VkDescriptorSetObj descriptorSet(m_device);
14453 descriptorSet.AppendDummy();
14454 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14455
14456 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14457
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014458 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014459}
14460
Chris Forbes82ff92a2016-09-09 10:50:24 +120014461TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014463
14464 ASSERT_NO_FATAL_FAILURE(InitState());
14465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14466
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014467 char const *vsSource =
14468 "#version 450\n"
14469 "out gl_PerVertex {\n"
14470 " vec4 gl_Position;\n"
14471 "};\n"
14472 "void main(){\n"
14473 " gl_Position = vec4(0);\n"
14474 "}\n";
14475 char const *fsSource =
14476 "#version 450\n"
14477 "\n"
14478 "layout(location=0) out vec4 color;\n"
14479 "void main(){\n"
14480 " color = vec4(1);\n"
14481 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014482
14483 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14484 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14485
14486 VkPipelineObj pipe(m_device);
14487 pipe.AddColorAttachment();
14488 pipe.AddShader(&vs);
14489 pipe.AddShader(&fs);
14490
14491 VkDescriptorSetObj descriptorSet(m_device);
14492 descriptorSet.AppendDummy();
14493 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14494
14495 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14496
14497 m_errorMonitor->VerifyFound();
14498}
14499
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014500TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14502 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14503 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014504
14505 ASSERT_NO_FATAL_FAILURE(InitState());
14506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14507
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014508 char const *vsSource =
14509 "#version 450\n"
14510 "void main(){ gl_Position = vec4(0); }\n";
14511 char const *fsSource =
14512 "#version 450\n"
14513 "\n"
14514 "layout(location=0) out vec4 color;\n"
14515 "void main(){\n"
14516 " color = vec4(1);\n"
14517 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014518
14519 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14521
14522 VkPipelineObj pipe(m_device);
14523 pipe.AddColorAttachment();
14524 pipe.AddShader(&vs);
14525 pipe.AddShader(&fs);
14526
14527 VkDescriptorSetObj descriptorSet(m_device);
14528 descriptorSet.AppendDummy();
14529 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14530
14531 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014532 {
14533 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14534 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14535 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014536 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014537 {
14538 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14539 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14540 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014541 },
14542 };
14543 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014544 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014545 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014546 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14547 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014548 VkRenderPass rp;
14549 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14550 ASSERT_VK_SUCCESS(err);
14551
14552 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14553
14554 m_errorMonitor->VerifyFound();
14555
14556 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14557}
14558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014559TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014560 TEST_DESCRIPTION(
14561 "Test that an error is produced for a variable output from "
14562 "the TCS without the patch decoration, but consumed in the TES "
14563 "with the decoration.");
14564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14565 "is per-vertex in tessellation control shader stage "
14566 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014567
14568 ASSERT_NO_FATAL_FAILURE(InitState());
14569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14570
Chris Forbesc1e852d2016-04-04 19:26:42 +120014571 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014572 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014573 return;
14574 }
14575
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014576 char const *vsSource =
14577 "#version 450\n"
14578 "void main(){}\n";
14579 char const *tcsSource =
14580 "#version 450\n"
14581 "layout(location=0) out int x[];\n"
14582 "layout(vertices=3) out;\n"
14583 "void main(){\n"
14584 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14585 " gl_TessLevelInner[0] = 1;\n"
14586 " x[gl_InvocationID] = gl_InvocationID;\n"
14587 "}\n";
14588 char const *tesSource =
14589 "#version 450\n"
14590 "layout(triangles, equal_spacing, cw) in;\n"
14591 "layout(location=0) patch in int x;\n"
14592 "out gl_PerVertex { vec4 gl_Position; };\n"
14593 "void main(){\n"
14594 " gl_Position.xyz = gl_TessCoord;\n"
14595 " gl_Position.w = x;\n"
14596 "}\n";
14597 char const *fsSource =
14598 "#version 450\n"
14599 "layout(location=0) out vec4 color;\n"
14600 "void main(){\n"
14601 " color = vec4(1);\n"
14602 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014603
14604 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14605 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14606 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014609 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14610 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014612 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014613
14614 VkPipelineObj pipe(m_device);
14615 pipe.SetInputAssembly(&iasci);
14616 pipe.SetTessellation(&tsci);
14617 pipe.AddColorAttachment();
14618 pipe.AddShader(&vs);
14619 pipe.AddShader(&tcs);
14620 pipe.AddShader(&tes);
14621 pipe.AddShader(&fs);
14622
14623 VkDescriptorSetObj descriptorSet(m_device);
14624 descriptorSet.AppendDummy();
14625 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14626
14627 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14628
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014629 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014630}
14631
Karl Schultz6addd812016-02-02 17:17:23 -070014632TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014633 TEST_DESCRIPTION(
14634 "Test that an error is produced for a vertex attribute setup where multiple "
14635 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14637 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014638
Chris Forbes280ba2c2015-06-12 11:16:41 +120014639 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014641
14642 /* Two binding descriptions for binding 0 */
14643 VkVertexInputBindingDescription input_bindings[2];
14644 memset(input_bindings, 0, sizeof(input_bindings));
14645
14646 VkVertexInputAttributeDescription input_attrib;
14647 memset(&input_attrib, 0, sizeof(input_attrib));
14648 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14649
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014650 char const *vsSource =
14651 "#version 450\n"
14652 "\n"
14653 "layout(location=0) in float x;\n" /* attrib provided float */
14654 "out gl_PerVertex {\n"
14655 " vec4 gl_Position;\n"
14656 "};\n"
14657 "void main(){\n"
14658 " gl_Position = vec4(x);\n"
14659 "}\n";
14660 char const *fsSource =
14661 "#version 450\n"
14662 "\n"
14663 "layout(location=0) out vec4 color;\n"
14664 "void main(){\n"
14665 " color = vec4(1);\n"
14666 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014667
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014668 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14669 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014670
14671 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014672 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014673 pipe.AddShader(&vs);
14674 pipe.AddShader(&fs);
14675
14676 pipe.AddVertexInputBindings(input_bindings, 2);
14677 pipe.AddVertexInputAttribs(&input_attrib, 1);
14678
Chris Forbes280ba2c2015-06-12 11:16:41 +120014679 VkDescriptorSetObj descriptorSet(m_device);
14680 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014681 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014682
Tony Barbour5781e8f2015-08-04 16:23:11 -060014683 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014684
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014685 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014686}
Chris Forbes8f68b562015-05-25 11:13:32 +120014687
Karl Schultz6addd812016-02-02 17:17:23 -070014688TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014689 TEST_DESCRIPTION(
14690 "Test that an error is produced for a fragment shader which does not "
14691 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014693
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014694 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014695
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014696 char const *vsSource =
14697 "#version 450\n"
14698 "\n"
14699 "out gl_PerVertex {\n"
14700 " vec4 gl_Position;\n"
14701 "};\n"
14702 "void main(){\n"
14703 " gl_Position = vec4(1);\n"
14704 "}\n";
14705 char const *fsSource =
14706 "#version 450\n"
14707 "\n"
14708 "void main(){\n"
14709 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014710
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014711 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14712 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014713
14714 VkPipelineObj pipe(m_device);
14715 pipe.AddShader(&vs);
14716 pipe.AddShader(&fs);
14717
Chia-I Wu08accc62015-07-07 11:50:03 +080014718 /* set up CB 0, not written */
14719 pipe.AddColorAttachment();
14720 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014721
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014722 VkDescriptorSetObj descriptorSet(m_device);
14723 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014724 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014725
Tony Barbour5781e8f2015-08-04 16:23:11 -060014726 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014727
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014728 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014729}
14730
Karl Schultz6addd812016-02-02 17:17:23 -070014731TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014732 TEST_DESCRIPTION(
14733 "Test that a warning is produced for a fragment shader which provides a spurious "
14734 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014736 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014737
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014738 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014739
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014740 char const *vsSource =
14741 "#version 450\n"
14742 "\n"
14743 "out gl_PerVertex {\n"
14744 " vec4 gl_Position;\n"
14745 "};\n"
14746 "void main(){\n"
14747 " gl_Position = vec4(1);\n"
14748 "}\n";
14749 char const *fsSource =
14750 "#version 450\n"
14751 "\n"
14752 "layout(location=0) out vec4 x;\n"
14753 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14754 "void main(){\n"
14755 " x = vec4(1);\n"
14756 " y = vec4(1);\n"
14757 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014758
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014761
14762 VkPipelineObj pipe(m_device);
14763 pipe.AddShader(&vs);
14764 pipe.AddShader(&fs);
14765
Chia-I Wu08accc62015-07-07 11:50:03 +080014766 /* set up CB 0, not written */
14767 pipe.AddColorAttachment();
14768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014769 /* FS writes CB 1, but we don't configure it */
14770
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014771 VkDescriptorSetObj descriptorSet(m_device);
14772 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014773 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014774
Tony Barbour5781e8f2015-08-04 16:23:11 -060014775 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014776
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014777 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014778}
14779
Karl Schultz6addd812016-02-02 17:17:23 -070014780TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014781 TEST_DESCRIPTION(
14782 "Test that an error is produced for a mismatch between the fundamental "
14783 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014785
Chris Forbesa36d69e2015-05-25 11:13:44 +120014786 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014787
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014788 char const *vsSource =
14789 "#version 450\n"
14790 "\n"
14791 "out gl_PerVertex {\n"
14792 " vec4 gl_Position;\n"
14793 "};\n"
14794 "void main(){\n"
14795 " gl_Position = vec4(1);\n"
14796 "}\n";
14797 char const *fsSource =
14798 "#version 450\n"
14799 "\n"
14800 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14801 "void main(){\n"
14802 " x = ivec4(1);\n"
14803 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014804
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014805 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14806 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014807
14808 VkPipelineObj pipe(m_device);
14809 pipe.AddShader(&vs);
14810 pipe.AddShader(&fs);
14811
Chia-I Wu08accc62015-07-07 11:50:03 +080014812 /* set up CB 0; type is UNORM by default */
14813 pipe.AddColorAttachment();
14814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014815
Chris Forbesa36d69e2015-05-25 11:13:44 +120014816 VkDescriptorSetObj descriptorSet(m_device);
14817 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014818 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014819
Tony Barbour5781e8f2015-08-04 16:23:11 -060014820 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014821
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014822 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014823}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014824
Karl Schultz6addd812016-02-02 17:17:23 -070014825TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014826 TEST_DESCRIPTION(
14827 "Test that an error is produced for a shader consuming a uniform "
14828 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014830
Chris Forbes556c76c2015-08-14 12:04:59 +120014831 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014832
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014833 char const *vsSource =
14834 "#version 450\n"
14835 "\n"
14836 "out gl_PerVertex {\n"
14837 " vec4 gl_Position;\n"
14838 "};\n"
14839 "void main(){\n"
14840 " gl_Position = vec4(1);\n"
14841 "}\n";
14842 char const *fsSource =
14843 "#version 450\n"
14844 "\n"
14845 "layout(location=0) out vec4 x;\n"
14846 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14847 "void main(){\n"
14848 " x = vec4(bar.y);\n"
14849 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014850
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014851 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14852 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014853
Chris Forbes556c76c2015-08-14 12:04:59 +120014854 VkPipelineObj pipe(m_device);
14855 pipe.AddShader(&vs);
14856 pipe.AddShader(&fs);
14857
14858 /* set up CB 0; type is UNORM by default */
14859 pipe.AddColorAttachment();
14860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14861
14862 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014863 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014864
14865 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14866
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014867 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014868}
14869
Chris Forbes5c59e902016-02-26 16:56:09 +130014870TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014871 TEST_DESCRIPTION(
14872 "Test that an error is produced for a shader consuming push constants "
14873 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014875
14876 ASSERT_NO_FATAL_FAILURE(InitState());
14877
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014878 char const *vsSource =
14879 "#version 450\n"
14880 "\n"
14881 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14882 "out gl_PerVertex {\n"
14883 " vec4 gl_Position;\n"
14884 "};\n"
14885 "void main(){\n"
14886 " gl_Position = vec4(consts.x);\n"
14887 "}\n";
14888 char const *fsSource =
14889 "#version 450\n"
14890 "\n"
14891 "layout(location=0) out vec4 x;\n"
14892 "void main(){\n"
14893 " x = vec4(1);\n"
14894 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014895
14896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14898
14899 VkPipelineObj pipe(m_device);
14900 pipe.AddShader(&vs);
14901 pipe.AddShader(&fs);
14902
14903 /* set up CB 0; type is UNORM by default */
14904 pipe.AddColorAttachment();
14905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14906
14907 VkDescriptorSetObj descriptorSet(m_device);
14908 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14909
14910 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14911
14912 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014913 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014914}
14915
Chris Forbes3fb17902016-08-22 14:57:55 +120014916TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014917 TEST_DESCRIPTION(
14918 "Test that an error is produced for a shader consuming an input attachment "
14919 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14921 "consumes input attachment index 0 but not provided in subpass");
14922
14923 ASSERT_NO_FATAL_FAILURE(InitState());
14924
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014925 char const *vsSource =
14926 "#version 450\n"
14927 "\n"
14928 "out gl_PerVertex {\n"
14929 " vec4 gl_Position;\n"
14930 "};\n"
14931 "void main(){\n"
14932 " gl_Position = vec4(1);\n"
14933 "}\n";
14934 char const *fsSource =
14935 "#version 450\n"
14936 "\n"
14937 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14938 "layout(location=0) out vec4 color;\n"
14939 "void main() {\n"
14940 " color = subpassLoad(x);\n"
14941 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014942
14943 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14944 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14945
14946 VkPipelineObj pipe(m_device);
14947 pipe.AddShader(&vs);
14948 pipe.AddShader(&fs);
14949 pipe.AddColorAttachment();
14950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014952 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14953 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014954 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014955 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014956 ASSERT_VK_SUCCESS(err);
14957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014958 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014959 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014960 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014961 ASSERT_VK_SUCCESS(err);
14962
14963 // error here.
14964 pipe.CreateVKPipeline(pl, renderPass());
14965
14966 m_errorMonitor->VerifyFound();
14967
14968 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14969 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14970}
14971
Chris Forbes5a9a0472016-08-22 16:02:09 +120014972TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014973 TEST_DESCRIPTION(
14974 "Test that an error is produced for a shader consuming an input attachment "
14975 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14977 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14978
14979 ASSERT_NO_FATAL_FAILURE(InitState());
14980
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014981 char const *vsSource =
14982 "#version 450\n"
14983 "\n"
14984 "out gl_PerVertex {\n"
14985 " vec4 gl_Position;\n"
14986 "};\n"
14987 "void main(){\n"
14988 " gl_Position = vec4(1);\n"
14989 "}\n";
14990 char const *fsSource =
14991 "#version 450\n"
14992 "\n"
14993 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14994 "layout(location=0) out vec4 color;\n"
14995 "void main() {\n"
14996 " color = subpassLoad(x);\n"
14997 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014998
14999 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15000 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15001
15002 VkPipelineObj pipe(m_device);
15003 pipe.AddShader(&vs);
15004 pipe.AddShader(&fs);
15005 pipe.AddColorAttachment();
15006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015008 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15009 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015010 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015011 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015012 ASSERT_VK_SUCCESS(err);
15013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015014 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015015 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015017 ASSERT_VK_SUCCESS(err);
15018
15019 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015020 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15021 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15022 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15023 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15024 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 +120015025 };
15026 VkAttachmentReference color = {
15027 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15028 };
15029 VkAttachmentReference input = {
15030 1, VK_IMAGE_LAYOUT_GENERAL,
15031 };
15032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015033 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015035 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015036 VkRenderPass rp;
15037 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15038 ASSERT_VK_SUCCESS(err);
15039
15040 // error here.
15041 pipe.CreateVKPipeline(pl, rp);
15042
15043 m_errorMonitor->VerifyFound();
15044
15045 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15046 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15047 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15048}
15049
Chris Forbes541f7b02016-08-22 15:30:27 +120015050TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015051 TEST_DESCRIPTION(
15052 "Test that an error is produced for a shader consuming an input attachment "
15053 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015055 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015056
15057 ASSERT_NO_FATAL_FAILURE(InitState());
15058
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015059 char const *vsSource =
15060 "#version 450\n"
15061 "\n"
15062 "out gl_PerVertex {\n"
15063 " vec4 gl_Position;\n"
15064 "};\n"
15065 "void main(){\n"
15066 " gl_Position = vec4(1);\n"
15067 "}\n";
15068 char const *fsSource =
15069 "#version 450\n"
15070 "\n"
15071 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15072 "layout(location=0) out vec4 color;\n"
15073 "void main() {\n"
15074 " color = subpassLoad(xs[0]);\n"
15075 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015076
15077 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15078 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15079
15080 VkPipelineObj pipe(m_device);
15081 pipe.AddShader(&vs);
15082 pipe.AddShader(&fs);
15083 pipe.AddColorAttachment();
15084 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15085
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015086 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15087 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015088 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015089 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015090 ASSERT_VK_SUCCESS(err);
15091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015092 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015093 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015094 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015095 ASSERT_VK_SUCCESS(err);
15096
15097 // error here.
15098 pipe.CreateVKPipeline(pl, renderPass());
15099
15100 m_errorMonitor->VerifyFound();
15101
15102 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15103 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15104}
15105
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015106TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015107 TEST_DESCRIPTION(
15108 "Test that an error is produced for a compute pipeline consuming a "
15109 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015111
15112 ASSERT_NO_FATAL_FAILURE(InitState());
15113
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015114 char const *csSource =
15115 "#version 450\n"
15116 "\n"
15117 "layout(local_size_x=1) in;\n"
15118 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15119 "void main(){\n"
15120 " x = vec4(1);\n"
15121 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015122
15123 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15124
15125 VkDescriptorSetObj descriptorSet(m_device);
15126 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015128 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15129 nullptr,
15130 0,
15131 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15132 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15133 descriptorSet.GetPipelineLayout(),
15134 VK_NULL_HANDLE,
15135 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015136
15137 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015138 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015139
15140 m_errorMonitor->VerifyFound();
15141
15142 if (err == VK_SUCCESS) {
15143 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15144 }
15145}
15146
Chris Forbes22a9b092016-07-19 14:34:05 +120015147TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015148 TEST_DESCRIPTION(
15149 "Test that an error is produced for a pipeline consuming a "
15150 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15152 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015153
15154 ASSERT_NO_FATAL_FAILURE(InitState());
15155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015156 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15157 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015158 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015159 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015160 ASSERT_VK_SUCCESS(err);
15161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015162 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015163 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015164 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015165 ASSERT_VK_SUCCESS(err);
15166
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015167 char const *csSource =
15168 "#version 450\n"
15169 "\n"
15170 "layout(local_size_x=1) in;\n"
15171 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15172 "void main() {\n"
15173 " x.x = 1.0f;\n"
15174 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015175 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015177 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15178 nullptr,
15179 0,
15180 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15181 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15182 pl,
15183 VK_NULL_HANDLE,
15184 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015185
15186 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015187 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015188
15189 m_errorMonitor->VerifyFound();
15190
15191 if (err == VK_SUCCESS) {
15192 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15193 }
15194
15195 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15196 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15197}
15198
Chris Forbes50020592016-07-27 13:52:41 +120015199TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015200 TEST_DESCRIPTION(
15201 "Test that an error is produced when an image view type "
15202 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015204 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 +120015205
15206 ASSERT_NO_FATAL_FAILURE(InitState());
15207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15208
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015209 char const *vsSource =
15210 "#version 450\n"
15211 "\n"
15212 "out gl_PerVertex { vec4 gl_Position; };\n"
15213 "void main() { gl_Position = vec4(0); }\n";
15214 char const *fsSource =
15215 "#version 450\n"
15216 "\n"
15217 "layout(set=0, binding=0) uniform sampler3D s;\n"
15218 "layout(location=0) out vec4 color;\n"
15219 "void main() {\n"
15220 " color = texture(s, vec3(0));\n"
15221 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015222 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15223 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15224
15225 VkPipelineObj pipe(m_device);
15226 pipe.AddShader(&vs);
15227 pipe.AddShader(&fs);
15228 pipe.AddColorAttachment();
15229
15230 VkTextureObj texture(m_device, nullptr);
15231 VkSamplerObj sampler(m_device);
15232
15233 VkDescriptorSetObj descriptorSet(m_device);
15234 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15235 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15236
15237 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15238 ASSERT_VK_SUCCESS(err);
15239
Tony Barbour552f6c02016-12-21 14:34:07 -070015240 m_commandBuffer->BeginCommandBuffer();
15241 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015242
15243 m_commandBuffer->BindPipeline(pipe);
15244 m_commandBuffer->BindDescriptorSet(descriptorSet);
15245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015246 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015247 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015248 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015249 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15250
15251 // error produced here.
15252 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15253
15254 m_errorMonitor->VerifyFound();
15255
Tony Barbour552f6c02016-12-21 14:34:07 -070015256 m_commandBuffer->EndRenderPass();
15257 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015258}
15259
Chris Forbes5533bfc2016-07-27 14:12:34 +120015260TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015261 TEST_DESCRIPTION(
15262 "Test that an error is produced when a multisampled images "
15263 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015266
15267 ASSERT_NO_FATAL_FAILURE(InitState());
15268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15269
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015270 char const *vsSource =
15271 "#version 450\n"
15272 "\n"
15273 "out gl_PerVertex { vec4 gl_Position; };\n"
15274 "void main() { gl_Position = vec4(0); }\n";
15275 char const *fsSource =
15276 "#version 450\n"
15277 "\n"
15278 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15279 "layout(location=0) out vec4 color;\n"
15280 "void main() {\n"
15281 " color = texelFetch(s, ivec2(0), 0);\n"
15282 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15285
15286 VkPipelineObj pipe(m_device);
15287 pipe.AddShader(&vs);
15288 pipe.AddShader(&fs);
15289 pipe.AddColorAttachment();
15290
15291 VkTextureObj texture(m_device, nullptr);
15292 VkSamplerObj sampler(m_device);
15293
15294 VkDescriptorSetObj descriptorSet(m_device);
15295 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15296 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15297
15298 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15299 ASSERT_VK_SUCCESS(err);
15300
Tony Barbour552f6c02016-12-21 14:34:07 -070015301 m_commandBuffer->BeginCommandBuffer();
15302 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015303
15304 m_commandBuffer->BindPipeline(pipe);
15305 m_commandBuffer->BindDescriptorSet(descriptorSet);
15306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015307 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015308 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015309 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015310 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15311
15312 // error produced here.
15313 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15314
15315 m_errorMonitor->VerifyFound();
15316
Tony Barbour552f6c02016-12-21 14:34:07 -070015317 m_commandBuffer->EndRenderPass();
15318 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015319}
15320
Mark Youngc48c4c12016-04-11 14:26:49 -060015321TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015323
15324 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015325
15326 // Create an image
15327 VkImage image;
15328
Karl Schultz6addd812016-02-02 17:17:23 -070015329 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15330 const int32_t tex_width = 32;
15331 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015332
15333 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015334 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15335 image_create_info.pNext = NULL;
15336 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15337 image_create_info.format = tex_format;
15338 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015339 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015340 image_create_info.extent.depth = 1;
15341 image_create_info.mipLevels = 1;
15342 image_create_info.arrayLayers = 1;
15343 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15344 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15345 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15346 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015347
15348 // Introduce error by sending down a bogus width extent
15349 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015350 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015351
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015352 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015353}
15354
Mark Youngc48c4c12016-04-11 14:26:49 -060015355TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015357
15358 ASSERT_NO_FATAL_FAILURE(InitState());
15359
15360 // Create an image
15361 VkImage image;
15362
15363 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15364 const int32_t tex_width = 32;
15365 const int32_t tex_height = 32;
15366
15367 VkImageCreateInfo image_create_info = {};
15368 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15369 image_create_info.pNext = NULL;
15370 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15371 image_create_info.format = tex_format;
15372 image_create_info.extent.width = tex_width;
15373 image_create_info.extent.height = tex_height;
15374 image_create_info.extent.depth = 1;
15375 image_create_info.mipLevels = 1;
15376 image_create_info.arrayLayers = 1;
15377 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15378 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15379 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15380 image_create_info.flags = 0;
15381
15382 // Introduce error by sending down a bogus width extent
15383 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015384 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015385 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15386
15387 m_errorMonitor->VerifyFound();
15388}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015389
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015390TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015391 TEST_DESCRIPTION(
15392 "Create a render pass with an attachment description "
15393 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015394
15395 ASSERT_NO_FATAL_FAILURE(InitState());
15396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15397
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015399
15400 VkAttachmentReference color_attach = {};
15401 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15402 color_attach.attachment = 0;
15403 VkSubpassDescription subpass = {};
15404 subpass.colorAttachmentCount = 1;
15405 subpass.pColorAttachments = &color_attach;
15406
15407 VkRenderPassCreateInfo rpci = {};
15408 rpci.subpassCount = 1;
15409 rpci.pSubpasses = &subpass;
15410 rpci.attachmentCount = 1;
15411 VkAttachmentDescription attach_desc = {};
15412 attach_desc.format = VK_FORMAT_UNDEFINED;
15413 rpci.pAttachments = &attach_desc;
15414 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15415 VkRenderPass rp;
15416 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15417
15418 m_errorMonitor->VerifyFound();
15419
15420 if (result == VK_SUCCESS) {
15421 vkDestroyRenderPass(m_device->device(), rp, NULL);
15422 }
15423}
15424
Karl Schultz6addd812016-02-02 17:17:23 -070015425TEST_F(VkLayerTest, InvalidImageView) {
15426 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015427
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015429
Tobin Ehliscde08892015-09-22 10:11:37 -060015430 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015431
Mike Stroyana3082432015-09-25 13:39:21 -060015432 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015433 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015434
Karl Schultz6addd812016-02-02 17:17:23 -070015435 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15436 const int32_t tex_width = 32;
15437 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015438
15439 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015440 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15441 image_create_info.pNext = NULL;
15442 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15443 image_create_info.format = tex_format;
15444 image_create_info.extent.width = tex_width;
15445 image_create_info.extent.height = tex_height;
15446 image_create_info.extent.depth = 1;
15447 image_create_info.mipLevels = 1;
15448 image_create_info.arrayLayers = 1;
15449 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15450 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15451 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15452 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015453
Chia-I Wuf7458c52015-10-26 21:10:41 +080015454 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015455 ASSERT_VK_SUCCESS(err);
15456
15457 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015458 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015459 image_view_create_info.image = image;
15460 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15461 image_view_create_info.format = tex_format;
15462 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015463 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015464 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015465 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015466
15467 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015468 m_errorMonitor->SetUnexpectedError(
15469 "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 -060015470 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015471
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015472 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015473 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015474}
Mike Stroyana3082432015-09-25 13:39:21 -060015475
Mark Youngd339ba32016-05-30 13:28:35 -060015476TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15477 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015479 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015480
15481 ASSERT_NO_FATAL_FAILURE(InitState());
15482
15483 // Create an image and try to create a view with no memory backing the image
15484 VkImage image;
15485
15486 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15487 const int32_t tex_width = 32;
15488 const int32_t tex_height = 32;
15489
15490 VkImageCreateInfo image_create_info = {};
15491 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15492 image_create_info.pNext = NULL;
15493 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15494 image_create_info.format = tex_format;
15495 image_create_info.extent.width = tex_width;
15496 image_create_info.extent.height = tex_height;
15497 image_create_info.extent.depth = 1;
15498 image_create_info.mipLevels = 1;
15499 image_create_info.arrayLayers = 1;
15500 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15501 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15502 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15503 image_create_info.flags = 0;
15504
15505 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15506 ASSERT_VK_SUCCESS(err);
15507
15508 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015509 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015510 image_view_create_info.image = image;
15511 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15512 image_view_create_info.format = tex_format;
15513 image_view_create_info.subresourceRange.layerCount = 1;
15514 image_view_create_info.subresourceRange.baseMipLevel = 0;
15515 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015516 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015517
15518 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015519 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015520
15521 m_errorMonitor->VerifyFound();
15522 vkDestroyImage(m_device->device(), image, NULL);
15523 // If last error is success, it still created the view, so delete it.
15524 if (err == VK_SUCCESS) {
15525 vkDestroyImageView(m_device->device(), view, NULL);
15526 }
Mark Youngd339ba32016-05-30 13:28:35 -060015527}
15528
Karl Schultz6addd812016-02-02 17:17:23 -070015529TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015530 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015532
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015533 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015534
Karl Schultz6addd812016-02-02 17:17:23 -070015535 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015536 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015537 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015538 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015539
15540 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015541 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015542 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015543 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15544 image_view_create_info.format = tex_format;
15545 image_view_create_info.subresourceRange.baseMipLevel = 0;
15546 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015547 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015548 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015549 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015550
15551 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015552 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015553
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015554 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015555}
15556
Mike Weiblena1e13f42017-02-09 21:25:59 -070015557TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15558 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15559
15560 ASSERT_NO_FATAL_FAILURE(InitState());
15561 VkSubresourceLayout subres_layout = {};
15562
15563 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15564 {
15565 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15566 VkImageObj img(m_device);
15567 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15568 ASSERT_TRUE(img.initialized());
15569
15570 VkImageSubresource subres = {};
15571 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15572 subres.mipLevel = 0;
15573 subres.arrayLayer = 0;
15574
15575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15576 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15577 m_errorMonitor->VerifyFound();
15578 }
15579
15580 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15581 {
15582 VkImageObj img(m_device);
15583 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15584 ASSERT_TRUE(img.initialized());
15585
15586 VkImageSubresource subres = {};
15587 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15588 subres.mipLevel = 0;
15589 subres.arrayLayer = 0;
15590
15591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15593 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15594 m_errorMonitor->VerifyFound();
15595 }
15596
15597 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15598 {
15599 VkImageObj img(m_device);
15600 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15601 ASSERT_TRUE(img.initialized());
15602
15603 VkImageSubresource subres = {};
15604 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15605 subres.mipLevel = 1; // ERROR: triggers VU 00739
15606 subres.arrayLayer = 0;
15607
15608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15609 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15610 m_errorMonitor->VerifyFound();
15611 }
15612
15613 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15614 {
15615 VkImageObj img(m_device);
15616 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15617 ASSERT_TRUE(img.initialized());
15618
15619 VkImageSubresource subres = {};
15620 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15621 subres.mipLevel = 0;
15622 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15623
15624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15625 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15626 m_errorMonitor->VerifyFound();
15627 }
15628}
15629
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015630TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015631 VkResult err;
15632 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015633
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015635
Mike Stroyana3082432015-09-25 13:39:21 -060015636 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015637
15638 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015639 VkImage srcImage;
15640 VkImage dstImage;
15641 VkDeviceMemory srcMem;
15642 VkDeviceMemory destMem;
15643 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015644
15645 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015646 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15647 image_create_info.pNext = NULL;
15648 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15649 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15650 image_create_info.extent.width = 32;
15651 image_create_info.extent.height = 32;
15652 image_create_info.extent.depth = 1;
15653 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015654 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015655 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15656 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15657 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15658 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015660 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015661 ASSERT_VK_SUCCESS(err);
15662
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015663 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015664 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015665 ASSERT_VK_SUCCESS(err);
15666
15667 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015668 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015669 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15670 memAlloc.pNext = NULL;
15671 memAlloc.allocationSize = 0;
15672 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015673
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015674 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015675 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015676 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015677 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015678 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015679 ASSERT_VK_SUCCESS(err);
15680
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015681 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015682 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015683 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015684 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015685 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015686 ASSERT_VK_SUCCESS(err);
15687
15688 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15689 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015690 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015691 ASSERT_VK_SUCCESS(err);
15692
Tony Barbour552f6c02016-12-21 14:34:07 -070015693 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015694 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015695 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015696 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015697 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015698 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015699 copyRegion.srcOffset.x = 0;
15700 copyRegion.srcOffset.y = 0;
15701 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015702 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015703 copyRegion.dstSubresource.mipLevel = 0;
15704 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015705 // Introduce failure by forcing the dst layerCount to differ from src
15706 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015707 copyRegion.dstOffset.x = 0;
15708 copyRegion.dstOffset.y = 0;
15709 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015710 copyRegion.extent.width = 1;
15711 copyRegion.extent.height = 1;
15712 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015713 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015714 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015715
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015716 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015717
Chia-I Wuf7458c52015-10-26 21:10:41 +080015718 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015719 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015720 vkFreeMemory(m_device->device(), srcMem, NULL);
15721 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015722}
15723
Tony Barbourd6673642016-05-05 14:46:39 -060015724TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015725 TEST_DESCRIPTION("Creating images with unsuported formats ");
15726
15727 ASSERT_NO_FATAL_FAILURE(InitState());
15728 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15729 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015730 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 -060015731 VK_IMAGE_TILING_OPTIMAL, 0);
15732 ASSERT_TRUE(image.initialized());
15733
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015734 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015735 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015736 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15738 image_create_info.format = VK_FORMAT_UNDEFINED;
15739 image_create_info.extent.width = 32;
15740 image_create_info.extent.height = 32;
15741 image_create_info.extent.depth = 1;
15742 image_create_info.mipLevels = 1;
15743 image_create_info.arrayLayers = 1;
15744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15745 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15746 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15749 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015750
15751 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015752 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15753 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15754 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15755 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015756 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15757 m_errorMonitor->VerifyFound();
15758
Tony Barbourd6673642016-05-05 14:46:39 -060015759 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015760 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015761 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15762 VkFormat format = static_cast<VkFormat>(f);
15763 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015764 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015765 unsupported = format;
15766 break;
15767 }
15768 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015769
Tony Barbourd6673642016-05-05 14:46:39 -060015770 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015771 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015773
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015774 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15775 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15776 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15777 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15778 m_errorMonitor->SetUnexpectedError(
15779 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15780 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15781 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015782 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015783 m_errorMonitor->VerifyFound();
15784 }
15785}
15786
15787TEST_F(VkLayerTest, ImageLayerViewTests) {
15788 VkResult ret;
15789 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15790
15791 ASSERT_NO_FATAL_FAILURE(InitState());
15792
15793 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015794 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 -060015795 VK_IMAGE_TILING_OPTIMAL, 0);
15796 ASSERT_TRUE(image.initialized());
15797
15798 VkImageView imgView;
15799 VkImageViewCreateInfo imgViewInfo = {};
15800 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15801 imgViewInfo.image = image.handle();
15802 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15803 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15804 imgViewInfo.subresourceRange.layerCount = 1;
15805 imgViewInfo.subresourceRange.baseMipLevel = 0;
15806 imgViewInfo.subresourceRange.levelCount = 1;
15807 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15808
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015810 // View can't have baseMipLevel >= image's mipLevels - Expect
15811 // VIEW_CREATE_ERROR
15812 imgViewInfo.subresourceRange.baseMipLevel = 1;
15813 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15814 m_errorMonitor->VerifyFound();
15815 imgViewInfo.subresourceRange.baseMipLevel = 0;
15816
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015818 // View can't have baseArrayLayer >= image's arraySize - Expect
15819 // VIEW_CREATE_ERROR
15820 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15821 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15822 m_errorMonitor->VerifyFound();
15823 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15824
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015826 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15827 imgViewInfo.subresourceRange.levelCount = 0;
15828 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15829 m_errorMonitor->VerifyFound();
15830 imgViewInfo.subresourceRange.levelCount = 1;
15831
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015832 m_errorMonitor->SetDesiredFailureMsg(
15833 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15834 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015835 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15836 imgViewInfo.subresourceRange.layerCount = 0;
15837 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15838 m_errorMonitor->VerifyFound();
15839 imgViewInfo.subresourceRange.layerCount = 1;
15840
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15842 "Formats MUST be IDENTICAL unless "
15843 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15844 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015845 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15846 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15847 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15848 m_errorMonitor->VerifyFound();
15849 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15850
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015852 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15853 // VIEW_CREATE_ERROR
15854 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15855 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15856 m_errorMonitor->VerifyFound();
15857 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15858
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015860 // TODO: Update framework to easily passing mutable flag into ImageObj init
15861 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015862 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15863 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15864 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015865 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15866 // VIEW_CREATE_ERROR
15867 VkImageCreateInfo mutImgInfo = image.create_info();
15868 VkImage mutImage;
15869 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015870 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015871 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15872 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15873 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15874 ASSERT_VK_SUCCESS(ret);
15875 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015876 m_errorMonitor->SetUnexpectedError(
15877 "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 -060015878 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15879 m_errorMonitor->VerifyFound();
15880 imgViewInfo.image = image.handle();
15881 vkDestroyImage(m_device->handle(), mutImage, NULL);
15882}
15883
Dave Houlton59a20702017-02-02 17:26:23 -070015884TEST_F(VkLayerTest, ImageBufferCopyTests) {
15885 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
15886
15887 ASSERT_NO_FATAL_FAILURE(InitState());
Dave Houlton584d51e2017-02-16 12:52:54 -070015888
15889 // Bail if any dimension of transfer granularity is 0.
15890 auto index = m_device->graphics_queue_node_index_;
15891 auto queue_family_properties = m_device->phy().queue_properties();
15892 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
15893 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
15894 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
15895 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
15896 return;
15897 }
15898
Dave Houlton59a20702017-02-02 17:26:23 -070015899 VkImageObj image_64k(m_device); // 128^2 texels, 64k
15900 VkImageObj image_16k(m_device); // 64^2 texels, 16k
15901 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070015902 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
15903 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
15904 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
15905 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
15906
Dave Houlton59a20702017-02-02 17:26:23 -070015907 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
15908 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15909 VK_IMAGE_TILING_OPTIMAL, 0);
15910 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
15911 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15912 VK_IMAGE_TILING_OPTIMAL, 0);
15913 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15914 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070015915 ASSERT_TRUE(image_64k.initialized());
15916 ASSERT_TRUE(image_16k.initialized());
15917 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070015918
Dave Houltonf3229d52017-02-21 15:59:08 -070015919 // Verify all needed Depth/Stencil formats are supported
15920 bool missing_ds_support = false;
15921 VkFormatProperties props = {0, 0, 0};
15922 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
15923 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15924 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
15925 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15926 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
15927 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15928 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
15929 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15930
15931 if (!missing_ds_support) {
15932 ds_image_4D_1S.init(
15933 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
15934 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15935 VK_IMAGE_TILING_OPTIMAL, 0);
15936 ASSERT_TRUE(ds_image_4D_1S.initialized());
15937
15938 ds_image_3D_1S.init(
15939 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
15940 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15941 VK_IMAGE_TILING_OPTIMAL, 0);
15942 ASSERT_TRUE(ds_image_3D_1S.initialized());
15943
15944 ds_image_2D.init(
15945 256, 256, VK_FORMAT_D16_UNORM,
15946 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15947 VK_IMAGE_TILING_OPTIMAL, 0);
15948 ASSERT_TRUE(ds_image_2D.initialized());
15949
15950 ds_image_1S.init(
15951 256, 256, VK_FORMAT_S8_UINT,
15952 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15953 VK_IMAGE_TILING_OPTIMAL, 0);
15954 ASSERT_TRUE(ds_image_1S.initialized());
15955 }
15956
15957 // Allocate buffers
15958 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070015959 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070015960 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
15961 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
15962 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
15963 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070015964
15965 VkBufferImageCopy region = {};
15966 region.bufferRowLength = 0;
15967 region.bufferImageHeight = 0;
15968 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15969 region.imageSubresource.layerCount = 1;
15970 region.imageOffset = {0, 0, 0};
15971 region.imageExtent = {64, 64, 1};
15972 region.bufferOffset = 0;
15973
15974 // attempt copies before putting command buffer in recording state
15975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
15976 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15977 &region);
15978 m_errorMonitor->VerifyFound();
15979
15980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
15981 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
15982 &region);
15983 m_errorMonitor->VerifyFound();
15984
15985 // start recording
15986 m_commandBuffer->BeginCommandBuffer();
15987
15988 // successful copies
15989 m_errorMonitor->ExpectSuccess();
15990 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15991 &region);
15992 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15993 &region);
15994 region.imageOffset.x = 16; // 16k copy, offset requires larger image
15995 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
15996 &region);
15997 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
15998 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15999 &region);
16000 region.imageOffset.x = 0;
16001 region.imageExtent.height = 64;
16002 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16003 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16004 &region);
16005 m_errorMonitor->VerifyNotFound();
16006
16007 // image/buffer too small (extent) on copy to image
16008 region.imageExtent = {65, 64, 1};
16009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16010 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16011 &region);
16012 m_errorMonitor->VerifyFound();
16013
16014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16015 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16016 &region);
16017 m_errorMonitor->VerifyFound();
16018
16019 // image/buffer too small (offset) on copy to image
16020 region.imageExtent = {64, 64, 1};
16021 region.imageOffset = {0, 4, 0};
16022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16023 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16024 &region);
16025 m_errorMonitor->VerifyFound();
16026
16027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16028 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16029 &region);
16030 m_errorMonitor->VerifyFound();
16031
16032 // image/buffer too small on copy to buffer
16033 region.imageExtent = {64, 64, 1};
16034 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016035 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16037 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16038 &region);
16039 m_errorMonitor->VerifyFound();
16040
16041 region.imageExtent = {64, 65, 1};
16042 region.bufferOffset = 0;
16043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16044 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16045 &region);
16046 m_errorMonitor->VerifyFound();
16047
16048 // buffer size ok but rowlength causes loose packing
16049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16050 region.imageExtent = {64, 64, 1};
16051 region.bufferRowLength = 68;
16052 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16053 &region);
16054 m_errorMonitor->VerifyFound();
16055
Dave Houlton59a20702017-02-02 17:26:23 -070016056 // aspect bits
16057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16058 region.imageExtent = {64, 64, 1};
16059 region.bufferRowLength = 0;
16060 region.bufferImageHeight = 0;
16061 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16062 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16063 buffer_16k.handle(), 1, &region);
16064 m_errorMonitor->VerifyFound();
16065
16066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16067 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16068 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16069 &region);
16070 m_errorMonitor->VerifyFound();
16071
16072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16073 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16074 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16075 buffer_16k.handle(), 1, &region);
16076 m_errorMonitor->VerifyFound();
16077
Dave Houltonf3229d52017-02-21 15:59:08 -070016078 // Test Depth/Stencil copies
16079 if (missing_ds_support) {
16080 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16081 } else {
16082 VkBufferImageCopy ds_region = {};
16083 ds_region.bufferOffset = 0;
16084 ds_region.bufferRowLength = 0;
16085 ds_region.bufferImageHeight = 0;
16086 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16087 ds_region.imageSubresource.mipLevel = 0;
16088 ds_region.imageSubresource.baseArrayLayer = 0;
16089 ds_region.imageSubresource.layerCount = 1;
16090 ds_region.imageOffset = {0, 0, 0};
16091 ds_region.imageExtent = {256, 256, 1};
16092
16093 // Depth copies that should succeed
16094 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16095 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16096 buffer_256k.handle(), 1, &ds_region);
16097 m_errorMonitor->VerifyNotFound();
16098
16099 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16100 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16101 buffer_256k.handle(), 1, &ds_region);
16102 m_errorMonitor->VerifyNotFound();
16103
16104 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16105 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16106 buffer_128k.handle(), 1, &ds_region);
16107 m_errorMonitor->VerifyNotFound();
16108
16109 // Depth copies that should fail
16110 ds_region.bufferOffset = 4;
16111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16112 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16113 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16114 buffer_256k.handle(), 1, &ds_region);
16115 m_errorMonitor->VerifyFound();
16116
16117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16118 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16119 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16120 buffer_256k.handle(), 1, &ds_region);
16121 m_errorMonitor->VerifyFound();
16122
16123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16124 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16125 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16126 buffer_128k.handle(), 1, &ds_region);
16127 m_errorMonitor->VerifyFound();
16128
16129 // Stencil copies that should succeed
16130 ds_region.bufferOffset = 0;
16131 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16132 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16133 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16134 buffer_64k.handle(), 1, &ds_region);
16135 m_errorMonitor->VerifyNotFound();
16136
16137 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16138 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16139 buffer_64k.handle(), 1, &ds_region);
16140 m_errorMonitor->VerifyNotFound();
16141
16142 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16143 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16144 buffer_64k.handle(), 1, &ds_region);
16145 m_errorMonitor->VerifyNotFound();
16146
16147 // Stencil copies that should fail
16148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16149 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16150 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16151 buffer_16k.handle(), 1, &ds_region);
16152 m_errorMonitor->VerifyFound();
16153
16154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16155 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16156 ds_region.bufferRowLength = 260;
16157 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16158 buffer_64k.handle(), 1, &ds_region);
16159 m_errorMonitor->VerifyFound();
16160
16161 ds_region.bufferRowLength = 0;
16162 ds_region.bufferOffset = 4;
16163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16164 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16165 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16166 buffer_64k.handle(), 1, &ds_region);
16167 m_errorMonitor->VerifyFound();
16168 }
16169
Dave Houlton584d51e2017-02-16 12:52:54 -070016170 // Test compressed formats, if supported
16171 VkPhysicalDeviceFeatures device_features;
16172 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016173 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16174 device_features.textureCompressionASTC_LDR)) {
16175 printf(" No compressed formats supported - block compression tests skipped.\n");
16176 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070016177 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16178 if (device_features.textureCompressionBC) {
16179 image_16k_4x4comp.init(32, 32, VK_FORMAT_BC5_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16180 } else if (device_features.textureCompressionETC2) {
16181 image_16k_4x4comp.init(32, 32, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16182 VK_IMAGE_TILING_OPTIMAL, 0);
16183 } else {
16184 image_16k_4x4comp.init(32, 32, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16185 0);
16186 }
16187 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016188
Dave Houlton584d51e2017-02-16 12:52:54 -070016189 // Just fits
16190 m_errorMonitor->ExpectSuccess();
16191 region.imageExtent = {128, 128, 1};
16192 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16193 buffer_16k.handle(), 1, &region);
16194 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016195
Dave Houlton584d51e2017-02-16 12:52:54 -070016196 // with offset, too big for buffer
16197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16198 region.bufferOffset = 16;
16199 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16200 buffer_16k.handle(), 1, &region);
16201 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016202
Dave Houlton584d51e2017-02-16 12:52:54 -070016203 // buffer offset must be a multiple of texel block size (16)
16204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16206 region.imageExtent = {64, 64, 1};
16207 region.bufferOffset = 24;
16208 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16209 buffer_16k.handle(), 1, &region);
16210 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016211
Dave Houlton584d51e2017-02-16 12:52:54 -070016212 // rowlength not a multiple of block width (4)
16213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16214 region.bufferOffset = 0;
16215 region.bufferRowLength = 130;
16216 region.bufferImageHeight = 0;
16217 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16218 buffer_64k.handle(), 1, &region);
16219 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016220
Dave Houlton584d51e2017-02-16 12:52:54 -070016221 // imageheight not a multiple of block height (4)
16222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16223 region.bufferRowLength = 0;
16224 region.bufferImageHeight = 130;
16225 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16226 buffer_64k.handle(), 1, &region);
16227 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016228
Dave Houlton584d51e2017-02-16 12:52:54 -070016229 // image extents must be multiple of block dimensions (4x4)
16230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16231 region.bufferImageHeight = 0;
16232 region.imageOffset = {4, 6, 0};
16233 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16234 buffer_64k.handle(), 1, &region);
16235 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016236
Dave Houlton584d51e2017-02-16 12:52:54 -070016237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16238 region.imageOffset = {22, 0, 0};
16239 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16240 buffer_64k.handle(), 1, &region);
16241 m_errorMonitor->VerifyFound();
16242 }
Dave Houlton59a20702017-02-02 17:26:23 -070016243}
16244
Tony Barbourd6673642016-05-05 14:46:39 -060016245TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016246 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016247
16248 ASSERT_NO_FATAL_FAILURE(InitState());
16249
Rene Lindsay135204f2016-12-22 17:11:09 -070016250 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016251 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016252 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 -070016253 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016254 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016255 vk_testing::Buffer buffer;
16256 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016257 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016258 VkBufferImageCopy region = {};
16259 region.bufferRowLength = 128;
16260 region.bufferImageHeight = 128;
16261 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16262 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016263 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016264 region.imageExtent.height = 4;
16265 region.imageExtent.width = 4;
16266 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016267
16268 VkImageObj image2(m_device);
16269 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 -070016270 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016271 ASSERT_TRUE(image2.initialized());
16272 vk_testing::Buffer buffer2;
16273 VkMemoryPropertyFlags reqs2 = 0;
16274 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16275 VkBufferImageCopy region2 = {};
16276 region2.bufferRowLength = 128;
16277 region2.bufferImageHeight = 128;
16278 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16279 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16280 region2.imageSubresource.layerCount = 1;
16281 region2.imageExtent.height = 4;
16282 region2.imageExtent.width = 4;
16283 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016284 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016285
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016286 // Image must have offset.z of 0 and extent.depth of 1
16287 // Introduce failure by setting imageExtent.depth to 0
16288 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016290 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016291 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016292 m_errorMonitor->VerifyFound();
16293
16294 region.imageExtent.depth = 1;
16295
16296 // Image must have offset.z of 0 and extent.depth of 1
16297 // Introduce failure by setting imageOffset.z to 4
16298 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016300 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016301 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016302 m_errorMonitor->VerifyFound();
16303
16304 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016305 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16306 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016307 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016309 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16310 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016311 m_errorMonitor->VerifyFound();
16312
16313 // BufferOffset must be a multiple of 4
16314 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016315 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016317 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16318 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016319 m_errorMonitor->VerifyFound();
16320
16321 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16322 region.bufferOffset = 0;
16323 region.imageExtent.height = 128;
16324 region.imageExtent.width = 128;
16325 // Introduce failure by setting bufferRowLength > 0 but less than width
16326 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016328 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16329 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016330 m_errorMonitor->VerifyFound();
16331
16332 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16333 region.bufferRowLength = 128;
16334 // Introduce failure by setting bufferRowHeight > 0 but less than height
16335 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016337 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16338 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016339 m_errorMonitor->VerifyFound();
16340
16341 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016342 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016343 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16344 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016345 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016346 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16347 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016348 VkImageBlit blitRegion = {};
16349 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16350 blitRegion.srcSubresource.baseArrayLayer = 0;
16351 blitRegion.srcSubresource.layerCount = 1;
16352 blitRegion.srcSubresource.mipLevel = 0;
16353 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16354 blitRegion.dstSubresource.baseArrayLayer = 0;
16355 blitRegion.dstSubresource.layerCount = 1;
16356 blitRegion.dstSubresource.mipLevel = 0;
16357
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016358 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016360 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016361 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16362 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016363 m_errorMonitor->VerifyFound();
16364
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016366 VkImageMemoryBarrier img_barrier;
16367 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16368 img_barrier.pNext = NULL;
16369 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16370 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16371 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16372 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16373 img_barrier.image = image.handle();
16374 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16375 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16376 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16377 img_barrier.subresourceRange.baseArrayLayer = 0;
16378 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016379 img_barrier.subresourceRange.layerCount = 0;
16380 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016381 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16382 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016383 m_errorMonitor->VerifyFound();
16384 img_barrier.subresourceRange.layerCount = 1;
16385}
16386
16387TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016388 TEST_DESCRIPTION("Exceed the limits of image format ");
16389
Cody Northropc31a84f2016-08-22 10:41:47 -060016390 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016392 VkImageCreateInfo image_create_info = {};
16393 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16394 image_create_info.pNext = NULL;
16395 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16396 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16397 image_create_info.extent.width = 32;
16398 image_create_info.extent.height = 32;
16399 image_create_info.extent.depth = 1;
16400 image_create_info.mipLevels = 1;
16401 image_create_info.arrayLayers = 1;
16402 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16403 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16404 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16405 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16406 image_create_info.flags = 0;
16407
16408 VkImage nullImg;
16409 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016410 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16411 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016412 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016413 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16414 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16415 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016416 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016419 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16420 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16421 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16422 m_errorMonitor->VerifyFound();
16423 image_create_info.mipLevels = 1;
16424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016426 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16427 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16428 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16429 m_errorMonitor->VerifyFound();
16430 image_create_info.arrayLayers = 1;
16431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016433 int samples = imgFmtProps.sampleCounts >> 1;
16434 image_create_info.samples = (VkSampleCountFlagBits)samples;
16435 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16436 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16437 m_errorMonitor->VerifyFound();
16438 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16439
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16441 "pCreateInfo->initialLayout, must be "
16442 "VK_IMAGE_LAYOUT_UNDEFINED or "
16443 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16445 // Expect INVALID_LAYOUT
16446 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16447 m_errorMonitor->VerifyFound();
16448 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16449}
16450
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016451TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016452 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016454
16455 ASSERT_NO_FATAL_FAILURE(InitState());
16456
16457 VkImageObj src_image(m_device);
16458 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16459 VkImageObj dst_image(m_device);
16460 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16461
Tony Barbour552f6c02016-12-21 14:34:07 -070016462 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016463 VkImageCopy copy_region;
16464 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16465 copy_region.srcSubresource.mipLevel = 0;
16466 copy_region.srcSubresource.baseArrayLayer = 0;
16467 copy_region.srcSubresource.layerCount = 0;
16468 copy_region.srcOffset.x = 0;
16469 copy_region.srcOffset.y = 0;
16470 copy_region.srcOffset.z = 0;
16471 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16472 copy_region.dstSubresource.mipLevel = 0;
16473 copy_region.dstSubresource.baseArrayLayer = 0;
16474 copy_region.dstSubresource.layerCount = 0;
16475 copy_region.dstOffset.x = 0;
16476 copy_region.dstOffset.y = 0;
16477 copy_region.dstOffset.z = 0;
16478 copy_region.extent.width = 64;
16479 copy_region.extent.height = 64;
16480 copy_region.extent.depth = 1;
16481 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16482 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016483 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016484
16485 m_errorMonitor->VerifyFound();
16486}
16487
16488TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016489 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016491
16492 ASSERT_NO_FATAL_FAILURE(InitState());
16493
16494 VkImageObj src_image(m_device);
16495 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16496 VkImageObj dst_image(m_device);
16497 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16498
Tony Barbour552f6c02016-12-21 14:34:07 -070016499 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016500 VkImageCopy copy_region;
16501 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16502 copy_region.srcSubresource.mipLevel = 0;
16503 copy_region.srcSubresource.baseArrayLayer = 0;
16504 copy_region.srcSubresource.layerCount = 0;
16505 copy_region.srcOffset.x = 0;
16506 copy_region.srcOffset.y = 0;
16507 copy_region.srcOffset.z = 0;
16508 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16509 copy_region.dstSubresource.mipLevel = 0;
16510 copy_region.dstSubresource.baseArrayLayer = 0;
16511 copy_region.dstSubresource.layerCount = 0;
16512 copy_region.dstOffset.x = 0;
16513 copy_region.dstOffset.y = 0;
16514 copy_region.dstOffset.z = 0;
16515 copy_region.extent.width = 64;
16516 copy_region.extent.height = 64;
16517 copy_region.extent.depth = 1;
16518 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16519 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016520 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016521
16522 m_errorMonitor->VerifyFound();
16523}
16524
Karl Schultz6addd812016-02-02 17:17:23 -070016525TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016526 VkResult err;
16527 bool pass;
16528
16529 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016531
16532 ASSERT_NO_FATAL_FAILURE(InitState());
16533
16534 // Create two images of different types and try to copy between them
16535 VkImage srcImage;
16536 VkImage dstImage;
16537 VkDeviceMemory srcMem;
16538 VkDeviceMemory destMem;
16539 VkMemoryRequirements memReqs;
16540
16541 VkImageCreateInfo image_create_info = {};
16542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16543 image_create_info.pNext = NULL;
16544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16545 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16546 image_create_info.extent.width = 32;
16547 image_create_info.extent.height = 32;
16548 image_create_info.extent.depth = 1;
16549 image_create_info.mipLevels = 1;
16550 image_create_info.arrayLayers = 1;
16551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16552 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16553 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16554 image_create_info.flags = 0;
16555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016556 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016557 ASSERT_VK_SUCCESS(err);
16558
16559 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16560 // Introduce failure by creating second image with a different-sized format.
16561 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016563 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016564 ASSERT_VK_SUCCESS(err);
16565
16566 // Allocate memory
16567 VkMemoryAllocateInfo memAlloc = {};
16568 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16569 memAlloc.pNext = NULL;
16570 memAlloc.allocationSize = 0;
16571 memAlloc.memoryTypeIndex = 0;
16572
16573 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16574 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016575 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016576 ASSERT_TRUE(pass);
16577 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16578 ASSERT_VK_SUCCESS(err);
16579
16580 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16581 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016582 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016583 ASSERT_TRUE(pass);
16584 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16585 ASSERT_VK_SUCCESS(err);
16586
16587 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16588 ASSERT_VK_SUCCESS(err);
16589 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16590 ASSERT_VK_SUCCESS(err);
16591
Tony Barbour552f6c02016-12-21 14:34:07 -070016592 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016593 VkImageCopy copyRegion;
16594 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16595 copyRegion.srcSubresource.mipLevel = 0;
16596 copyRegion.srcSubresource.baseArrayLayer = 0;
16597 copyRegion.srcSubresource.layerCount = 0;
16598 copyRegion.srcOffset.x = 0;
16599 copyRegion.srcOffset.y = 0;
16600 copyRegion.srcOffset.z = 0;
16601 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16602 copyRegion.dstSubresource.mipLevel = 0;
16603 copyRegion.dstSubresource.baseArrayLayer = 0;
16604 copyRegion.dstSubresource.layerCount = 0;
16605 copyRegion.dstOffset.x = 0;
16606 copyRegion.dstOffset.y = 0;
16607 copyRegion.dstOffset.z = 0;
16608 copyRegion.extent.width = 1;
16609 copyRegion.extent.height = 1;
16610 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016611 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016612 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016613
16614 m_errorMonitor->VerifyFound();
16615
16616 vkDestroyImage(m_device->device(), srcImage, NULL);
16617 vkDestroyImage(m_device->device(), dstImage, NULL);
16618 vkFreeMemory(m_device->device(), srcMem, NULL);
16619 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016620}
16621
Karl Schultz6addd812016-02-02 17:17:23 -070016622TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16623 VkResult err;
16624 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016625
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016626 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16628 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016629
Mike Stroyana3082432015-09-25 13:39:21 -060016630 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016631
16632 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016633 VkImage srcImage;
16634 VkImage dstImage;
16635 VkDeviceMemory srcMem;
16636 VkDeviceMemory destMem;
16637 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016638
16639 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016640 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16641 image_create_info.pNext = NULL;
16642 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16643 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16644 image_create_info.extent.width = 32;
16645 image_create_info.extent.height = 32;
16646 image_create_info.extent.depth = 1;
16647 image_create_info.mipLevels = 1;
16648 image_create_info.arrayLayers = 1;
16649 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16650 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16651 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16652 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016654 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016655 ASSERT_VK_SUCCESS(err);
16656
Karl Schultzbdb75952016-04-19 11:36:49 -060016657 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16658
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016659 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016660 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016661 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016662 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016664 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016665 ASSERT_VK_SUCCESS(err);
16666
16667 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016668 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016669 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16670 memAlloc.pNext = NULL;
16671 memAlloc.allocationSize = 0;
16672 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016673
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016674 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016675 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016676 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016677 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016678 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016679 ASSERT_VK_SUCCESS(err);
16680
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016681 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016682 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016683 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016684 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016685 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016686 ASSERT_VK_SUCCESS(err);
16687
16688 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16689 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016690 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016691 ASSERT_VK_SUCCESS(err);
16692
Tony Barbour552f6c02016-12-21 14:34:07 -070016693 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016694 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016695 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016696 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016697 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016698 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016699 copyRegion.srcOffset.x = 0;
16700 copyRegion.srcOffset.y = 0;
16701 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016702 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016703 copyRegion.dstSubresource.mipLevel = 0;
16704 copyRegion.dstSubresource.baseArrayLayer = 0;
16705 copyRegion.dstSubresource.layerCount = 0;
16706 copyRegion.dstOffset.x = 0;
16707 copyRegion.dstOffset.y = 0;
16708 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016709 copyRegion.extent.width = 1;
16710 copyRegion.extent.height = 1;
16711 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016712 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016713 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016714
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016715 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016716
Chia-I Wuf7458c52015-10-26 21:10:41 +080016717 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016718 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016719 vkFreeMemory(m_device->device(), srcMem, NULL);
16720 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016721}
16722
Karl Schultz6addd812016-02-02 17:17:23 -070016723TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16724 VkResult err;
16725 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016726
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16728 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016729
Mike Stroyana3082432015-09-25 13:39:21 -060016730 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016731
16732 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016733 VkImage srcImage;
16734 VkImage dstImage;
16735 VkDeviceMemory srcMem;
16736 VkDeviceMemory destMem;
16737 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016738
16739 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016740 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16741 image_create_info.pNext = NULL;
16742 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16743 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16744 image_create_info.extent.width = 32;
16745 image_create_info.extent.height = 1;
16746 image_create_info.extent.depth = 1;
16747 image_create_info.mipLevels = 1;
16748 image_create_info.arrayLayers = 1;
16749 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16750 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16751 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16752 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016753
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016754 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016755 ASSERT_VK_SUCCESS(err);
16756
Karl Schultz6addd812016-02-02 17:17:23 -070016757 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016759 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016760 ASSERT_VK_SUCCESS(err);
16761
16762 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016763 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016764 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16765 memAlloc.pNext = NULL;
16766 memAlloc.allocationSize = 0;
16767 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016768
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016769 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016770 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016771 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016772 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016773 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016774 ASSERT_VK_SUCCESS(err);
16775
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016776 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016777 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016778 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016779 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016780 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016781 ASSERT_VK_SUCCESS(err);
16782
16783 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16784 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016785 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016786 ASSERT_VK_SUCCESS(err);
16787
Tony Barbour552f6c02016-12-21 14:34:07 -070016788 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016789 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016790 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16791 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016792 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016793 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016794 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016795 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016796 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016797 resolveRegion.srcOffset.x = 0;
16798 resolveRegion.srcOffset.y = 0;
16799 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016800 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016801 resolveRegion.dstSubresource.mipLevel = 0;
16802 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016803 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016804 resolveRegion.dstOffset.x = 0;
16805 resolveRegion.dstOffset.y = 0;
16806 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016807 resolveRegion.extent.width = 1;
16808 resolveRegion.extent.height = 1;
16809 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016810 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016811 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016812
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016813 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016814
Chia-I Wuf7458c52015-10-26 21:10:41 +080016815 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016816 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016817 vkFreeMemory(m_device->device(), srcMem, NULL);
16818 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016819}
16820
Karl Schultz6addd812016-02-02 17:17:23 -070016821TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16822 VkResult err;
16823 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16826 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016827
Mike Stroyana3082432015-09-25 13:39:21 -060016828 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016829
Chris Forbesa7530692016-05-08 12:35:39 +120016830 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016831 VkImage srcImage;
16832 VkImage dstImage;
16833 VkDeviceMemory srcMem;
16834 VkDeviceMemory destMem;
16835 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016836
16837 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016838 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16839 image_create_info.pNext = NULL;
16840 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16841 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16842 image_create_info.extent.width = 32;
16843 image_create_info.extent.height = 1;
16844 image_create_info.extent.depth = 1;
16845 image_create_info.mipLevels = 1;
16846 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016847 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016848 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16849 // Note: Some implementations expect color attachment usage for any
16850 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016851 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016852 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016854 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016855 ASSERT_VK_SUCCESS(err);
16856
Karl Schultz6addd812016-02-02 17:17:23 -070016857 // Note: Some implementations expect color attachment usage for any
16858 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016859 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016861 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016862 ASSERT_VK_SUCCESS(err);
16863
16864 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016865 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016866 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16867 memAlloc.pNext = NULL;
16868 memAlloc.allocationSize = 0;
16869 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016870
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016871 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016872 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016873 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016874 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016875 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016876 ASSERT_VK_SUCCESS(err);
16877
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016878 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016879 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016880 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016881 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016882 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016883 ASSERT_VK_SUCCESS(err);
16884
16885 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16886 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016887 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016888 ASSERT_VK_SUCCESS(err);
16889
Tony Barbour552f6c02016-12-21 14:34:07 -070016890 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016891 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016892 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16893 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016894 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016895 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016896 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016897 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016898 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016899 resolveRegion.srcOffset.x = 0;
16900 resolveRegion.srcOffset.y = 0;
16901 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016902 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016903 resolveRegion.dstSubresource.mipLevel = 0;
16904 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016905 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016906 resolveRegion.dstOffset.x = 0;
16907 resolveRegion.dstOffset.y = 0;
16908 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016909 resolveRegion.extent.width = 1;
16910 resolveRegion.extent.height = 1;
16911 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016912 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016913 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016914
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016915 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016916
Chia-I Wuf7458c52015-10-26 21:10:41 +080016917 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016918 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016919 vkFreeMemory(m_device->device(), srcMem, NULL);
16920 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016921}
16922
Karl Schultz6addd812016-02-02 17:17:23 -070016923TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16924 VkResult err;
16925 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016926
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016928 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016929
Mike Stroyana3082432015-09-25 13:39:21 -060016930 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016931
16932 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016933 VkImage srcImage;
16934 VkImage dstImage;
16935 VkDeviceMemory srcMem;
16936 VkDeviceMemory destMem;
16937 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016938
16939 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016940 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16941 image_create_info.pNext = NULL;
16942 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16943 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16944 image_create_info.extent.width = 32;
16945 image_create_info.extent.height = 1;
16946 image_create_info.extent.depth = 1;
16947 image_create_info.mipLevels = 1;
16948 image_create_info.arrayLayers = 1;
16949 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16950 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16951 // Note: Some implementations expect color attachment usage for any
16952 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016953 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016954 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016955
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016956 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016957 ASSERT_VK_SUCCESS(err);
16958
Karl Schultz6addd812016-02-02 17:17:23 -070016959 // Set format to something other than source image
16960 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16961 // Note: Some implementations expect color attachment usage for any
16962 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016963 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016964 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016966 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016967 ASSERT_VK_SUCCESS(err);
16968
16969 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016970 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016971 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16972 memAlloc.pNext = NULL;
16973 memAlloc.allocationSize = 0;
16974 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016975
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016976 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016977 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016978 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016979 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016980 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016981 ASSERT_VK_SUCCESS(err);
16982
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016983 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016984 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016985 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016986 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016987 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016988 ASSERT_VK_SUCCESS(err);
16989
16990 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16991 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016992 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016993 ASSERT_VK_SUCCESS(err);
16994
Tony Barbour552f6c02016-12-21 14:34:07 -070016995 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016996 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016997 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16998 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016999 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017000 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017001 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017002 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017003 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017004 resolveRegion.srcOffset.x = 0;
17005 resolveRegion.srcOffset.y = 0;
17006 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017007 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017008 resolveRegion.dstSubresource.mipLevel = 0;
17009 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017010 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017011 resolveRegion.dstOffset.x = 0;
17012 resolveRegion.dstOffset.y = 0;
17013 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017014 resolveRegion.extent.width = 1;
17015 resolveRegion.extent.height = 1;
17016 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017017 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017018 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017019
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017020 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017021
Chia-I Wuf7458c52015-10-26 21:10:41 +080017022 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017023 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017024 vkFreeMemory(m_device->device(), srcMem, NULL);
17025 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017026}
17027
Karl Schultz6addd812016-02-02 17:17:23 -070017028TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17029 VkResult err;
17030 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017031
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017033 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017034
Mike Stroyana3082432015-09-25 13:39:21 -060017035 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017036
17037 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017038 VkImage srcImage;
17039 VkImage dstImage;
17040 VkDeviceMemory srcMem;
17041 VkDeviceMemory destMem;
17042 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017043
17044 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017045 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17046 image_create_info.pNext = NULL;
17047 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17048 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17049 image_create_info.extent.width = 32;
17050 image_create_info.extent.height = 1;
17051 image_create_info.extent.depth = 1;
17052 image_create_info.mipLevels = 1;
17053 image_create_info.arrayLayers = 1;
17054 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17055 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17056 // Note: Some implementations expect color attachment usage for any
17057 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017058 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017059 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017061 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017062 ASSERT_VK_SUCCESS(err);
17063
Karl Schultz6addd812016-02-02 17:17:23 -070017064 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17065 // Note: Some implementations expect color attachment usage for any
17066 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017067 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017068 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017070 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017071 ASSERT_VK_SUCCESS(err);
17072
17073 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017074 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017075 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17076 memAlloc.pNext = NULL;
17077 memAlloc.allocationSize = 0;
17078 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017079
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017080 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017081 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017082 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017083 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017084 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017085 ASSERT_VK_SUCCESS(err);
17086
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017087 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017088 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017089 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017090 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017091 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017092 ASSERT_VK_SUCCESS(err);
17093
17094 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17095 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017096 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017097 ASSERT_VK_SUCCESS(err);
17098
Tony Barbour552f6c02016-12-21 14:34:07 -070017099 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017100 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017101 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17102 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017103 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017104 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017105 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017106 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017107 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017108 resolveRegion.srcOffset.x = 0;
17109 resolveRegion.srcOffset.y = 0;
17110 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017111 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017112 resolveRegion.dstSubresource.mipLevel = 0;
17113 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017114 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017115 resolveRegion.dstOffset.x = 0;
17116 resolveRegion.dstOffset.y = 0;
17117 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017118 resolveRegion.extent.width = 1;
17119 resolveRegion.extent.height = 1;
17120 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017121 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017122 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017123
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017124 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017125
Chia-I Wuf7458c52015-10-26 21:10:41 +080017126 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017127 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017128 vkFreeMemory(m_device->device(), srcMem, NULL);
17129 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017130}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017131
Karl Schultz6addd812016-02-02 17:17:23 -070017132TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017133 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017134 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17135 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017136 // The image format check comes 2nd in validation so we trigger it first,
17137 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017138 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17141 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017142
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017143 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017144
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017145 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017146 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17147 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017148
17149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17151 ds_pool_ci.pNext = NULL;
17152 ds_pool_ci.maxSets = 1;
17153 ds_pool_ci.poolSizeCount = 1;
17154 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017155
17156 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017157 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017158 ASSERT_VK_SUCCESS(err);
17159
17160 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017161 dsl_binding.binding = 0;
17162 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17163 dsl_binding.descriptorCount = 1;
17164 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17165 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017166
17167 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017168 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17169 ds_layout_ci.pNext = NULL;
17170 ds_layout_ci.bindingCount = 1;
17171 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017172 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017173 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017174 ASSERT_VK_SUCCESS(err);
17175
17176 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017177 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017178 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017179 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017180 alloc_info.descriptorPool = ds_pool;
17181 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017182 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017183 ASSERT_VK_SUCCESS(err);
17184
Karl Schultz6addd812016-02-02 17:17:23 -070017185 VkImage image_bad;
17186 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017187 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017188 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017189 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017190 const int32_t tex_width = 32;
17191 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017192
17193 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017194 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17195 image_create_info.pNext = NULL;
17196 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17197 image_create_info.format = tex_format_bad;
17198 image_create_info.extent.width = tex_width;
17199 image_create_info.extent.height = tex_height;
17200 image_create_info.extent.depth = 1;
17201 image_create_info.mipLevels = 1;
17202 image_create_info.arrayLayers = 1;
17203 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17204 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017205 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017206 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017208 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017209 ASSERT_VK_SUCCESS(err);
17210 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017211 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17212 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017213 ASSERT_VK_SUCCESS(err);
17214
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017215 // ---Bind image memory---
17216 VkMemoryRequirements img_mem_reqs;
17217 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17218 VkMemoryAllocateInfo image_alloc_info = {};
17219 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17220 image_alloc_info.pNext = NULL;
17221 image_alloc_info.memoryTypeIndex = 0;
17222 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017223 bool pass =
17224 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 -070017225 ASSERT_TRUE(pass);
17226 VkDeviceMemory mem;
17227 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17228 ASSERT_VK_SUCCESS(err);
17229 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17230 ASSERT_VK_SUCCESS(err);
17231 // -----------------------
17232
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017233 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017234 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017235 image_view_create_info.image = image_bad;
17236 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17237 image_view_create_info.format = tex_format_bad;
17238 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17239 image_view_create_info.subresourceRange.baseMipLevel = 0;
17240 image_view_create_info.subresourceRange.layerCount = 1;
17241 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017242 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017243
17244 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017245 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017246
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017247 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017248
Chia-I Wuf7458c52015-10-26 21:10:41 +080017249 vkDestroyImage(m_device->device(), image_bad, NULL);
17250 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017251 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17252 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017253
17254 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017255}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017256
17257TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017258 TEST_DESCRIPTION(
17259 "Call ClearColorImage w/ a depth|stencil image and "
17260 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017261
17262 ASSERT_NO_FATAL_FAILURE(InitState());
17263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17264
Tony Barbour552f6c02016-12-21 14:34:07 -070017265 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017266
17267 // Color image
17268 VkClearColorValue clear_color;
17269 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17270 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17271 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17272 const int32_t img_width = 32;
17273 const int32_t img_height = 32;
17274 VkImageCreateInfo image_create_info = {};
17275 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17276 image_create_info.pNext = NULL;
17277 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17278 image_create_info.format = color_format;
17279 image_create_info.extent.width = img_width;
17280 image_create_info.extent.height = img_height;
17281 image_create_info.extent.depth = 1;
17282 image_create_info.mipLevels = 1;
17283 image_create_info.arrayLayers = 1;
17284 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17285 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17286 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17287
17288 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017289 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017291 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017292
17293 // Depth/Stencil image
17294 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017295 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017296 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17297 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17298 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17299 ds_image_create_info.extent.width = 64;
17300 ds_image_create_info.extent.height = 64;
17301 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017302 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 -060017303
17304 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017305 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017307 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 -060017308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017311 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017312 &color_range);
17313
17314 m_errorMonitor->VerifyFound();
17315
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17317 "vkCmdClearColorImage called with "
17318 "image created without "
17319 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017320
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017321 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017322 &color_range);
17323
17324 m_errorMonitor->VerifyFound();
17325
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017326 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17328 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017329
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017330 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17331 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017332
17333 m_errorMonitor->VerifyFound();
17334}
Tobin Ehliscde08892015-09-22 10:11:37 -060017335
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017336// WSI Enabled Tests
17337//
Chris Forbes09368e42016-10-13 11:59:22 +130017338#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017339TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17340
17341#if defined(VK_USE_PLATFORM_XCB_KHR)
17342 VkSurfaceKHR surface = VK_NULL_HANDLE;
17343
17344 VkResult err;
17345 bool pass;
17346 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17347 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17348 // uint32_t swapchain_image_count = 0;
17349 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17350 // uint32_t image_index = 0;
17351 // VkPresentInfoKHR present_info = {};
17352
17353 ASSERT_NO_FATAL_FAILURE(InitState());
17354
17355 // Use the create function from one of the VK_KHR_*_surface extension in
17356 // order to create a surface, testing all known errors in the process,
17357 // before successfully creating a surface:
17358 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17360 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17361 pass = (err != VK_SUCCESS);
17362 ASSERT_TRUE(pass);
17363 m_errorMonitor->VerifyFound();
17364
17365 // Next, try to create a surface with the wrong
17366 // VkXcbSurfaceCreateInfoKHR::sType:
17367 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17368 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17370 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17371 pass = (err != VK_SUCCESS);
17372 ASSERT_TRUE(pass);
17373 m_errorMonitor->VerifyFound();
17374
17375 // Create a native window, and then correctly create a surface:
17376 xcb_connection_t *connection;
17377 xcb_screen_t *screen;
17378 xcb_window_t xcb_window;
17379 xcb_intern_atom_reply_t *atom_wm_delete_window;
17380
17381 const xcb_setup_t *setup;
17382 xcb_screen_iterator_t iter;
17383 int scr;
17384 uint32_t value_mask, value_list[32];
17385 int width = 1;
17386 int height = 1;
17387
17388 connection = xcb_connect(NULL, &scr);
17389 ASSERT_TRUE(connection != NULL);
17390 setup = xcb_get_setup(connection);
17391 iter = xcb_setup_roots_iterator(setup);
17392 while (scr-- > 0)
17393 xcb_screen_next(&iter);
17394 screen = iter.data;
17395
17396 xcb_window = xcb_generate_id(connection);
17397
17398 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17399 value_list[0] = screen->black_pixel;
17400 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17401
17402 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17403 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17404
17405 /* Magic code that will send notification when window is destroyed */
17406 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17407 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17408
17409 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17410 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17411 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17412 free(reply);
17413
17414 xcb_map_window(connection, xcb_window);
17415
17416 // Force the x/y coordinates to 100,100 results are identical in consecutive
17417 // runs
17418 const uint32_t coords[] = { 100, 100 };
17419 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17420
17421 // Finally, try to correctly create a surface:
17422 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17423 xcb_create_info.pNext = NULL;
17424 xcb_create_info.flags = 0;
17425 xcb_create_info.connection = connection;
17426 xcb_create_info.window = xcb_window;
17427 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17428 pass = (err == VK_SUCCESS);
17429 ASSERT_TRUE(pass);
17430
17431 // Check if surface supports presentation:
17432
17433 // 1st, do so without having queried the queue families:
17434 VkBool32 supported = false;
17435 // TODO: Get the following error to come out:
17436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17437 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17438 "function");
17439 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17440 pass = (err != VK_SUCCESS);
17441 // ASSERT_TRUE(pass);
17442 // m_errorMonitor->VerifyFound();
17443
17444 // Next, query a queue family index that's too large:
17445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17446 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17447 pass = (err != VK_SUCCESS);
17448 ASSERT_TRUE(pass);
17449 m_errorMonitor->VerifyFound();
17450
17451 // Finally, do so correctly:
17452 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17453 // SUPPORTED
17454 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17455 pass = (err == VK_SUCCESS);
17456 ASSERT_TRUE(pass);
17457
17458 // Before proceeding, try to create a swapchain without having called
17459 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17460 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17461 swapchain_create_info.pNext = NULL;
17462 swapchain_create_info.flags = 0;
17463 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17464 swapchain_create_info.surface = surface;
17465 swapchain_create_info.imageArrayLayers = 1;
17466 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17467 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17469 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17470 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17471 pass = (err != VK_SUCCESS);
17472 ASSERT_TRUE(pass);
17473 m_errorMonitor->VerifyFound();
17474
17475 // Get the surface capabilities:
17476 VkSurfaceCapabilitiesKHR surface_capabilities;
17477
17478 // Do so correctly (only error logged by this entrypoint is if the
17479 // extension isn't enabled):
17480 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17481 pass = (err == VK_SUCCESS);
17482 ASSERT_TRUE(pass);
17483
17484 // Get the surface formats:
17485 uint32_t surface_format_count;
17486
17487 // First, try without a pointer to surface_format_count:
17488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17489 "specified as NULL");
17490 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17491 pass = (err == VK_SUCCESS);
17492 ASSERT_TRUE(pass);
17493 m_errorMonitor->VerifyFound();
17494
17495 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17496 // correctly done a 1st try (to get the count):
17497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17498 surface_format_count = 0;
17499 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17500 pass = (err == VK_SUCCESS);
17501 ASSERT_TRUE(pass);
17502 m_errorMonitor->VerifyFound();
17503
17504 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17505 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17506 pass = (err == VK_SUCCESS);
17507 ASSERT_TRUE(pass);
17508
17509 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17510 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17511
17512 // Next, do a 2nd try with surface_format_count being set too high:
17513 surface_format_count += 5;
17514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17515 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17516 pass = (err == VK_SUCCESS);
17517 ASSERT_TRUE(pass);
17518 m_errorMonitor->VerifyFound();
17519
17520 // Finally, do a correct 1st and 2nd try:
17521 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17522 pass = (err == VK_SUCCESS);
17523 ASSERT_TRUE(pass);
17524 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17525 pass = (err == VK_SUCCESS);
17526 ASSERT_TRUE(pass);
17527
17528 // Get the surface present modes:
17529 uint32_t surface_present_mode_count;
17530
17531 // First, try without a pointer to surface_format_count:
17532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17533 "specified as NULL");
17534
17535 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17536 pass = (err == VK_SUCCESS);
17537 ASSERT_TRUE(pass);
17538 m_errorMonitor->VerifyFound();
17539
17540 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17541 // correctly done a 1st try (to get the count):
17542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17543 surface_present_mode_count = 0;
17544 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17545 (VkPresentModeKHR *)&surface_present_mode_count);
17546 pass = (err == VK_SUCCESS);
17547 ASSERT_TRUE(pass);
17548 m_errorMonitor->VerifyFound();
17549
17550 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17551 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17552 pass = (err == VK_SUCCESS);
17553 ASSERT_TRUE(pass);
17554
17555 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17556 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17557
17558 // Next, do a 2nd try with surface_format_count being set too high:
17559 surface_present_mode_count += 5;
17560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17561 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17562 pass = (err == VK_SUCCESS);
17563 ASSERT_TRUE(pass);
17564 m_errorMonitor->VerifyFound();
17565
17566 // Finally, do a correct 1st and 2nd try:
17567 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17568 pass = (err == VK_SUCCESS);
17569 ASSERT_TRUE(pass);
17570 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17571 pass = (err == VK_SUCCESS);
17572 ASSERT_TRUE(pass);
17573
17574 // Create a swapchain:
17575
17576 // First, try without a pointer to swapchain_create_info:
17577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17578 "specified as NULL");
17579
17580 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17581 pass = (err != VK_SUCCESS);
17582 ASSERT_TRUE(pass);
17583 m_errorMonitor->VerifyFound();
17584
17585 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17586 // sType:
17587 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17589
17590 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17591 pass = (err != VK_SUCCESS);
17592 ASSERT_TRUE(pass);
17593 m_errorMonitor->VerifyFound();
17594
17595 // Next, call with a NULL swapchain pointer:
17596 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17597 swapchain_create_info.pNext = NULL;
17598 swapchain_create_info.flags = 0;
17599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17600 "specified as NULL");
17601
17602 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17603 pass = (err != VK_SUCCESS);
17604 ASSERT_TRUE(pass);
17605 m_errorMonitor->VerifyFound();
17606
17607 // TODO: Enhance swapchain layer so that
17608 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17609
17610 // Next, call with a queue family index that's too large:
17611 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17612 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17613 swapchain_create_info.queueFamilyIndexCount = 2;
17614 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17616 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17617 pass = (err != VK_SUCCESS);
17618 ASSERT_TRUE(pass);
17619 m_errorMonitor->VerifyFound();
17620
17621 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17622 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17623 swapchain_create_info.queueFamilyIndexCount = 1;
17624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17625 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17626 "pCreateInfo->pQueueFamilyIndices).");
17627 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17628 pass = (err != VK_SUCCESS);
17629 ASSERT_TRUE(pass);
17630 m_errorMonitor->VerifyFound();
17631
17632 // Next, call with an invalid imageSharingMode:
17633 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17634 swapchain_create_info.queueFamilyIndexCount = 1;
17635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17636 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17637 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17638 pass = (err != VK_SUCCESS);
17639 ASSERT_TRUE(pass);
17640 m_errorMonitor->VerifyFound();
17641 // Fix for the future:
17642 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17643 // SUPPORTED
17644 swapchain_create_info.queueFamilyIndexCount = 0;
17645 queueFamilyIndex[0] = 0;
17646 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17647
17648 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17649 // Get the images from a swapchain:
17650 // Acquire an image from a swapchain:
17651 // Present an image to a swapchain:
17652 // Destroy the swapchain:
17653
17654 // TODOs:
17655 //
17656 // - Try destroying the device without first destroying the swapchain
17657 //
17658 // - Try destroying the device without first destroying the surface
17659 //
17660 // - Try destroying the surface without first destroying the swapchain
17661
17662 // Destroy the surface:
17663 vkDestroySurfaceKHR(instance(), surface, NULL);
17664
17665 // Tear down the window:
17666 xcb_destroy_window(connection, xcb_window);
17667 xcb_disconnect(connection);
17668
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017669#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017670 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017671#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017672}
Chris Forbes09368e42016-10-13 11:59:22 +130017673#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017674
17675//
17676// POSITIVE VALIDATION TESTS
17677//
17678// These tests do not expect to encounter ANY validation errors pass only if this is true
17679
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070017680TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
17681 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
17682 ASSERT_NO_FATAL_FAILURE(InitState());
17683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17684
17685 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17686 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17687 command_buffer_allocate_info.commandPool = m_commandPool;
17688 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17689 command_buffer_allocate_info.commandBufferCount = 1;
17690
17691 VkCommandBuffer secondary_command_buffer;
17692 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17693 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17694 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17695 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17696 command_buffer_inheritance_info.renderPass = m_renderPass;
17697 command_buffer_inheritance_info.framebuffer = m_framebuffer;
17698
17699 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17700 command_buffer_begin_info.flags =
17701 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
17702 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17703
17704 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17705 VkClearAttachment color_attachment;
17706 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17707 color_attachment.clearValue.color.float32[0] = 0;
17708 color_attachment.clearValue.color.float32[1] = 0;
17709 color_attachment.clearValue.color.float32[2] = 0;
17710 color_attachment.clearValue.color.float32[3] = 0;
17711 color_attachment.colorAttachment = 0;
17712 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
17713 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
17714}
17715
Tobin Ehlise0006882016-11-03 10:14:28 -060017716TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017717 TEST_DESCRIPTION(
17718 "Perform an image layout transition in a secondary command buffer followed "
17719 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017720 VkResult err;
17721 m_errorMonitor->ExpectSuccess();
17722 ASSERT_NO_FATAL_FAILURE(InitState());
17723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17724 // Allocate a secondary and primary cmd buffer
17725 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17726 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17727 command_buffer_allocate_info.commandPool = m_commandPool;
17728 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17729 command_buffer_allocate_info.commandBufferCount = 1;
17730
17731 VkCommandBuffer secondary_command_buffer;
17732 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17733 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17734 VkCommandBuffer primary_command_buffer;
17735 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17736 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17737 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17738 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17739 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17740 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17741 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17742
17743 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17744 ASSERT_VK_SUCCESS(err);
17745 VkImageObj image(m_device);
17746 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17747 ASSERT_TRUE(image.initialized());
17748 VkImageMemoryBarrier img_barrier = {};
17749 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17750 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17751 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17752 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17753 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17754 img_barrier.image = image.handle();
17755 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17756 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17757 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17758 img_barrier.subresourceRange.baseArrayLayer = 0;
17759 img_barrier.subresourceRange.baseMipLevel = 0;
17760 img_barrier.subresourceRange.layerCount = 1;
17761 img_barrier.subresourceRange.levelCount = 1;
17762 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17763 0, nullptr, 1, &img_barrier);
17764 err = vkEndCommandBuffer(secondary_command_buffer);
17765 ASSERT_VK_SUCCESS(err);
17766
17767 // Now update primary cmd buffer to execute secondary and transitions image
17768 command_buffer_begin_info.pInheritanceInfo = nullptr;
17769 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17770 ASSERT_VK_SUCCESS(err);
17771 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17772 VkImageMemoryBarrier img_barrier2 = {};
17773 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17774 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17775 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17776 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17777 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17778 img_barrier2.image = image.handle();
17779 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17780 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17781 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17782 img_barrier2.subresourceRange.baseArrayLayer = 0;
17783 img_barrier2.subresourceRange.baseMipLevel = 0;
17784 img_barrier2.subresourceRange.layerCount = 1;
17785 img_barrier2.subresourceRange.levelCount = 1;
17786 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17787 nullptr, 1, &img_barrier2);
17788 err = vkEndCommandBuffer(primary_command_buffer);
17789 ASSERT_VK_SUCCESS(err);
17790 VkSubmitInfo submit_info = {};
17791 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17792 submit_info.commandBufferCount = 1;
17793 submit_info.pCommandBuffers = &primary_command_buffer;
17794 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17795 ASSERT_VK_SUCCESS(err);
17796 m_errorMonitor->VerifyNotFound();
17797 err = vkDeviceWaitIdle(m_device->device());
17798 ASSERT_VK_SUCCESS(err);
17799 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17800 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17801}
17802
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017803// This is a positive test. No failures are expected.
17804TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017805 TEST_DESCRIPTION(
17806 "Ensure that the vkUpdateDescriptorSets validation code "
17807 "is ignoring VkWriteDescriptorSet members that are not "
17808 "related to the descriptor type specified by "
17809 "VkWriteDescriptorSet::descriptorType. Correct "
17810 "validation behavior will result in the test running to "
17811 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017812
17813 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17814
17815 ASSERT_NO_FATAL_FAILURE(InitState());
17816
17817 // Image Case
17818 {
17819 m_errorMonitor->ExpectSuccess();
17820
17821 VkImage image;
17822 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17823 const int32_t tex_width = 32;
17824 const int32_t tex_height = 32;
17825 VkImageCreateInfo image_create_info = {};
17826 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17827 image_create_info.pNext = NULL;
17828 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17829 image_create_info.format = tex_format;
17830 image_create_info.extent.width = tex_width;
17831 image_create_info.extent.height = tex_height;
17832 image_create_info.extent.depth = 1;
17833 image_create_info.mipLevels = 1;
17834 image_create_info.arrayLayers = 1;
17835 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17836 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17837 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17838 image_create_info.flags = 0;
17839 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17840 ASSERT_VK_SUCCESS(err);
17841
17842 VkMemoryRequirements memory_reqs;
17843 VkDeviceMemory image_memory;
17844 bool pass;
17845 VkMemoryAllocateInfo memory_info = {};
17846 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17847 memory_info.pNext = NULL;
17848 memory_info.allocationSize = 0;
17849 memory_info.memoryTypeIndex = 0;
17850 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17851 memory_info.allocationSize = memory_reqs.size;
17852 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17853 ASSERT_TRUE(pass);
17854 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17855 ASSERT_VK_SUCCESS(err);
17856 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17857 ASSERT_VK_SUCCESS(err);
17858
17859 VkImageViewCreateInfo image_view_create_info = {};
17860 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17861 image_view_create_info.image = image;
17862 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17863 image_view_create_info.format = tex_format;
17864 image_view_create_info.subresourceRange.layerCount = 1;
17865 image_view_create_info.subresourceRange.baseMipLevel = 0;
17866 image_view_create_info.subresourceRange.levelCount = 1;
17867 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17868
17869 VkImageView view;
17870 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17871 ASSERT_VK_SUCCESS(err);
17872
17873 VkDescriptorPoolSize ds_type_count = {};
17874 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17875 ds_type_count.descriptorCount = 1;
17876
17877 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17878 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17879 ds_pool_ci.pNext = NULL;
17880 ds_pool_ci.maxSets = 1;
17881 ds_pool_ci.poolSizeCount = 1;
17882 ds_pool_ci.pPoolSizes = &ds_type_count;
17883
17884 VkDescriptorPool ds_pool;
17885 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17886 ASSERT_VK_SUCCESS(err);
17887
17888 VkDescriptorSetLayoutBinding dsl_binding = {};
17889 dsl_binding.binding = 0;
17890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17891 dsl_binding.descriptorCount = 1;
17892 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17893 dsl_binding.pImmutableSamplers = NULL;
17894
17895 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17896 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17897 ds_layout_ci.pNext = NULL;
17898 ds_layout_ci.bindingCount = 1;
17899 ds_layout_ci.pBindings = &dsl_binding;
17900 VkDescriptorSetLayout ds_layout;
17901 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17902 ASSERT_VK_SUCCESS(err);
17903
17904 VkDescriptorSet descriptor_set;
17905 VkDescriptorSetAllocateInfo alloc_info = {};
17906 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17907 alloc_info.descriptorSetCount = 1;
17908 alloc_info.descriptorPool = ds_pool;
17909 alloc_info.pSetLayouts = &ds_layout;
17910 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17911 ASSERT_VK_SUCCESS(err);
17912
17913 VkDescriptorImageInfo image_info = {};
17914 image_info.imageView = view;
17915 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17916
17917 VkWriteDescriptorSet descriptor_write;
17918 memset(&descriptor_write, 0, sizeof(descriptor_write));
17919 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17920 descriptor_write.dstSet = descriptor_set;
17921 descriptor_write.dstBinding = 0;
17922 descriptor_write.descriptorCount = 1;
17923 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17924 descriptor_write.pImageInfo = &image_info;
17925
17926 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17927 // be
17928 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17929 // This will most likely produce a crash if the parameter_validation
17930 // layer
17931 // does not correctly ignore pBufferInfo.
17932 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17933 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17934
17935 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17936
17937 m_errorMonitor->VerifyNotFound();
17938
17939 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17940 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17941 vkDestroyImageView(m_device->device(), view, NULL);
17942 vkDestroyImage(m_device->device(), image, NULL);
17943 vkFreeMemory(m_device->device(), image_memory, NULL);
17944 }
17945
17946 // Buffer Case
17947 {
17948 m_errorMonitor->ExpectSuccess();
17949
17950 VkBuffer buffer;
17951 uint32_t queue_family_index = 0;
17952 VkBufferCreateInfo buffer_create_info = {};
17953 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17954 buffer_create_info.size = 1024;
17955 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17956 buffer_create_info.queueFamilyIndexCount = 1;
17957 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17958
17959 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17960 ASSERT_VK_SUCCESS(err);
17961
17962 VkMemoryRequirements memory_reqs;
17963 VkDeviceMemory buffer_memory;
17964 bool pass;
17965 VkMemoryAllocateInfo memory_info = {};
17966 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17967 memory_info.pNext = NULL;
17968 memory_info.allocationSize = 0;
17969 memory_info.memoryTypeIndex = 0;
17970
17971 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17972 memory_info.allocationSize = memory_reqs.size;
17973 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17974 ASSERT_TRUE(pass);
17975
17976 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17977 ASSERT_VK_SUCCESS(err);
17978 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17979 ASSERT_VK_SUCCESS(err);
17980
17981 VkDescriptorPoolSize ds_type_count = {};
17982 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17983 ds_type_count.descriptorCount = 1;
17984
17985 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17986 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17987 ds_pool_ci.pNext = NULL;
17988 ds_pool_ci.maxSets = 1;
17989 ds_pool_ci.poolSizeCount = 1;
17990 ds_pool_ci.pPoolSizes = &ds_type_count;
17991
17992 VkDescriptorPool ds_pool;
17993 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17994 ASSERT_VK_SUCCESS(err);
17995
17996 VkDescriptorSetLayoutBinding dsl_binding = {};
17997 dsl_binding.binding = 0;
17998 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17999 dsl_binding.descriptorCount = 1;
18000 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18001 dsl_binding.pImmutableSamplers = NULL;
18002
18003 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18004 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18005 ds_layout_ci.pNext = NULL;
18006 ds_layout_ci.bindingCount = 1;
18007 ds_layout_ci.pBindings = &dsl_binding;
18008 VkDescriptorSetLayout ds_layout;
18009 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18010 ASSERT_VK_SUCCESS(err);
18011
18012 VkDescriptorSet descriptor_set;
18013 VkDescriptorSetAllocateInfo alloc_info = {};
18014 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18015 alloc_info.descriptorSetCount = 1;
18016 alloc_info.descriptorPool = ds_pool;
18017 alloc_info.pSetLayouts = &ds_layout;
18018 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18019 ASSERT_VK_SUCCESS(err);
18020
18021 VkDescriptorBufferInfo buffer_info = {};
18022 buffer_info.buffer = buffer;
18023 buffer_info.offset = 0;
18024 buffer_info.range = 1024;
18025
18026 VkWriteDescriptorSet descriptor_write;
18027 memset(&descriptor_write, 0, sizeof(descriptor_write));
18028 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18029 descriptor_write.dstSet = descriptor_set;
18030 descriptor_write.dstBinding = 0;
18031 descriptor_write.descriptorCount = 1;
18032 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18033 descriptor_write.pBufferInfo = &buffer_info;
18034
18035 // Set pImageInfo and pTexelBufferView to invalid values, which should
18036 // be
18037 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18038 // This will most likely produce a crash if the parameter_validation
18039 // layer
18040 // does not correctly ignore pImageInfo.
18041 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18042 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18043
18044 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18045
18046 m_errorMonitor->VerifyNotFound();
18047
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018048 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18049 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18050 vkDestroyBuffer(m_device->device(), buffer, NULL);
18051 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18052 }
18053
18054 // Texel Buffer Case
18055 {
18056 m_errorMonitor->ExpectSuccess();
18057
18058 VkBuffer buffer;
18059 uint32_t queue_family_index = 0;
18060 VkBufferCreateInfo buffer_create_info = {};
18061 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18062 buffer_create_info.size = 1024;
18063 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18064 buffer_create_info.queueFamilyIndexCount = 1;
18065 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18066
18067 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18068 ASSERT_VK_SUCCESS(err);
18069
18070 VkMemoryRequirements memory_reqs;
18071 VkDeviceMemory buffer_memory;
18072 bool pass;
18073 VkMemoryAllocateInfo memory_info = {};
18074 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18075 memory_info.pNext = NULL;
18076 memory_info.allocationSize = 0;
18077 memory_info.memoryTypeIndex = 0;
18078
18079 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18080 memory_info.allocationSize = memory_reqs.size;
18081 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18082 ASSERT_TRUE(pass);
18083
18084 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18085 ASSERT_VK_SUCCESS(err);
18086 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18087 ASSERT_VK_SUCCESS(err);
18088
18089 VkBufferViewCreateInfo buff_view_ci = {};
18090 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18091 buff_view_ci.buffer = buffer;
18092 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18093 buff_view_ci.range = VK_WHOLE_SIZE;
18094 VkBufferView buffer_view;
18095 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18096
18097 VkDescriptorPoolSize ds_type_count = {};
18098 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18099 ds_type_count.descriptorCount = 1;
18100
18101 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18102 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18103 ds_pool_ci.pNext = NULL;
18104 ds_pool_ci.maxSets = 1;
18105 ds_pool_ci.poolSizeCount = 1;
18106 ds_pool_ci.pPoolSizes = &ds_type_count;
18107
18108 VkDescriptorPool ds_pool;
18109 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18110 ASSERT_VK_SUCCESS(err);
18111
18112 VkDescriptorSetLayoutBinding dsl_binding = {};
18113 dsl_binding.binding = 0;
18114 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18115 dsl_binding.descriptorCount = 1;
18116 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18117 dsl_binding.pImmutableSamplers = NULL;
18118
18119 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18120 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18121 ds_layout_ci.pNext = NULL;
18122 ds_layout_ci.bindingCount = 1;
18123 ds_layout_ci.pBindings = &dsl_binding;
18124 VkDescriptorSetLayout ds_layout;
18125 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18126 ASSERT_VK_SUCCESS(err);
18127
18128 VkDescriptorSet descriptor_set;
18129 VkDescriptorSetAllocateInfo alloc_info = {};
18130 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18131 alloc_info.descriptorSetCount = 1;
18132 alloc_info.descriptorPool = ds_pool;
18133 alloc_info.pSetLayouts = &ds_layout;
18134 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18135 ASSERT_VK_SUCCESS(err);
18136
18137 VkWriteDescriptorSet descriptor_write;
18138 memset(&descriptor_write, 0, sizeof(descriptor_write));
18139 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18140 descriptor_write.dstSet = descriptor_set;
18141 descriptor_write.dstBinding = 0;
18142 descriptor_write.descriptorCount = 1;
18143 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18144 descriptor_write.pTexelBufferView = &buffer_view;
18145
18146 // Set pImageInfo and pBufferInfo to invalid values, which should be
18147 // ignored for descriptorType ==
18148 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18149 // This will most likely produce a crash if the parameter_validation
18150 // layer
18151 // does not correctly ignore pImageInfo and pBufferInfo.
18152 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18153 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18154
18155 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18156
18157 m_errorMonitor->VerifyNotFound();
18158
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018159 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18160 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18161 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18162 vkDestroyBuffer(m_device->device(), buffer, NULL);
18163 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18164 }
18165}
18166
Tobin Ehlisf7428442016-10-25 07:58:24 -060018167TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18168 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18169
18170 ASSERT_NO_FATAL_FAILURE(InitState());
18171 // Create layout where two binding #s are "1"
18172 static const uint32_t NUM_BINDINGS = 3;
18173 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18174 dsl_binding[0].binding = 1;
18175 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18176 dsl_binding[0].descriptorCount = 1;
18177 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18178 dsl_binding[0].pImmutableSamplers = NULL;
18179 dsl_binding[1].binding = 0;
18180 dsl_binding[1].descriptorCount = 1;
18181 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18182 dsl_binding[1].descriptorCount = 1;
18183 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18184 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018185 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018186 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18187 dsl_binding[2].descriptorCount = 1;
18188 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18189 dsl_binding[2].pImmutableSamplers = NULL;
18190
18191 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18192 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18193 ds_layout_ci.pNext = NULL;
18194 ds_layout_ci.bindingCount = NUM_BINDINGS;
18195 ds_layout_ci.pBindings = dsl_binding;
18196 VkDescriptorSetLayout ds_layout;
18197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18198 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18199 m_errorMonitor->VerifyFound();
18200}
18201
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018202TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018203 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18204
18205 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018206
Tony Barbour552f6c02016-12-21 14:34:07 -070018207 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018208
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018209 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18210
18211 {
18212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18213 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18214 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18215 m_errorMonitor->VerifyFound();
18216 }
18217
18218 {
18219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18220 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18221 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18222 m_errorMonitor->VerifyFound();
18223 }
18224
18225 {
18226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18227 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18228 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18229 m_errorMonitor->VerifyFound();
18230 }
18231
18232 {
18233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18234 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18235 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18236 m_errorMonitor->VerifyFound();
18237 }
18238
18239 {
18240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18241 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18242 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18243 m_errorMonitor->VerifyFound();
18244 }
18245
18246 {
18247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18248 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18249 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18250 m_errorMonitor->VerifyFound();
18251 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018252
18253 {
18254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18255 VkRect2D scissor = {{-1, 0}, {16, 16}};
18256 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18257 m_errorMonitor->VerifyFound();
18258 }
18259
18260 {
18261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18262 VkRect2D scissor = {{0, -2}, {16, 16}};
18263 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18264 m_errorMonitor->VerifyFound();
18265 }
18266
18267 {
18268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18269 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18270 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18271 m_errorMonitor->VerifyFound();
18272 }
18273
18274 {
18275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18276 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18277 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18278 m_errorMonitor->VerifyFound();
18279 }
18280
Tony Barbour552f6c02016-12-21 14:34:07 -070018281 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018282}
18283
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018284// This is a positive test. No failures are expected.
18285TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18286 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18287 VkResult err;
18288
18289 ASSERT_NO_FATAL_FAILURE(InitState());
18290 m_errorMonitor->ExpectSuccess();
18291 VkDescriptorPoolSize ds_type_count = {};
18292 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18293 ds_type_count.descriptorCount = 2;
18294
18295 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18296 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18297 ds_pool_ci.pNext = NULL;
18298 ds_pool_ci.maxSets = 1;
18299 ds_pool_ci.poolSizeCount = 1;
18300 ds_pool_ci.pPoolSizes = &ds_type_count;
18301
18302 VkDescriptorPool ds_pool;
18303 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18304 ASSERT_VK_SUCCESS(err);
18305
18306 // Create layout with two uniform buffer descriptors w/ empty binding between them
18307 static const uint32_t NUM_BINDINGS = 3;
18308 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18309 dsl_binding[0].binding = 0;
18310 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18311 dsl_binding[0].descriptorCount = 1;
18312 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18313 dsl_binding[0].pImmutableSamplers = NULL;
18314 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018315 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018316 dsl_binding[2].binding = 2;
18317 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18318 dsl_binding[2].descriptorCount = 1;
18319 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18320 dsl_binding[2].pImmutableSamplers = NULL;
18321
18322 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18323 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18324 ds_layout_ci.pNext = NULL;
18325 ds_layout_ci.bindingCount = NUM_BINDINGS;
18326 ds_layout_ci.pBindings = dsl_binding;
18327 VkDescriptorSetLayout ds_layout;
18328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18329 ASSERT_VK_SUCCESS(err);
18330
18331 VkDescriptorSet descriptor_set = {};
18332 VkDescriptorSetAllocateInfo alloc_info = {};
18333 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18334 alloc_info.descriptorSetCount = 1;
18335 alloc_info.descriptorPool = ds_pool;
18336 alloc_info.pSetLayouts = &ds_layout;
18337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18338 ASSERT_VK_SUCCESS(err);
18339
18340 // Create a buffer to be used for update
18341 VkBufferCreateInfo buff_ci = {};
18342 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18343 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18344 buff_ci.size = 256;
18345 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18346 VkBuffer buffer;
18347 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18348 ASSERT_VK_SUCCESS(err);
18349 // Have to bind memory to buffer before descriptor update
18350 VkMemoryAllocateInfo mem_alloc = {};
18351 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18352 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018353 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018354 mem_alloc.memoryTypeIndex = 0;
18355
18356 VkMemoryRequirements mem_reqs;
18357 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18358 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18359 if (!pass) {
18360 vkDestroyBuffer(m_device->device(), buffer, NULL);
18361 return;
18362 }
18363
18364 VkDeviceMemory mem;
18365 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18366 ASSERT_VK_SUCCESS(err);
18367 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18368 ASSERT_VK_SUCCESS(err);
18369
18370 // Only update the descriptor at binding 2
18371 VkDescriptorBufferInfo buff_info = {};
18372 buff_info.buffer = buffer;
18373 buff_info.offset = 0;
18374 buff_info.range = VK_WHOLE_SIZE;
18375 VkWriteDescriptorSet descriptor_write = {};
18376 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18377 descriptor_write.dstBinding = 2;
18378 descriptor_write.descriptorCount = 1;
18379 descriptor_write.pTexelBufferView = nullptr;
18380 descriptor_write.pBufferInfo = &buff_info;
18381 descriptor_write.pImageInfo = nullptr;
18382 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18383 descriptor_write.dstSet = descriptor_set;
18384
18385 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18386
18387 m_errorMonitor->VerifyNotFound();
18388 // Cleanup
18389 vkFreeMemory(m_device->device(), mem, NULL);
18390 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18391 vkDestroyBuffer(m_device->device(), buffer, NULL);
18392 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18393}
18394
18395// This is a positive test. No failures are expected.
18396TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18397 VkResult err;
18398 bool pass;
18399
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018400 TEST_DESCRIPTION(
18401 "Create a buffer, allocate memory, bind memory, destroy "
18402 "the buffer, create an image, and bind the same memory to "
18403 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018404
18405 m_errorMonitor->ExpectSuccess();
18406
18407 ASSERT_NO_FATAL_FAILURE(InitState());
18408
18409 VkBuffer buffer;
18410 VkImage image;
18411 VkDeviceMemory mem;
18412 VkMemoryRequirements mem_reqs;
18413
18414 VkBufferCreateInfo buf_info = {};
18415 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18416 buf_info.pNext = NULL;
18417 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18418 buf_info.size = 256;
18419 buf_info.queueFamilyIndexCount = 0;
18420 buf_info.pQueueFamilyIndices = NULL;
18421 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18422 buf_info.flags = 0;
18423 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18424 ASSERT_VK_SUCCESS(err);
18425
18426 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18427
18428 VkMemoryAllocateInfo alloc_info = {};
18429 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18430 alloc_info.pNext = NULL;
18431 alloc_info.memoryTypeIndex = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070018432
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018433 // Ensure memory is big enough for both bindings
18434 alloc_info.allocationSize = 0x10000;
18435
18436 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18437 if (!pass) {
18438 vkDestroyBuffer(m_device->device(), buffer, NULL);
18439 return;
18440 }
18441
18442 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18443 ASSERT_VK_SUCCESS(err);
18444
18445 uint8_t *pData;
18446 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18447 ASSERT_VK_SUCCESS(err);
18448
18449 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18450
18451 vkUnmapMemory(m_device->device(), mem);
18452
18453 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18454 ASSERT_VK_SUCCESS(err);
18455
18456 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18457 // memory. In fact, it was never used by the GPU.
18458 // Just be be sure, wait for idle.
18459 vkDestroyBuffer(m_device->device(), buffer, NULL);
18460 vkDeviceWaitIdle(m_device->device());
18461
Tobin Ehlis6a005702016-12-28 15:25:56 -070018462 // Use optimal as some platforms report linear support but then fail image creation
18463 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18464 VkImageFormatProperties image_format_properties;
18465 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18466 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18467 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018468 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018469 vkFreeMemory(m_device->device(), mem, NULL);
18470 return;
18471 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018472 VkImageCreateInfo image_create_info = {};
18473 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18474 image_create_info.pNext = NULL;
18475 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18476 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18477 image_create_info.extent.width = 64;
18478 image_create_info.extent.height = 64;
18479 image_create_info.extent.depth = 1;
18480 image_create_info.mipLevels = 1;
18481 image_create_info.arrayLayers = 1;
18482 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018483 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018484 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18485 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18486 image_create_info.queueFamilyIndexCount = 0;
18487 image_create_info.pQueueFamilyIndices = NULL;
18488 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18489 image_create_info.flags = 0;
18490
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018491 /* Create a mappable image. It will be the texture if linear images are ok
18492 * to be textures or it will be the staging image if they are not.
18493 */
18494 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18495 ASSERT_VK_SUCCESS(err);
18496
18497 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18498
Tobin Ehlis6a005702016-12-28 15:25:56 -070018499 VkMemoryAllocateInfo mem_alloc = {};
18500 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18501 mem_alloc.pNext = NULL;
18502 mem_alloc.allocationSize = 0;
18503 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018504 mem_alloc.allocationSize = mem_reqs.size;
18505
18506 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18507 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018508 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018509 vkDestroyImage(m_device->device(), image, NULL);
18510 return;
18511 }
18512
18513 // VALIDATION FAILURE:
18514 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18515 ASSERT_VK_SUCCESS(err);
18516
18517 m_errorMonitor->VerifyNotFound();
18518
18519 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018520 vkDestroyImage(m_device->device(), image, NULL);
18521}
18522
Tony Barbourab713912017-02-02 14:17:35 -070018523// This is a positive test. No failures are expected.
18524TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18525 VkResult err;
18526
18527 TEST_DESCRIPTION(
18528 "Call all applicable destroy and free routines with NULL"
18529 "handles, expecting no validation errors");
18530
18531 m_errorMonitor->ExpectSuccess();
18532
18533 ASSERT_NO_FATAL_FAILURE(InitState());
18534 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18535 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18536 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18537 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18538 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18539 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18540 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18541 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18542 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18543 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18544 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18545 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18546 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18547 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18548 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18549 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18550 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18551 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18552 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18553 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18554
18555 VkCommandPool command_pool;
18556 VkCommandPoolCreateInfo pool_create_info{};
18557 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18558 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18559 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18560 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18561 VkCommandBuffer command_buffers[3] = {};
18562 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18563 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18564 command_buffer_allocate_info.commandPool = command_pool;
18565 command_buffer_allocate_info.commandBufferCount = 1;
18566 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18567 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18568 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18569 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18570
18571 VkDescriptorPoolSize ds_type_count = {};
18572 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18573 ds_type_count.descriptorCount = 1;
18574
18575 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18576 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18577 ds_pool_ci.pNext = NULL;
18578 ds_pool_ci.maxSets = 1;
18579 ds_pool_ci.poolSizeCount = 1;
18580 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18581 ds_pool_ci.pPoolSizes = &ds_type_count;
18582
18583 VkDescriptorPool ds_pool;
18584 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18585 ASSERT_VK_SUCCESS(err);
18586
18587 VkDescriptorSetLayoutBinding dsl_binding = {};
18588 dsl_binding.binding = 2;
18589 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18590 dsl_binding.descriptorCount = 1;
18591 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18592 dsl_binding.pImmutableSamplers = NULL;
18593 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18594 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18595 ds_layout_ci.pNext = NULL;
18596 ds_layout_ci.bindingCount = 1;
18597 ds_layout_ci.pBindings = &dsl_binding;
18598 VkDescriptorSetLayout ds_layout;
18599 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18600 ASSERT_VK_SUCCESS(err);
18601
18602 VkDescriptorSet descriptor_sets[3] = {};
18603 VkDescriptorSetAllocateInfo alloc_info = {};
18604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18605 alloc_info.descriptorSetCount = 1;
18606 alloc_info.descriptorPool = ds_pool;
18607 alloc_info.pSetLayouts = &ds_layout;
18608 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18609 ASSERT_VK_SUCCESS(err);
18610 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18611 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18612 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18613
18614 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18615
18616 m_errorMonitor->VerifyNotFound();
18617}
18618
Tony Barbour626994c2017-02-08 15:29:37 -070018619TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018620 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018621
18622 m_errorMonitor->ExpectSuccess();
18623
18624 ASSERT_NO_FATAL_FAILURE(InitState());
18625 VkCommandBuffer cmd_bufs[4];
18626 VkCommandBufferAllocateInfo alloc_info;
18627 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18628 alloc_info.pNext = NULL;
18629 alloc_info.commandBufferCount = 4;
18630 alloc_info.commandPool = m_commandPool;
18631 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18632 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18633 VkImageObj image(m_device);
18634 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18635 ASSERT_TRUE(image.initialized());
18636 VkCommandBufferBeginInfo cb_binfo;
18637 cb_binfo.pNext = NULL;
18638 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18639 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18640 cb_binfo.flags = 0;
18641 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18642 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18643 VkImageMemoryBarrier img_barrier = {};
18644 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18645 img_barrier.pNext = NULL;
18646 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18647 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18648 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18649 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18650 img_barrier.image = image.handle();
18651 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18652 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18653 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18654 img_barrier.subresourceRange.baseArrayLayer = 0;
18655 img_barrier.subresourceRange.baseMipLevel = 0;
18656 img_barrier.subresourceRange.layerCount = 1;
18657 img_barrier.subresourceRange.levelCount = 1;
18658 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18659 &img_barrier);
18660 vkEndCommandBuffer(cmd_bufs[0]);
18661 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18662 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18663 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18664 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18665 &img_barrier);
18666 vkEndCommandBuffer(cmd_bufs[1]);
18667 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18668 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18669 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18670 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18671 &img_barrier);
18672 vkEndCommandBuffer(cmd_bufs[2]);
18673 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18674 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18675 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18676 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18677 &img_barrier);
18678 vkEndCommandBuffer(cmd_bufs[3]);
18679
18680 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18681 VkSemaphore semaphore1, semaphore2;
18682 VkSemaphoreCreateInfo semaphore_create_info{};
18683 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18684 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18685 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18686 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18687 VkSubmitInfo submit_info[3];
18688 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18689 submit_info[0].pNext = nullptr;
18690 submit_info[0].commandBufferCount = 1;
18691 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18692 submit_info[0].signalSemaphoreCount = 1;
18693 submit_info[0].pSignalSemaphores = &semaphore1;
18694 submit_info[0].waitSemaphoreCount = 0;
18695 submit_info[0].pWaitDstStageMask = nullptr;
18696 submit_info[0].pWaitDstStageMask = flags;
18697 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18698 submit_info[1].pNext = nullptr;
18699 submit_info[1].commandBufferCount = 1;
18700 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18701 submit_info[1].waitSemaphoreCount = 1;
18702 submit_info[1].pWaitSemaphores = &semaphore1;
18703 submit_info[1].signalSemaphoreCount = 1;
18704 submit_info[1].pSignalSemaphores = &semaphore2;
18705 submit_info[1].pWaitDstStageMask = flags;
18706 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18707 submit_info[2].pNext = nullptr;
18708 submit_info[2].commandBufferCount = 2;
18709 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18710 submit_info[2].waitSemaphoreCount = 1;
18711 submit_info[2].pWaitSemaphores = &semaphore2;
18712 submit_info[2].signalSemaphoreCount = 0;
18713 submit_info[2].pSignalSemaphores = nullptr;
18714 submit_info[2].pWaitDstStageMask = flags;
18715 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18716 vkQueueWaitIdle(m_device->m_queue);
18717
18718 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18719 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18720 m_errorMonitor->VerifyNotFound();
18721}
18722
Tobin Ehlis953e8392016-11-17 10:54:13 -070018723TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18724 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18725 // We previously had a bug where dynamic offset of inactive bindings was still being used
18726 VkResult err;
18727 m_errorMonitor->ExpectSuccess();
18728
18729 ASSERT_NO_FATAL_FAILURE(InitState());
18730 ASSERT_NO_FATAL_FAILURE(InitViewport());
18731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18732
18733 VkDescriptorPoolSize ds_type_count = {};
18734 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18735 ds_type_count.descriptorCount = 3;
18736
18737 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18738 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18739 ds_pool_ci.pNext = NULL;
18740 ds_pool_ci.maxSets = 1;
18741 ds_pool_ci.poolSizeCount = 1;
18742 ds_pool_ci.pPoolSizes = &ds_type_count;
18743
18744 VkDescriptorPool ds_pool;
18745 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18746 ASSERT_VK_SUCCESS(err);
18747
18748 const uint32_t BINDING_COUNT = 3;
18749 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018750 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018751 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18752 dsl_binding[0].descriptorCount = 1;
18753 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18754 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018755 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018756 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18757 dsl_binding[1].descriptorCount = 1;
18758 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18759 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018760 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018761 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18762 dsl_binding[2].descriptorCount = 1;
18763 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18764 dsl_binding[2].pImmutableSamplers = NULL;
18765
18766 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18767 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18768 ds_layout_ci.pNext = NULL;
18769 ds_layout_ci.bindingCount = BINDING_COUNT;
18770 ds_layout_ci.pBindings = dsl_binding;
18771 VkDescriptorSetLayout ds_layout;
18772 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18773 ASSERT_VK_SUCCESS(err);
18774
18775 VkDescriptorSet descriptor_set;
18776 VkDescriptorSetAllocateInfo alloc_info = {};
18777 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18778 alloc_info.descriptorSetCount = 1;
18779 alloc_info.descriptorPool = ds_pool;
18780 alloc_info.pSetLayouts = &ds_layout;
18781 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18782 ASSERT_VK_SUCCESS(err);
18783
18784 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18785 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18786 pipeline_layout_ci.pNext = NULL;
18787 pipeline_layout_ci.setLayoutCount = 1;
18788 pipeline_layout_ci.pSetLayouts = &ds_layout;
18789
18790 VkPipelineLayout pipeline_layout;
18791 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18792 ASSERT_VK_SUCCESS(err);
18793
18794 // Create two buffers to update the descriptors with
18795 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18796 uint32_t qfi = 0;
18797 VkBufferCreateInfo buffCI = {};
18798 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18799 buffCI.size = 2048;
18800 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18801 buffCI.queueFamilyIndexCount = 1;
18802 buffCI.pQueueFamilyIndices = &qfi;
18803
18804 VkBuffer dyub1;
18805 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18806 ASSERT_VK_SUCCESS(err);
18807 // buffer2
18808 buffCI.size = 1024;
18809 VkBuffer dyub2;
18810 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18811 ASSERT_VK_SUCCESS(err);
18812 // Allocate memory and bind to buffers
18813 VkMemoryAllocateInfo mem_alloc[2] = {};
18814 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18815 mem_alloc[0].pNext = NULL;
18816 mem_alloc[0].memoryTypeIndex = 0;
18817 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18818 mem_alloc[1].pNext = NULL;
18819 mem_alloc[1].memoryTypeIndex = 0;
18820
18821 VkMemoryRequirements mem_reqs1;
18822 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18823 VkMemoryRequirements mem_reqs2;
18824 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18825 mem_alloc[0].allocationSize = mem_reqs1.size;
18826 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18827 mem_alloc[1].allocationSize = mem_reqs2.size;
18828 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18829 if (!pass) {
18830 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18831 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18832 return;
18833 }
18834
18835 VkDeviceMemory mem1;
18836 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18837 ASSERT_VK_SUCCESS(err);
18838 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18839 ASSERT_VK_SUCCESS(err);
18840 VkDeviceMemory mem2;
18841 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18842 ASSERT_VK_SUCCESS(err);
18843 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18844 ASSERT_VK_SUCCESS(err);
18845 // Update descriptors
18846 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18847 buff_info[0].buffer = dyub1;
18848 buff_info[0].offset = 0;
18849 buff_info[0].range = 256;
18850 buff_info[1].buffer = dyub1;
18851 buff_info[1].offset = 256;
18852 buff_info[1].range = 512;
18853 buff_info[2].buffer = dyub2;
18854 buff_info[2].offset = 0;
18855 buff_info[2].range = 512;
18856
18857 VkWriteDescriptorSet descriptor_write;
18858 memset(&descriptor_write, 0, sizeof(descriptor_write));
18859 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18860 descriptor_write.dstSet = descriptor_set;
18861 descriptor_write.dstBinding = 0;
18862 descriptor_write.descriptorCount = BINDING_COUNT;
18863 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18864 descriptor_write.pBufferInfo = buff_info;
18865
18866 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18867
Tony Barbour552f6c02016-12-21 14:34:07 -070018868 m_commandBuffer->BeginCommandBuffer();
18869 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018870
18871 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018872 char const *vsSource =
18873 "#version 450\n"
18874 "\n"
18875 "out gl_PerVertex { \n"
18876 " vec4 gl_Position;\n"
18877 "};\n"
18878 "void main(){\n"
18879 " gl_Position = vec4(1);\n"
18880 "}\n";
18881 char const *fsSource =
18882 "#version 450\n"
18883 "\n"
18884 "layout(location=0) out vec4 x;\n"
18885 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18886 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18887 "void main(){\n"
18888 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18889 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018890 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18891 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18892 VkPipelineObj pipe(m_device);
18893 pipe.SetViewport(m_viewports);
18894 pipe.SetScissor(m_scissors);
18895 pipe.AddShader(&vs);
18896 pipe.AddShader(&fs);
18897 pipe.AddColorAttachment();
18898 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18899
18900 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18901 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18902 // we used to have a bug in this case.
18903 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18904 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18905 &descriptor_set, BINDING_COUNT, dyn_off);
18906 Draw(1, 0, 0, 0);
18907 m_errorMonitor->VerifyNotFound();
18908
18909 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18910 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18911 vkFreeMemory(m_device->device(), mem1, NULL);
18912 vkFreeMemory(m_device->device(), mem2, NULL);
18913
18914 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18915 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18916 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18917}
18918
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018919TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018920 TEST_DESCRIPTION(
18921 "Ensure that validations handling of non-coherent memory "
18922 "mapping while using VK_WHOLE_SIZE does not cause access "
18923 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018924 VkResult err;
18925 uint8_t *pData;
18926 ASSERT_NO_FATAL_FAILURE(InitState());
18927
18928 VkDeviceMemory mem;
18929 VkMemoryRequirements mem_reqs;
18930 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018931 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018932 VkMemoryAllocateInfo alloc_info = {};
18933 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18934 alloc_info.pNext = NULL;
18935 alloc_info.memoryTypeIndex = 0;
18936
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018937 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018938 alloc_info.allocationSize = allocation_size;
18939
18940 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
18941 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 -070018942 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018943 if (!pass) {
18944 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018945 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
18946 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018947 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018948 pass = m_device->phy().set_memory_type(
18949 mem_reqs.memoryTypeBits, &alloc_info,
18950 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
18951 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018952 if (!pass) {
18953 return;
18954 }
18955 }
18956 }
18957
18958 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18959 ASSERT_VK_SUCCESS(err);
18960
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018961 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018962 m_errorMonitor->ExpectSuccess();
18963 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
18964 ASSERT_VK_SUCCESS(err);
18965 VkMappedMemoryRange mmr = {};
18966 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18967 mmr.memory = mem;
18968 mmr.offset = 0;
18969 mmr.size = VK_WHOLE_SIZE;
18970 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18971 ASSERT_VK_SUCCESS(err);
18972 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18973 ASSERT_VK_SUCCESS(err);
18974 m_errorMonitor->VerifyNotFound();
18975 vkUnmapMemory(m_device->device(), mem);
18976
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018977 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018978 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018979 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018980 ASSERT_VK_SUCCESS(err);
18981 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18982 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018983 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018984 mmr.size = VK_WHOLE_SIZE;
18985 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18986 ASSERT_VK_SUCCESS(err);
18987 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18988 ASSERT_VK_SUCCESS(err);
18989 m_errorMonitor->VerifyNotFound();
18990 vkUnmapMemory(m_device->device(), mem);
18991
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018992 // Map with offset and size
18993 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018994 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018995 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018996 ASSERT_VK_SUCCESS(err);
18997 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18998 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018999 mmr.offset = 4 * atom_size;
19000 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019001 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19002 ASSERT_VK_SUCCESS(err);
19003 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19004 ASSERT_VK_SUCCESS(err);
19005 m_errorMonitor->VerifyNotFound();
19006 vkUnmapMemory(m_device->device(), mem);
19007
19008 // Map without offset and flush WHOLE_SIZE with two separate offsets
19009 m_errorMonitor->ExpectSuccess();
19010 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19011 ASSERT_VK_SUCCESS(err);
19012 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19013 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019014 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019015 mmr.size = VK_WHOLE_SIZE;
19016 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19017 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019018 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019019 mmr.size = VK_WHOLE_SIZE;
19020 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19021 ASSERT_VK_SUCCESS(err);
19022 m_errorMonitor->VerifyNotFound();
19023 vkUnmapMemory(m_device->device(), mem);
19024
19025 vkFreeMemory(m_device->device(), mem, NULL);
19026}
19027
19028// This is a positive test. We used to expect error in this case but spec now allows it
19029TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19030 m_errorMonitor->ExpectSuccess();
19031 vk_testing::Fence testFence;
19032 VkFenceCreateInfo fenceInfo = {};
19033 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19034 fenceInfo.pNext = NULL;
19035
19036 ASSERT_NO_FATAL_FAILURE(InitState());
19037 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019038 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019039 VkResult result = vkResetFences(m_device->device(), 1, fences);
19040 ASSERT_VK_SUCCESS(result);
19041
19042 m_errorMonitor->VerifyNotFound();
19043}
19044
19045TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19046 m_errorMonitor->ExpectSuccess();
19047
19048 ASSERT_NO_FATAL_FAILURE(InitState());
19049 VkResult err;
19050
19051 // Record (empty!) command buffer that can be submitted multiple times
19052 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019053 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19054 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019055 m_commandBuffer->BeginCommandBuffer(&cbbi);
19056 m_commandBuffer->EndCommandBuffer();
19057
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019058 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019059 VkFence fence;
19060 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19061 ASSERT_VK_SUCCESS(err);
19062
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019063 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019064 VkSemaphore s1, s2;
19065 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19066 ASSERT_VK_SUCCESS(err);
19067 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19068 ASSERT_VK_SUCCESS(err);
19069
19070 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019071 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019072 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19073 ASSERT_VK_SUCCESS(err);
19074
19075 // Submit CB again, signaling s2.
19076 si.pSignalSemaphores = &s2;
19077 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19078 ASSERT_VK_SUCCESS(err);
19079
19080 // Wait for fence.
19081 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19082 ASSERT_VK_SUCCESS(err);
19083
19084 // CB is still in flight from second submission, but semaphore s1 is no
19085 // longer in flight. delete it.
19086 vkDestroySemaphore(m_device->device(), s1, nullptr);
19087
19088 m_errorMonitor->VerifyNotFound();
19089
19090 // Force device idle and clean up remaining objects
19091 vkDeviceWaitIdle(m_device->device());
19092 vkDestroySemaphore(m_device->device(), s2, nullptr);
19093 vkDestroyFence(m_device->device(), fence, nullptr);
19094}
19095
19096TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19097 m_errorMonitor->ExpectSuccess();
19098
19099 ASSERT_NO_FATAL_FAILURE(InitState());
19100 VkResult err;
19101
19102 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019103 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019104 VkFence f1;
19105 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19106 ASSERT_VK_SUCCESS(err);
19107
19108 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019109 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019110 VkFence f2;
19111 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19112 ASSERT_VK_SUCCESS(err);
19113
19114 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019115 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019116 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19117
19118 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019119 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019120 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19121
19122 // Should have both retired!
19123 vkDestroyFence(m_device->device(), f1, nullptr);
19124 vkDestroyFence(m_device->device(), f2, nullptr);
19125
19126 m_errorMonitor->VerifyNotFound();
19127}
19128
19129TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019130 TEST_DESCRIPTION(
19131 "Verify that creating an image view from an image with valid usage "
19132 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019133
19134 ASSERT_NO_FATAL_FAILURE(InitState());
19135
19136 m_errorMonitor->ExpectSuccess();
19137 // Verify that we can create a view with usage INPUT_ATTACHMENT
19138 VkImageObj image(m_device);
19139 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19140 ASSERT_TRUE(image.initialized());
19141 VkImageView imageView;
19142 VkImageViewCreateInfo ivci = {};
19143 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19144 ivci.image = image.handle();
19145 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19146 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19147 ivci.subresourceRange.layerCount = 1;
19148 ivci.subresourceRange.baseMipLevel = 0;
19149 ivci.subresourceRange.levelCount = 1;
19150 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19151
19152 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19153 m_errorMonitor->VerifyNotFound();
19154 vkDestroyImageView(m_device->device(), imageView, NULL);
19155}
19156
19157// This is a positive test. No failures are expected.
19158TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019159 TEST_DESCRIPTION(
19160 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19161 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019162
19163 ASSERT_NO_FATAL_FAILURE(InitState());
19164
19165 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019166 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019167
19168 m_errorMonitor->ExpectSuccess();
19169
19170 VkImage image;
19171 VkImageCreateInfo image_create_info = {};
19172 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19173 image_create_info.pNext = NULL;
19174 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19175 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19176 image_create_info.extent.width = 64;
19177 image_create_info.extent.height = 64;
19178 image_create_info.extent.depth = 1;
19179 image_create_info.mipLevels = 1;
19180 image_create_info.arrayLayers = 1;
19181 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19182 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19183 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19184 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19185 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19186 ASSERT_VK_SUCCESS(err);
19187
19188 VkMemoryRequirements memory_reqs;
19189 VkDeviceMemory memory_one, memory_two;
19190 bool pass;
19191 VkMemoryAllocateInfo memory_info = {};
19192 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19193 memory_info.pNext = NULL;
19194 memory_info.allocationSize = 0;
19195 memory_info.memoryTypeIndex = 0;
19196 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19197 // Find an image big enough to allow sparse mapping of 2 memory regions
19198 // Increase the image size until it is at least twice the
19199 // size of the required alignment, to ensure we can bind both
19200 // allocated memory blocks to the image on aligned offsets.
19201 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19202 vkDestroyImage(m_device->device(), image, nullptr);
19203 image_create_info.extent.width *= 2;
19204 image_create_info.extent.height *= 2;
19205 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19206 ASSERT_VK_SUCCESS(err);
19207 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19208 }
19209 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19210 // at the end of the first
19211 memory_info.allocationSize = memory_reqs.alignment;
19212 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19213 ASSERT_TRUE(pass);
19214 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19215 ASSERT_VK_SUCCESS(err);
19216 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19217 ASSERT_VK_SUCCESS(err);
19218 VkSparseMemoryBind binds[2];
19219 binds[0].flags = 0;
19220 binds[0].memory = memory_one;
19221 binds[0].memoryOffset = 0;
19222 binds[0].resourceOffset = 0;
19223 binds[0].size = memory_info.allocationSize;
19224 binds[1].flags = 0;
19225 binds[1].memory = memory_two;
19226 binds[1].memoryOffset = 0;
19227 binds[1].resourceOffset = memory_info.allocationSize;
19228 binds[1].size = memory_info.allocationSize;
19229
19230 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19231 opaqueBindInfo.image = image;
19232 opaqueBindInfo.bindCount = 2;
19233 opaqueBindInfo.pBinds = binds;
19234
19235 VkFence fence = VK_NULL_HANDLE;
19236 VkBindSparseInfo bindSparseInfo = {};
19237 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19238 bindSparseInfo.imageOpaqueBindCount = 1;
19239 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19240
19241 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19242 vkQueueWaitIdle(m_device->m_queue);
19243 vkDestroyImage(m_device->device(), image, NULL);
19244 vkFreeMemory(m_device->device(), memory_one, NULL);
19245 vkFreeMemory(m_device->device(), memory_two, NULL);
19246 m_errorMonitor->VerifyNotFound();
19247}
19248
19249TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019250 TEST_DESCRIPTION(
19251 "Ensure that CmdBeginRenderPass with an attachment's "
19252 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19253 "the command buffer has prior knowledge of that "
19254 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019255
19256 m_errorMonitor->ExpectSuccess();
19257
19258 ASSERT_NO_FATAL_FAILURE(InitState());
19259
19260 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019261 VkAttachmentDescription attachment = {0,
19262 VK_FORMAT_R8G8B8A8_UNORM,
19263 VK_SAMPLE_COUNT_1_BIT,
19264 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19265 VK_ATTACHMENT_STORE_OP_STORE,
19266 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19267 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19268 VK_IMAGE_LAYOUT_UNDEFINED,
19269 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019270
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019271 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019272
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019273 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019274
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019275 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019276
19277 VkRenderPass rp;
19278 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19279 ASSERT_VK_SUCCESS(err);
19280
19281 // A compatible framebuffer.
19282 VkImageObj image(m_device);
19283 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19284 ASSERT_TRUE(image.initialized());
19285
19286 VkImageViewCreateInfo ivci = {
19287 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19288 nullptr,
19289 0,
19290 image.handle(),
19291 VK_IMAGE_VIEW_TYPE_2D,
19292 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019293 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19294 VK_COMPONENT_SWIZZLE_IDENTITY},
19295 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019296 };
19297 VkImageView view;
19298 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19299 ASSERT_VK_SUCCESS(err);
19300
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019301 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019302 VkFramebuffer fb;
19303 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19304 ASSERT_VK_SUCCESS(err);
19305
19306 // Record a single command buffer which uses this renderpass twice. The
19307 // bug is triggered at the beginning of the second renderpass, when the
19308 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019309 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 -070019310 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019311 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19312 vkCmdEndRenderPass(m_commandBuffer->handle());
19313 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19314
19315 m_errorMonitor->VerifyNotFound();
19316
19317 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019318 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019319
19320 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19321 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19322 vkDestroyImageView(m_device->device(), view, nullptr);
19323}
19324
19325TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019326 TEST_DESCRIPTION(
19327 "This test should pass. Create a Framebuffer and "
19328 "command buffer, bind them together, then destroy "
19329 "command pool and framebuffer and verify there are no "
19330 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019331
19332 m_errorMonitor->ExpectSuccess();
19333
19334 ASSERT_NO_FATAL_FAILURE(InitState());
19335
19336 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019337 VkAttachmentDescription attachment = {0,
19338 VK_FORMAT_R8G8B8A8_UNORM,
19339 VK_SAMPLE_COUNT_1_BIT,
19340 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19341 VK_ATTACHMENT_STORE_OP_STORE,
19342 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19343 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19344 VK_IMAGE_LAYOUT_UNDEFINED,
19345 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019346
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019347 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019348
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019349 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019350
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019351 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019352
19353 VkRenderPass rp;
19354 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19355 ASSERT_VK_SUCCESS(err);
19356
19357 // A compatible framebuffer.
19358 VkImageObj image(m_device);
19359 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19360 ASSERT_TRUE(image.initialized());
19361
19362 VkImageViewCreateInfo ivci = {
19363 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19364 nullptr,
19365 0,
19366 image.handle(),
19367 VK_IMAGE_VIEW_TYPE_2D,
19368 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019369 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19370 VK_COMPONENT_SWIZZLE_IDENTITY},
19371 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019372 };
19373 VkImageView view;
19374 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19375 ASSERT_VK_SUCCESS(err);
19376
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019377 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019378 VkFramebuffer fb;
19379 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19380 ASSERT_VK_SUCCESS(err);
19381
19382 // Explicitly create a command buffer to bind the FB to so that we can then
19383 // destroy the command pool in order to implicitly free command buffer
19384 VkCommandPool command_pool;
19385 VkCommandPoolCreateInfo pool_create_info{};
19386 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19387 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19388 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19389 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19390
19391 VkCommandBuffer command_buffer;
19392 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19393 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19394 command_buffer_allocate_info.commandPool = command_pool;
19395 command_buffer_allocate_info.commandBufferCount = 1;
19396 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19397 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19398
19399 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019400 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019401 VkCommandBufferBeginInfo begin_info{};
19402 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19403 vkBeginCommandBuffer(command_buffer, &begin_info);
19404
19405 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19406 vkCmdEndRenderPass(command_buffer);
19407 vkEndCommandBuffer(command_buffer);
19408 vkDestroyImageView(m_device->device(), view, nullptr);
19409 // Destroy command pool to implicitly free command buffer
19410 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19411 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19412 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19413 m_errorMonitor->VerifyNotFound();
19414}
19415
19416TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019417 TEST_DESCRIPTION(
19418 "Ensure that CmdBeginRenderPass applies the layout "
19419 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019420
19421 m_errorMonitor->ExpectSuccess();
19422
19423 ASSERT_NO_FATAL_FAILURE(InitState());
19424
19425 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019426 VkAttachmentDescription attachment = {0,
19427 VK_FORMAT_R8G8B8A8_UNORM,
19428 VK_SAMPLE_COUNT_1_BIT,
19429 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19430 VK_ATTACHMENT_STORE_OP_STORE,
19431 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19432 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19433 VK_IMAGE_LAYOUT_UNDEFINED,
19434 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019435
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019436 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019437
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019438 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019439
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019440 VkSubpassDependency dep = {0,
19441 0,
19442 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19443 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19444 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19445 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19446 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019447
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019448 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019449
19450 VkResult err;
19451 VkRenderPass rp;
19452 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19453 ASSERT_VK_SUCCESS(err);
19454
19455 // A compatible framebuffer.
19456 VkImageObj image(m_device);
19457 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19458 ASSERT_TRUE(image.initialized());
19459
19460 VkImageViewCreateInfo ivci = {
19461 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19462 nullptr,
19463 0,
19464 image.handle(),
19465 VK_IMAGE_VIEW_TYPE_2D,
19466 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019467 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19468 VK_COMPONENT_SWIZZLE_IDENTITY},
19469 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019470 };
19471 VkImageView view;
19472 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19473 ASSERT_VK_SUCCESS(err);
19474
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019475 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019476 VkFramebuffer fb;
19477 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19478 ASSERT_VK_SUCCESS(err);
19479
19480 // Record a single command buffer which issues a pipeline barrier w/
19481 // image memory barrier for the attachment. This detects the previously
19482 // missing tracking of the subpass layout by throwing a validation error
19483 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019484 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 -070019485 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019486 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19487
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019488 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19489 nullptr,
19490 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19491 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19492 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19493 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19494 VK_QUEUE_FAMILY_IGNORED,
19495 VK_QUEUE_FAMILY_IGNORED,
19496 image.handle(),
19497 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019498 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019499 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19500 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019501
19502 vkCmdEndRenderPass(m_commandBuffer->handle());
19503 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019504 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019505
19506 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19507 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19508 vkDestroyImageView(m_device->device(), view, nullptr);
19509}
19510
19511TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019512 TEST_DESCRIPTION(
19513 "Validate that when an imageView of a depth/stencil image "
19514 "is used as a depth/stencil framebuffer attachment, the "
19515 "aspectMask is ignored and both depth and stencil image "
19516 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019517
19518 VkFormatProperties format_properties;
19519 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19520 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19521 return;
19522 }
19523
19524 m_errorMonitor->ExpectSuccess();
19525
19526 ASSERT_NO_FATAL_FAILURE(InitState());
19527
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019528 VkAttachmentDescription attachment = {0,
19529 VK_FORMAT_D32_SFLOAT_S8_UINT,
19530 VK_SAMPLE_COUNT_1_BIT,
19531 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19532 VK_ATTACHMENT_STORE_OP_STORE,
19533 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19534 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19535 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19536 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019537
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019538 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019539
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019540 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019541
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019542 VkSubpassDependency dep = {0,
19543 0,
19544 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19545 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19546 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19547 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19548 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019549
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019550 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019551
19552 VkResult err;
19553 VkRenderPass rp;
19554 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19555 ASSERT_VK_SUCCESS(err);
19556
19557 VkImageObj image(m_device);
19558 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019559 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019560 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019561 ASSERT_TRUE(image.initialized());
19562 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19563
19564 VkImageViewCreateInfo ivci = {
19565 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19566 nullptr,
19567 0,
19568 image.handle(),
19569 VK_IMAGE_VIEW_TYPE_2D,
19570 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019571 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19572 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019573 };
19574 VkImageView view;
19575 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19576 ASSERT_VK_SUCCESS(err);
19577
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019578 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019579 VkFramebuffer fb;
19580 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19581 ASSERT_VK_SUCCESS(err);
19582
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019583 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 -070019584 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019585 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19586
19587 VkImageMemoryBarrier imb = {};
19588 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19589 imb.pNext = nullptr;
19590 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19591 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19592 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19593 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19594 imb.srcQueueFamilyIndex = 0;
19595 imb.dstQueueFamilyIndex = 0;
19596 imb.image = image.handle();
19597 imb.subresourceRange.aspectMask = 0x6;
19598 imb.subresourceRange.baseMipLevel = 0;
19599 imb.subresourceRange.levelCount = 0x1;
19600 imb.subresourceRange.baseArrayLayer = 0;
19601 imb.subresourceRange.layerCount = 0x1;
19602
19603 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019604 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19605 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019606
19607 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019608 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019609 QueueCommandBuffer(false);
19610 m_errorMonitor->VerifyNotFound();
19611
19612 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19613 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19614 vkDestroyImageView(m_device->device(), view, nullptr);
19615}
19616
19617TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019618 TEST_DESCRIPTION(
19619 "Ensure that layout transitions work correctly without "
19620 "errors, when an attachment reference is "
19621 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019622
19623 m_errorMonitor->ExpectSuccess();
19624
19625 ASSERT_NO_FATAL_FAILURE(InitState());
19626
19627 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019628 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019629
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019630 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019631
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019632 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019633
19634 VkRenderPass rp;
19635 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19636 ASSERT_VK_SUCCESS(err);
19637
19638 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019639 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019640 VkFramebuffer fb;
19641 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19642 ASSERT_VK_SUCCESS(err);
19643
19644 // Record a command buffer which just begins and ends the renderpass. The
19645 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019646 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 -070019647 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019648 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19649 vkCmdEndRenderPass(m_commandBuffer->handle());
19650 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019651 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019652
19653 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19654 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19655}
19656
19657// This is a positive test. No errors are expected.
19658TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019659 TEST_DESCRIPTION(
19660 "Create a stencil-only attachment with a LOAD_OP set to "
19661 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019662 VkResult result = VK_SUCCESS;
19663 VkImageFormatProperties formatProps;
19664 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019665 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19666 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019667 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19668 return;
19669 }
19670
19671 ASSERT_NO_FATAL_FAILURE(InitState());
19672 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19673 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019674 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019675 VkAttachmentDescription att = {};
19676 VkAttachmentReference ref = {};
19677 att.format = depth_stencil_fmt;
19678 att.samples = VK_SAMPLE_COUNT_1_BIT;
19679 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19680 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19681 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19682 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19683 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19684 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19685
19686 VkClearValue clear;
19687 clear.depthStencil.depth = 1.0;
19688 clear.depthStencil.stencil = 0;
19689 ref.attachment = 0;
19690 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19691
19692 VkSubpassDescription subpass = {};
19693 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19694 subpass.flags = 0;
19695 subpass.inputAttachmentCount = 0;
19696 subpass.pInputAttachments = NULL;
19697 subpass.colorAttachmentCount = 0;
19698 subpass.pColorAttachments = NULL;
19699 subpass.pResolveAttachments = NULL;
19700 subpass.pDepthStencilAttachment = &ref;
19701 subpass.preserveAttachmentCount = 0;
19702 subpass.pPreserveAttachments = NULL;
19703
19704 VkRenderPass rp;
19705 VkRenderPassCreateInfo rp_info = {};
19706 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19707 rp_info.attachmentCount = 1;
19708 rp_info.pAttachments = &att;
19709 rp_info.subpassCount = 1;
19710 rp_info.pSubpasses = &subpass;
19711 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19712 ASSERT_VK_SUCCESS(result);
19713
19714 VkImageView *depthView = m_depthStencil->BindInfo();
19715 VkFramebufferCreateInfo fb_info = {};
19716 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19717 fb_info.pNext = NULL;
19718 fb_info.renderPass = rp;
19719 fb_info.attachmentCount = 1;
19720 fb_info.pAttachments = depthView;
19721 fb_info.width = 100;
19722 fb_info.height = 100;
19723 fb_info.layers = 1;
19724 VkFramebuffer fb;
19725 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19726 ASSERT_VK_SUCCESS(result);
19727
19728 VkRenderPassBeginInfo rpbinfo = {};
19729 rpbinfo.clearValueCount = 1;
19730 rpbinfo.pClearValues = &clear;
19731 rpbinfo.pNext = NULL;
19732 rpbinfo.renderPass = rp;
19733 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19734 rpbinfo.renderArea.extent.width = 100;
19735 rpbinfo.renderArea.extent.height = 100;
19736 rpbinfo.renderArea.offset.x = 0;
19737 rpbinfo.renderArea.offset.y = 0;
19738 rpbinfo.framebuffer = fb;
19739
19740 VkFence fence = {};
19741 VkFenceCreateInfo fence_ci = {};
19742 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19743 fence_ci.pNext = nullptr;
19744 fence_ci.flags = 0;
19745 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19746 ASSERT_VK_SUCCESS(result);
19747
19748 m_commandBuffer->BeginCommandBuffer();
19749 m_commandBuffer->BeginRenderPass(rpbinfo);
19750 m_commandBuffer->EndRenderPass();
19751 m_commandBuffer->EndCommandBuffer();
19752 m_commandBuffer->QueueCommandBuffer(fence);
19753
19754 VkImageObj destImage(m_device);
19755 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 -070019756 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019757 VkImageMemoryBarrier barrier = {};
19758 VkImageSubresourceRange range;
19759 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19760 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19761 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19762 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19763 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19764 barrier.image = m_depthStencil->handle();
19765 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19766 range.baseMipLevel = 0;
19767 range.levelCount = 1;
19768 range.baseArrayLayer = 0;
19769 range.layerCount = 1;
19770 barrier.subresourceRange = range;
19771 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19772 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19773 cmdbuf.BeginCommandBuffer();
19774 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 -070019775 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019776 barrier.srcAccessMask = 0;
19777 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19778 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19779 barrier.image = destImage.handle();
19780 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19781 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 -070019782 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019783 VkImageCopy cregion;
19784 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19785 cregion.srcSubresource.mipLevel = 0;
19786 cregion.srcSubresource.baseArrayLayer = 0;
19787 cregion.srcSubresource.layerCount = 1;
19788 cregion.srcOffset.x = 0;
19789 cregion.srcOffset.y = 0;
19790 cregion.srcOffset.z = 0;
19791 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19792 cregion.dstSubresource.mipLevel = 0;
19793 cregion.dstSubresource.baseArrayLayer = 0;
19794 cregion.dstSubresource.layerCount = 1;
19795 cregion.dstOffset.x = 0;
19796 cregion.dstOffset.y = 0;
19797 cregion.dstOffset.z = 0;
19798 cregion.extent.width = 100;
19799 cregion.extent.height = 100;
19800 cregion.extent.depth = 1;
19801 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019802 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019803 cmdbuf.EndCommandBuffer();
19804
19805 VkSubmitInfo submit_info;
19806 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19807 submit_info.pNext = NULL;
19808 submit_info.waitSemaphoreCount = 0;
19809 submit_info.pWaitSemaphores = NULL;
19810 submit_info.pWaitDstStageMask = NULL;
19811 submit_info.commandBufferCount = 1;
19812 submit_info.pCommandBuffers = &cmdbuf.handle();
19813 submit_info.signalSemaphoreCount = 0;
19814 submit_info.pSignalSemaphores = NULL;
19815
19816 m_errorMonitor->ExpectSuccess();
19817 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19818 m_errorMonitor->VerifyNotFound();
19819
19820 vkQueueWaitIdle(m_device->m_queue);
19821 vkDestroyFence(m_device->device(), fence, nullptr);
19822 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19823 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19824}
19825
19826// This is a positive test. No errors should be generated.
19827TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19828 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19829
19830 m_errorMonitor->ExpectSuccess();
19831 ASSERT_NO_FATAL_FAILURE(InitState());
19832
19833 VkEvent event;
19834 VkEventCreateInfo event_create_info{};
19835 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19836 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19837
19838 VkCommandPool command_pool;
19839 VkCommandPoolCreateInfo pool_create_info{};
19840 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19841 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19842 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19843 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19844
19845 VkCommandBuffer command_buffer;
19846 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19847 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19848 command_buffer_allocate_info.commandPool = command_pool;
19849 command_buffer_allocate_info.commandBufferCount = 1;
19850 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19851 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19852
19853 VkQueue queue = VK_NULL_HANDLE;
19854 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19855
19856 {
19857 VkCommandBufferBeginInfo begin_info{};
19858 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19859 vkBeginCommandBuffer(command_buffer, &begin_info);
19860
19861 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 -070019862 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019863 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19864 vkEndCommandBuffer(command_buffer);
19865 }
19866 {
19867 VkSubmitInfo submit_info{};
19868 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19869 submit_info.commandBufferCount = 1;
19870 submit_info.pCommandBuffers = &command_buffer;
19871 submit_info.signalSemaphoreCount = 0;
19872 submit_info.pSignalSemaphores = nullptr;
19873 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19874 }
19875 { vkSetEvent(m_device->device(), event); }
19876
19877 vkQueueWaitIdle(queue);
19878
19879 vkDestroyEvent(m_device->device(), event, nullptr);
19880 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19881 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19882
19883 m_errorMonitor->VerifyNotFound();
19884}
19885// This is a positive test. No errors should be generated.
19886TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19887 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19888
19889 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019890 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019891
19892 m_errorMonitor->ExpectSuccess();
19893
19894 VkQueryPool query_pool;
19895 VkQueryPoolCreateInfo query_pool_create_info{};
19896 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19897 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19898 query_pool_create_info.queryCount = 1;
19899 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19900
19901 VkCommandPool command_pool;
19902 VkCommandPoolCreateInfo pool_create_info{};
19903 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19904 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19905 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19906 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19907
19908 VkCommandBuffer command_buffer;
19909 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19910 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19911 command_buffer_allocate_info.commandPool = command_pool;
19912 command_buffer_allocate_info.commandBufferCount = 1;
19913 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19914 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19915
19916 VkCommandBuffer secondary_command_buffer;
19917 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19918 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
19919
19920 VkQueue queue = VK_NULL_HANDLE;
19921 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19922
19923 uint32_t qfi = 0;
19924 VkBufferCreateInfo buff_create_info = {};
19925 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19926 buff_create_info.size = 1024;
19927 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19928 buff_create_info.queueFamilyIndexCount = 1;
19929 buff_create_info.pQueueFamilyIndices = &qfi;
19930
19931 VkResult err;
19932 VkBuffer buffer;
19933 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19934 ASSERT_VK_SUCCESS(err);
19935 VkMemoryAllocateInfo mem_alloc = {};
19936 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19937 mem_alloc.pNext = NULL;
19938 mem_alloc.allocationSize = 1024;
19939 mem_alloc.memoryTypeIndex = 0;
19940
19941 VkMemoryRequirements memReqs;
19942 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19943 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19944 if (!pass) {
19945 vkDestroyBuffer(m_device->device(), buffer, NULL);
19946 return;
19947 }
19948
19949 VkDeviceMemory mem;
19950 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19951 ASSERT_VK_SUCCESS(err);
19952 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19953 ASSERT_VK_SUCCESS(err);
19954
19955 VkCommandBufferInheritanceInfo hinfo = {};
19956 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19957 hinfo.renderPass = VK_NULL_HANDLE;
19958 hinfo.subpass = 0;
19959 hinfo.framebuffer = VK_NULL_HANDLE;
19960 hinfo.occlusionQueryEnable = VK_FALSE;
19961 hinfo.queryFlags = 0;
19962 hinfo.pipelineStatistics = 0;
19963
19964 {
19965 VkCommandBufferBeginInfo begin_info{};
19966 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19967 begin_info.pInheritanceInfo = &hinfo;
19968 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
19969
19970 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
19971 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19972
19973 vkEndCommandBuffer(secondary_command_buffer);
19974
19975 begin_info.pInheritanceInfo = nullptr;
19976 vkBeginCommandBuffer(command_buffer, &begin_info);
19977
19978 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
19979 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
19980
19981 vkEndCommandBuffer(command_buffer);
19982 }
19983 {
19984 VkSubmitInfo submit_info{};
19985 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19986 submit_info.commandBufferCount = 1;
19987 submit_info.pCommandBuffers = &command_buffer;
19988 submit_info.signalSemaphoreCount = 0;
19989 submit_info.pSignalSemaphores = nullptr;
19990 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19991 }
19992
19993 vkQueueWaitIdle(queue);
19994
19995 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19996 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19997 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
19998 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19999 vkDestroyBuffer(m_device->device(), buffer, NULL);
20000 vkFreeMemory(m_device->device(), mem, NULL);
20001
20002 m_errorMonitor->VerifyNotFound();
20003}
20004
20005// This is a positive test. No errors should be generated.
20006TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20007 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20008
20009 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020010 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020011
20012 m_errorMonitor->ExpectSuccess();
20013
20014 VkQueryPool query_pool;
20015 VkQueryPoolCreateInfo query_pool_create_info{};
20016 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20017 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20018 query_pool_create_info.queryCount = 1;
20019 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20020
20021 VkCommandPool command_pool;
20022 VkCommandPoolCreateInfo pool_create_info{};
20023 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20024 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20025 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20026 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20027
20028 VkCommandBuffer command_buffer[2];
20029 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20030 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20031 command_buffer_allocate_info.commandPool = command_pool;
20032 command_buffer_allocate_info.commandBufferCount = 2;
20033 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20034 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20035
20036 VkQueue queue = VK_NULL_HANDLE;
20037 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20038
20039 uint32_t qfi = 0;
20040 VkBufferCreateInfo buff_create_info = {};
20041 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20042 buff_create_info.size = 1024;
20043 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20044 buff_create_info.queueFamilyIndexCount = 1;
20045 buff_create_info.pQueueFamilyIndices = &qfi;
20046
20047 VkResult err;
20048 VkBuffer buffer;
20049 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20050 ASSERT_VK_SUCCESS(err);
20051 VkMemoryAllocateInfo mem_alloc = {};
20052 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20053 mem_alloc.pNext = NULL;
20054 mem_alloc.allocationSize = 1024;
20055 mem_alloc.memoryTypeIndex = 0;
20056
20057 VkMemoryRequirements memReqs;
20058 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20059 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20060 if (!pass) {
20061 vkDestroyBuffer(m_device->device(), buffer, NULL);
20062 return;
20063 }
20064
20065 VkDeviceMemory mem;
20066 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20067 ASSERT_VK_SUCCESS(err);
20068 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20069 ASSERT_VK_SUCCESS(err);
20070
20071 {
20072 VkCommandBufferBeginInfo begin_info{};
20073 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20074 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20075
20076 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20077 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20078
20079 vkEndCommandBuffer(command_buffer[0]);
20080
20081 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20082
20083 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20084
20085 vkEndCommandBuffer(command_buffer[1]);
20086 }
20087 {
20088 VkSubmitInfo submit_info{};
20089 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20090 submit_info.commandBufferCount = 2;
20091 submit_info.pCommandBuffers = command_buffer;
20092 submit_info.signalSemaphoreCount = 0;
20093 submit_info.pSignalSemaphores = nullptr;
20094 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20095 }
20096
20097 vkQueueWaitIdle(queue);
20098
20099 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20100 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20101 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20102 vkDestroyBuffer(m_device->device(), buffer, NULL);
20103 vkFreeMemory(m_device->device(), mem, NULL);
20104
20105 m_errorMonitor->VerifyNotFound();
20106}
20107
Tony Barbourc46924f2016-11-04 11:49:52 -060020108TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020109 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20110
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020111 ASSERT_NO_FATAL_FAILURE(InitState());
20112 VkEvent event;
20113 VkEventCreateInfo event_create_info{};
20114 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20115 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20116
20117 VkCommandPool command_pool;
20118 VkCommandPoolCreateInfo pool_create_info{};
20119 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20120 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20121 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20123
20124 VkCommandBuffer command_buffer;
20125 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20126 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20127 command_buffer_allocate_info.commandPool = command_pool;
20128 command_buffer_allocate_info.commandBufferCount = 1;
20129 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20130 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20131
20132 VkQueue queue = VK_NULL_HANDLE;
20133 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20134
20135 {
20136 VkCommandBufferBeginInfo begin_info{};
20137 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20138 vkBeginCommandBuffer(command_buffer, &begin_info);
20139
20140 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020141 vkEndCommandBuffer(command_buffer);
20142 }
20143 {
20144 VkSubmitInfo submit_info{};
20145 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20146 submit_info.commandBufferCount = 1;
20147 submit_info.pCommandBuffers = &command_buffer;
20148 submit_info.signalSemaphoreCount = 0;
20149 submit_info.pSignalSemaphores = nullptr;
20150 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20151 }
20152 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20154 "that is already in use by a "
20155 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020156 vkSetEvent(m_device->device(), event);
20157 m_errorMonitor->VerifyFound();
20158 }
20159
20160 vkQueueWaitIdle(queue);
20161
20162 vkDestroyEvent(m_device->device(), event, nullptr);
20163 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20164 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20165}
20166
20167// This is a positive test. No errors should be generated.
20168TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020169 TEST_DESCRIPTION(
20170 "Two command buffers with two separate fences are each "
20171 "run through a Submit & WaitForFences cycle 3 times. This "
20172 "previously revealed a bug so running this positive test "
20173 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020174 m_errorMonitor->ExpectSuccess();
20175
20176 ASSERT_NO_FATAL_FAILURE(InitState());
20177 VkQueue queue = VK_NULL_HANDLE;
20178 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20179
20180 static const uint32_t NUM_OBJECTS = 2;
20181 static const uint32_t NUM_FRAMES = 3;
20182 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20183 VkFence fences[NUM_OBJECTS] = {};
20184
20185 VkCommandPool cmd_pool;
20186 VkCommandPoolCreateInfo cmd_pool_ci = {};
20187 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20188 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20189 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20190 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20191 ASSERT_VK_SUCCESS(err);
20192
20193 VkCommandBufferAllocateInfo cmd_buf_info = {};
20194 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20195 cmd_buf_info.commandPool = cmd_pool;
20196 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20197 cmd_buf_info.commandBufferCount = 1;
20198
20199 VkFenceCreateInfo fence_ci = {};
20200 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20201 fence_ci.pNext = nullptr;
20202 fence_ci.flags = 0;
20203
20204 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20205 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20206 ASSERT_VK_SUCCESS(err);
20207 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20208 ASSERT_VK_SUCCESS(err);
20209 }
20210
20211 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20212 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20213 // Create empty cmd buffer
20214 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20215 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20216
20217 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20218 ASSERT_VK_SUCCESS(err);
20219 err = vkEndCommandBuffer(cmd_buffers[obj]);
20220 ASSERT_VK_SUCCESS(err);
20221
20222 VkSubmitInfo submit_info = {};
20223 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20224 submit_info.commandBufferCount = 1;
20225 submit_info.pCommandBuffers = &cmd_buffers[obj];
20226 // Submit cmd buffer and wait for fence
20227 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20228 ASSERT_VK_SUCCESS(err);
20229 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20230 ASSERT_VK_SUCCESS(err);
20231 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20232 ASSERT_VK_SUCCESS(err);
20233 }
20234 }
20235 m_errorMonitor->VerifyNotFound();
20236 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20237 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20238 vkDestroyFence(m_device->device(), fences[i], nullptr);
20239 }
20240}
20241// This is a positive test. No errors should be generated.
20242TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020243 TEST_DESCRIPTION(
20244 "Two command buffers, each in a separate QueueSubmit call "
20245 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020246
20247 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020248 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020249
20250 m_errorMonitor->ExpectSuccess();
20251
20252 VkSemaphore semaphore;
20253 VkSemaphoreCreateInfo semaphore_create_info{};
20254 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20255 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20256
20257 VkCommandPool command_pool;
20258 VkCommandPoolCreateInfo pool_create_info{};
20259 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20260 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20261 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20262 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20263
20264 VkCommandBuffer command_buffer[2];
20265 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20266 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20267 command_buffer_allocate_info.commandPool = command_pool;
20268 command_buffer_allocate_info.commandBufferCount = 2;
20269 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20270 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20271
20272 VkQueue queue = VK_NULL_HANDLE;
20273 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20274
20275 {
20276 VkCommandBufferBeginInfo begin_info{};
20277 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20278 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20279
20280 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 -070020281 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020282
20283 VkViewport viewport{};
20284 viewport.maxDepth = 1.0f;
20285 viewport.minDepth = 0.0f;
20286 viewport.width = 512;
20287 viewport.height = 512;
20288 viewport.x = 0;
20289 viewport.y = 0;
20290 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20291 vkEndCommandBuffer(command_buffer[0]);
20292 }
20293 {
20294 VkCommandBufferBeginInfo begin_info{};
20295 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20296 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20297
20298 VkViewport viewport{};
20299 viewport.maxDepth = 1.0f;
20300 viewport.minDepth = 0.0f;
20301 viewport.width = 512;
20302 viewport.height = 512;
20303 viewport.x = 0;
20304 viewport.y = 0;
20305 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20306 vkEndCommandBuffer(command_buffer[1]);
20307 }
20308 {
20309 VkSubmitInfo submit_info{};
20310 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20311 submit_info.commandBufferCount = 1;
20312 submit_info.pCommandBuffers = &command_buffer[0];
20313 submit_info.signalSemaphoreCount = 1;
20314 submit_info.pSignalSemaphores = &semaphore;
20315 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20316 }
20317 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020318 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020319 VkSubmitInfo submit_info{};
20320 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20321 submit_info.commandBufferCount = 1;
20322 submit_info.pCommandBuffers = &command_buffer[1];
20323 submit_info.waitSemaphoreCount = 1;
20324 submit_info.pWaitSemaphores = &semaphore;
20325 submit_info.pWaitDstStageMask = flags;
20326 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20327 }
20328
20329 vkQueueWaitIdle(m_device->m_queue);
20330
20331 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20332 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20333 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20334
20335 m_errorMonitor->VerifyNotFound();
20336}
20337
20338// This is a positive test. No errors should be generated.
20339TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020340 TEST_DESCRIPTION(
20341 "Two command buffers, each in a separate QueueSubmit call "
20342 "submitted on separate queues, the second having a fence"
20343 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020344
20345 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020346 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020347
20348 m_errorMonitor->ExpectSuccess();
20349
20350 VkFence fence;
20351 VkFenceCreateInfo fence_create_info{};
20352 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20353 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20354
20355 VkSemaphore semaphore;
20356 VkSemaphoreCreateInfo semaphore_create_info{};
20357 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20358 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20359
20360 VkCommandPool command_pool;
20361 VkCommandPoolCreateInfo pool_create_info{};
20362 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20363 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20364 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20365 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20366
20367 VkCommandBuffer command_buffer[2];
20368 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20369 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20370 command_buffer_allocate_info.commandPool = command_pool;
20371 command_buffer_allocate_info.commandBufferCount = 2;
20372 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20373 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20374
20375 VkQueue queue = VK_NULL_HANDLE;
20376 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20377
20378 {
20379 VkCommandBufferBeginInfo begin_info{};
20380 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20381 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20382
20383 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 -070020384 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020385
20386 VkViewport viewport{};
20387 viewport.maxDepth = 1.0f;
20388 viewport.minDepth = 0.0f;
20389 viewport.width = 512;
20390 viewport.height = 512;
20391 viewport.x = 0;
20392 viewport.y = 0;
20393 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20394 vkEndCommandBuffer(command_buffer[0]);
20395 }
20396 {
20397 VkCommandBufferBeginInfo begin_info{};
20398 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20399 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20400
20401 VkViewport viewport{};
20402 viewport.maxDepth = 1.0f;
20403 viewport.minDepth = 0.0f;
20404 viewport.width = 512;
20405 viewport.height = 512;
20406 viewport.x = 0;
20407 viewport.y = 0;
20408 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20409 vkEndCommandBuffer(command_buffer[1]);
20410 }
20411 {
20412 VkSubmitInfo submit_info{};
20413 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20414 submit_info.commandBufferCount = 1;
20415 submit_info.pCommandBuffers = &command_buffer[0];
20416 submit_info.signalSemaphoreCount = 1;
20417 submit_info.pSignalSemaphores = &semaphore;
20418 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20419 }
20420 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020421 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020422 VkSubmitInfo submit_info{};
20423 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20424 submit_info.commandBufferCount = 1;
20425 submit_info.pCommandBuffers = &command_buffer[1];
20426 submit_info.waitSemaphoreCount = 1;
20427 submit_info.pWaitSemaphores = &semaphore;
20428 submit_info.pWaitDstStageMask = flags;
20429 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20430 }
20431
20432 vkQueueWaitIdle(m_device->m_queue);
20433
20434 vkDestroyFence(m_device->device(), fence, nullptr);
20435 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20436 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20437 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20438
20439 m_errorMonitor->VerifyNotFound();
20440}
20441
20442// This is a positive test. No errors should be generated.
20443TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020444 TEST_DESCRIPTION(
20445 "Two command buffers, each in a separate QueueSubmit call "
20446 "submitted on separate queues, the second having a fence"
20447 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020448
20449 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020450 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020451
20452 m_errorMonitor->ExpectSuccess();
20453
20454 VkFence fence;
20455 VkFenceCreateInfo fence_create_info{};
20456 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20457 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20458
20459 VkSemaphore semaphore;
20460 VkSemaphoreCreateInfo semaphore_create_info{};
20461 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20462 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20463
20464 VkCommandPool command_pool;
20465 VkCommandPoolCreateInfo pool_create_info{};
20466 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20467 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20468 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20469 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20470
20471 VkCommandBuffer command_buffer[2];
20472 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20473 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20474 command_buffer_allocate_info.commandPool = command_pool;
20475 command_buffer_allocate_info.commandBufferCount = 2;
20476 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20477 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20478
20479 VkQueue queue = VK_NULL_HANDLE;
20480 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20481
20482 {
20483 VkCommandBufferBeginInfo begin_info{};
20484 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20485 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20486
20487 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 -070020488 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020489
20490 VkViewport viewport{};
20491 viewport.maxDepth = 1.0f;
20492 viewport.minDepth = 0.0f;
20493 viewport.width = 512;
20494 viewport.height = 512;
20495 viewport.x = 0;
20496 viewport.y = 0;
20497 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20498 vkEndCommandBuffer(command_buffer[0]);
20499 }
20500 {
20501 VkCommandBufferBeginInfo begin_info{};
20502 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20503 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20504
20505 VkViewport viewport{};
20506 viewport.maxDepth = 1.0f;
20507 viewport.minDepth = 0.0f;
20508 viewport.width = 512;
20509 viewport.height = 512;
20510 viewport.x = 0;
20511 viewport.y = 0;
20512 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20513 vkEndCommandBuffer(command_buffer[1]);
20514 }
20515 {
20516 VkSubmitInfo submit_info{};
20517 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20518 submit_info.commandBufferCount = 1;
20519 submit_info.pCommandBuffers = &command_buffer[0];
20520 submit_info.signalSemaphoreCount = 1;
20521 submit_info.pSignalSemaphores = &semaphore;
20522 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20523 }
20524 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020525 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020526 VkSubmitInfo submit_info{};
20527 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20528 submit_info.commandBufferCount = 1;
20529 submit_info.pCommandBuffers = &command_buffer[1];
20530 submit_info.waitSemaphoreCount = 1;
20531 submit_info.pWaitSemaphores = &semaphore;
20532 submit_info.pWaitDstStageMask = flags;
20533 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20534 }
20535
20536 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
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
20547TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020548 ASSERT_NO_FATAL_FAILURE(InitState());
20549 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020550 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020551 return;
20552 }
20553
20554 VkResult err;
20555
20556 m_errorMonitor->ExpectSuccess();
20557
20558 VkQueue q0 = m_device->m_queue;
20559 VkQueue q1 = nullptr;
20560 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20561 ASSERT_NE(q1, nullptr);
20562
20563 // An (empty) command buffer. We must have work in the first submission --
20564 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020565 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020566 VkCommandPool pool;
20567 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20568 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020569 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20570 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020571 VkCommandBuffer cb;
20572 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20573 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020574 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020575 err = vkBeginCommandBuffer(cb, &cbbi);
20576 ASSERT_VK_SUCCESS(err);
20577 err = vkEndCommandBuffer(cb);
20578 ASSERT_VK_SUCCESS(err);
20579
20580 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020581 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020582 VkSemaphore s;
20583 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20584 ASSERT_VK_SUCCESS(err);
20585
20586 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020587 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020588
20589 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20590 ASSERT_VK_SUCCESS(err);
20591
20592 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020593 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020594 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020595
20596 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20597 ASSERT_VK_SUCCESS(err);
20598
20599 // Wait for q0 idle
20600 err = vkQueueWaitIdle(q0);
20601 ASSERT_VK_SUCCESS(err);
20602
20603 // Command buffer should have been completed (it was on q0); reset the pool.
20604 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20605
20606 m_errorMonitor->VerifyNotFound();
20607
20608 // Force device completely idle and clean up resources
20609 vkDeviceWaitIdle(m_device->device());
20610 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20611 vkDestroySemaphore(m_device->device(), s, nullptr);
20612}
20613
20614// This is a positive test. No errors should be generated.
20615TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020616 TEST_DESCRIPTION(
20617 "Two command buffers, each in a separate QueueSubmit call "
20618 "submitted on separate queues, the second having a fence, "
20619 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020620
20621 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020622 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020623
20624 m_errorMonitor->ExpectSuccess();
20625
20626 ASSERT_NO_FATAL_FAILURE(InitState());
20627 VkFence fence;
20628 VkFenceCreateInfo fence_create_info{};
20629 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20630 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20631
20632 VkSemaphore semaphore;
20633 VkSemaphoreCreateInfo semaphore_create_info{};
20634 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20635 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20636
20637 VkCommandPool command_pool;
20638 VkCommandPoolCreateInfo pool_create_info{};
20639 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20640 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20641 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20642 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20643
20644 VkCommandBuffer command_buffer[2];
20645 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20646 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20647 command_buffer_allocate_info.commandPool = command_pool;
20648 command_buffer_allocate_info.commandBufferCount = 2;
20649 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20650 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20651
20652 VkQueue queue = VK_NULL_HANDLE;
20653 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20654
20655 {
20656 VkCommandBufferBeginInfo begin_info{};
20657 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20658 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20659
20660 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 -070020661 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020662
20663 VkViewport viewport{};
20664 viewport.maxDepth = 1.0f;
20665 viewport.minDepth = 0.0f;
20666 viewport.width = 512;
20667 viewport.height = 512;
20668 viewport.x = 0;
20669 viewport.y = 0;
20670 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20671 vkEndCommandBuffer(command_buffer[0]);
20672 }
20673 {
20674 VkCommandBufferBeginInfo begin_info{};
20675 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20676 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20677
20678 VkViewport viewport{};
20679 viewport.maxDepth = 1.0f;
20680 viewport.minDepth = 0.0f;
20681 viewport.width = 512;
20682 viewport.height = 512;
20683 viewport.x = 0;
20684 viewport.y = 0;
20685 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20686 vkEndCommandBuffer(command_buffer[1]);
20687 }
20688 {
20689 VkSubmitInfo submit_info{};
20690 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20691 submit_info.commandBufferCount = 1;
20692 submit_info.pCommandBuffers = &command_buffer[0];
20693 submit_info.signalSemaphoreCount = 1;
20694 submit_info.pSignalSemaphores = &semaphore;
20695 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20696 }
20697 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020698 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020699 VkSubmitInfo submit_info{};
20700 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20701 submit_info.commandBufferCount = 1;
20702 submit_info.pCommandBuffers = &command_buffer[1];
20703 submit_info.waitSemaphoreCount = 1;
20704 submit_info.pWaitSemaphores = &semaphore;
20705 submit_info.pWaitDstStageMask = flags;
20706 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20707 }
20708
20709 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20710
20711 vkDestroyFence(m_device->device(), fence, nullptr);
20712 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20713 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20714 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20715
20716 m_errorMonitor->VerifyNotFound();
20717}
20718
20719// This is a positive test. No errors should be generated.
20720TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020721 TEST_DESCRIPTION(
20722 "Two command buffers, each in a separate QueueSubmit call "
20723 "on the same queue, sharing a signal/wait semaphore, the "
20724 "second having a fence, "
20725 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020726
20727 m_errorMonitor->ExpectSuccess();
20728
20729 ASSERT_NO_FATAL_FAILURE(InitState());
20730 VkFence fence;
20731 VkFenceCreateInfo fence_create_info{};
20732 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20733 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20734
20735 VkSemaphore semaphore;
20736 VkSemaphoreCreateInfo semaphore_create_info{};
20737 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20738 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20739
20740 VkCommandPool command_pool;
20741 VkCommandPoolCreateInfo pool_create_info{};
20742 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20743 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20744 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20745 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20746
20747 VkCommandBuffer command_buffer[2];
20748 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20749 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20750 command_buffer_allocate_info.commandPool = command_pool;
20751 command_buffer_allocate_info.commandBufferCount = 2;
20752 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20753 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20754
20755 {
20756 VkCommandBufferBeginInfo begin_info{};
20757 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20758 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20759
20760 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 -070020761 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020762
20763 VkViewport viewport{};
20764 viewport.maxDepth = 1.0f;
20765 viewport.minDepth = 0.0f;
20766 viewport.width = 512;
20767 viewport.height = 512;
20768 viewport.x = 0;
20769 viewport.y = 0;
20770 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20771 vkEndCommandBuffer(command_buffer[0]);
20772 }
20773 {
20774 VkCommandBufferBeginInfo begin_info{};
20775 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20776 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20777
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[1], 0, 1, &viewport);
20786 vkEndCommandBuffer(command_buffer[1]);
20787 }
20788 {
20789 VkSubmitInfo submit_info{};
20790 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20791 submit_info.commandBufferCount = 1;
20792 submit_info.pCommandBuffers = &command_buffer[0];
20793 submit_info.signalSemaphoreCount = 1;
20794 submit_info.pSignalSemaphores = &semaphore;
20795 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20796 }
20797 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020798 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020799 VkSubmitInfo submit_info{};
20800 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20801 submit_info.commandBufferCount = 1;
20802 submit_info.pCommandBuffers = &command_buffer[1];
20803 submit_info.waitSemaphoreCount = 1;
20804 submit_info.pWaitSemaphores = &semaphore;
20805 submit_info.pWaitDstStageMask = flags;
20806 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20807 }
20808
20809 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20810
20811 vkDestroyFence(m_device->device(), fence, nullptr);
20812 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20813 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20814 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20815
20816 m_errorMonitor->VerifyNotFound();
20817}
20818
20819// This is a positive test. No errors should be generated.
20820TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020821 TEST_DESCRIPTION(
20822 "Two command buffers, each in a separate QueueSubmit call "
20823 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20824 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020825
20826 m_errorMonitor->ExpectSuccess();
20827
20828 ASSERT_NO_FATAL_FAILURE(InitState());
20829 VkFence fence;
20830 VkFenceCreateInfo fence_create_info{};
20831 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20832 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20833
20834 VkCommandPool command_pool;
20835 VkCommandPoolCreateInfo pool_create_info{};
20836 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20837 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20838 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20839 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20840
20841 VkCommandBuffer command_buffer[2];
20842 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20843 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20844 command_buffer_allocate_info.commandPool = command_pool;
20845 command_buffer_allocate_info.commandBufferCount = 2;
20846 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20847 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20848
20849 {
20850 VkCommandBufferBeginInfo begin_info{};
20851 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20852 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20853
20854 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 -070020855 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020856
20857 VkViewport viewport{};
20858 viewport.maxDepth = 1.0f;
20859 viewport.minDepth = 0.0f;
20860 viewport.width = 512;
20861 viewport.height = 512;
20862 viewport.x = 0;
20863 viewport.y = 0;
20864 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20865 vkEndCommandBuffer(command_buffer[0]);
20866 }
20867 {
20868 VkCommandBufferBeginInfo begin_info{};
20869 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20870 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20871
20872 VkViewport viewport{};
20873 viewport.maxDepth = 1.0f;
20874 viewport.minDepth = 0.0f;
20875 viewport.width = 512;
20876 viewport.height = 512;
20877 viewport.x = 0;
20878 viewport.y = 0;
20879 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20880 vkEndCommandBuffer(command_buffer[1]);
20881 }
20882 {
20883 VkSubmitInfo submit_info{};
20884 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20885 submit_info.commandBufferCount = 1;
20886 submit_info.pCommandBuffers = &command_buffer[0];
20887 submit_info.signalSemaphoreCount = 0;
20888 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20889 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20890 }
20891 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020892 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020893 VkSubmitInfo submit_info{};
20894 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20895 submit_info.commandBufferCount = 1;
20896 submit_info.pCommandBuffers = &command_buffer[1];
20897 submit_info.waitSemaphoreCount = 0;
20898 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20899 submit_info.pWaitDstStageMask = flags;
20900 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20901 }
20902
20903 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20904
20905 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20906 ASSERT_VK_SUCCESS(err);
20907
20908 vkDestroyFence(m_device->device(), fence, nullptr);
20909 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20910 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20911
20912 m_errorMonitor->VerifyNotFound();
20913}
20914
20915// This is a positive test. No errors should be generated.
20916TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020917 TEST_DESCRIPTION(
20918 "Two command buffers, each in a separate QueueSubmit call "
20919 "on the same queue, the second having a fence, followed "
20920 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020921
20922 m_errorMonitor->ExpectSuccess();
20923
20924 ASSERT_NO_FATAL_FAILURE(InitState());
20925 VkFence fence;
20926 VkFenceCreateInfo fence_create_info{};
20927 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20928 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20929
20930 VkCommandPool command_pool;
20931 VkCommandPoolCreateInfo pool_create_info{};
20932 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20933 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20934 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20935 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20936
20937 VkCommandBuffer command_buffer[2];
20938 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20939 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20940 command_buffer_allocate_info.commandPool = command_pool;
20941 command_buffer_allocate_info.commandBufferCount = 2;
20942 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20943 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20944
20945 {
20946 VkCommandBufferBeginInfo begin_info{};
20947 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20948 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20949
20950 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 -070020951 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020952
20953 VkViewport viewport{};
20954 viewport.maxDepth = 1.0f;
20955 viewport.minDepth = 0.0f;
20956 viewport.width = 512;
20957 viewport.height = 512;
20958 viewport.x = 0;
20959 viewport.y = 0;
20960 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20961 vkEndCommandBuffer(command_buffer[0]);
20962 }
20963 {
20964 VkCommandBufferBeginInfo begin_info{};
20965 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20966 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20967
20968 VkViewport viewport{};
20969 viewport.maxDepth = 1.0f;
20970 viewport.minDepth = 0.0f;
20971 viewport.width = 512;
20972 viewport.height = 512;
20973 viewport.x = 0;
20974 viewport.y = 0;
20975 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20976 vkEndCommandBuffer(command_buffer[1]);
20977 }
20978 {
20979 VkSubmitInfo submit_info{};
20980 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20981 submit_info.commandBufferCount = 1;
20982 submit_info.pCommandBuffers = &command_buffer[0];
20983 submit_info.signalSemaphoreCount = 0;
20984 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20985 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20986 }
20987 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020988 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020989 VkSubmitInfo submit_info{};
20990 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20991 submit_info.commandBufferCount = 1;
20992 submit_info.pCommandBuffers = &command_buffer[1];
20993 submit_info.waitSemaphoreCount = 0;
20994 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20995 submit_info.pWaitDstStageMask = flags;
20996 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20997 }
20998
20999 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21000
21001 vkDestroyFence(m_device->device(), fence, nullptr);
21002 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21003 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21004
21005 m_errorMonitor->VerifyNotFound();
21006}
21007
21008// This is a positive test. No errors should be generated.
21009TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021010 TEST_DESCRIPTION(
21011 "Two command buffers each in a separate SubmitInfo sent in a single "
21012 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021013 ASSERT_NO_FATAL_FAILURE(InitState());
21014
21015 m_errorMonitor->ExpectSuccess();
21016
21017 VkFence fence;
21018 VkFenceCreateInfo fence_create_info{};
21019 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21020 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21021
21022 VkSemaphore semaphore;
21023 VkSemaphoreCreateInfo semaphore_create_info{};
21024 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21025 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21026
21027 VkCommandPool command_pool;
21028 VkCommandPoolCreateInfo pool_create_info{};
21029 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21030 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21031 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21032 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21033
21034 VkCommandBuffer command_buffer[2];
21035 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21036 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21037 command_buffer_allocate_info.commandPool = command_pool;
21038 command_buffer_allocate_info.commandBufferCount = 2;
21039 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21040 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21041
21042 {
21043 VkCommandBufferBeginInfo begin_info{};
21044 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21045 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21046
21047 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 -070021048 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021049
21050 VkViewport viewport{};
21051 viewport.maxDepth = 1.0f;
21052 viewport.minDepth = 0.0f;
21053 viewport.width = 512;
21054 viewport.height = 512;
21055 viewport.x = 0;
21056 viewport.y = 0;
21057 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21058 vkEndCommandBuffer(command_buffer[0]);
21059 }
21060 {
21061 VkCommandBufferBeginInfo begin_info{};
21062 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21063 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21064
21065 VkViewport viewport{};
21066 viewport.maxDepth = 1.0f;
21067 viewport.minDepth = 0.0f;
21068 viewport.width = 512;
21069 viewport.height = 512;
21070 viewport.x = 0;
21071 viewport.y = 0;
21072 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21073 vkEndCommandBuffer(command_buffer[1]);
21074 }
21075 {
21076 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021077 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021078
21079 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21080 submit_info[0].pNext = NULL;
21081 submit_info[0].commandBufferCount = 1;
21082 submit_info[0].pCommandBuffers = &command_buffer[0];
21083 submit_info[0].signalSemaphoreCount = 1;
21084 submit_info[0].pSignalSemaphores = &semaphore;
21085 submit_info[0].waitSemaphoreCount = 0;
21086 submit_info[0].pWaitSemaphores = NULL;
21087 submit_info[0].pWaitDstStageMask = 0;
21088
21089 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21090 submit_info[1].pNext = NULL;
21091 submit_info[1].commandBufferCount = 1;
21092 submit_info[1].pCommandBuffers = &command_buffer[1];
21093 submit_info[1].waitSemaphoreCount = 1;
21094 submit_info[1].pWaitSemaphores = &semaphore;
21095 submit_info[1].pWaitDstStageMask = flags;
21096 submit_info[1].signalSemaphoreCount = 0;
21097 submit_info[1].pSignalSemaphores = NULL;
21098 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21099 }
21100
21101 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21102
21103 vkDestroyFence(m_device->device(), fence, nullptr);
21104 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21105 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21106 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21107
21108 m_errorMonitor->VerifyNotFound();
21109}
21110
21111TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21112 m_errorMonitor->ExpectSuccess();
21113
21114 ASSERT_NO_FATAL_FAILURE(InitState());
21115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21116
Tony Barbour552f6c02016-12-21 14:34:07 -070021117 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021118
21119 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21120 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21121 m_errorMonitor->VerifyNotFound();
21122 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21123 m_errorMonitor->VerifyNotFound();
21124 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21125 m_errorMonitor->VerifyNotFound();
21126
21127 m_commandBuffer->EndCommandBuffer();
21128 m_errorMonitor->VerifyNotFound();
21129}
21130
21131TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021132 TEST_DESCRIPTION(
21133 "Positive test where we create a renderpass with an "
21134 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21135 "has a valid layout, and a second subpass then uses a "
21136 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021137 m_errorMonitor->ExpectSuccess();
21138 ASSERT_NO_FATAL_FAILURE(InitState());
21139
21140 VkAttachmentReference attach[2] = {};
21141 attach[0].attachment = 0;
21142 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21143 attach[1].attachment = 0;
21144 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21145 VkSubpassDescription subpasses[2] = {};
21146 // First subpass clears DS attach on load
21147 subpasses[0].pDepthStencilAttachment = &attach[0];
21148 // 2nd subpass reads in DS as input attachment
21149 subpasses[1].inputAttachmentCount = 1;
21150 subpasses[1].pInputAttachments = &attach[1];
21151 VkAttachmentDescription attach_desc = {};
21152 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
21153 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21154 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21155 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21156 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21157 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21158 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21159 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21160 VkRenderPassCreateInfo rpci = {};
21161 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21162 rpci.attachmentCount = 1;
21163 rpci.pAttachments = &attach_desc;
21164 rpci.subpassCount = 2;
21165 rpci.pSubpasses = subpasses;
21166
21167 // Now create RenderPass and verify no errors
21168 VkRenderPass rp;
21169 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21170 m_errorMonitor->VerifyNotFound();
21171
21172 vkDestroyRenderPass(m_device->device(), rp, NULL);
21173}
21174
Tobin Ehlis01103de2017-02-16 13:22:47 -070021175TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21176 TEST_DESCRIPTION(
21177 "Create a render pass with depth-stencil attachment where layout transition "
21178 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21179 "transition has correctly occurred at queue submit time with no validation errors.");
21180
21181 VkFormat ds_format = VK_FORMAT_D24_UNORM_S8_UINT;
21182 VkImageFormatProperties format_props;
21183 vkGetPhysicalDeviceImageFormatProperties(gpu(), ds_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
21184 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21185 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
21186 printf("DS format VK_FORMAT_D24_UNORM_S8_UINT not supported, RenderPassDepthStencilLayoutTransition skipped.\n");
21187 return;
21188 }
21189
21190 m_errorMonitor->ExpectSuccess();
21191 ASSERT_NO_FATAL_FAILURE(InitState());
21192 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21193
21194 // A renderpass with one depth/stencil attachment.
21195 VkAttachmentDescription attachment = {0,
21196 ds_format,
21197 VK_SAMPLE_COUNT_1_BIT,
21198 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21199 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21200 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21201 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21202 VK_IMAGE_LAYOUT_UNDEFINED,
21203 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21204
21205 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21206
21207 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21208
21209 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21210
21211 VkRenderPass rp;
21212 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21213 ASSERT_VK_SUCCESS(err);
21214 // A compatible ds image.
21215 VkImageObj image(m_device);
21216 image.init(32, 32, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
21217 ASSERT_TRUE(image.initialized());
21218
21219 VkImageViewCreateInfo ivci = {
21220 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21221 nullptr,
21222 0,
21223 image.handle(),
21224 VK_IMAGE_VIEW_TYPE_2D,
21225 ds_format,
21226 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21227 VK_COMPONENT_SWIZZLE_IDENTITY},
21228 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21229 };
21230 VkImageView view;
21231 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21232 ASSERT_VK_SUCCESS(err);
21233
21234 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21235 VkFramebuffer fb;
21236 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21237 ASSERT_VK_SUCCESS(err);
21238
21239 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21240 m_commandBuffer->BeginCommandBuffer();
21241 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21242 vkCmdEndRenderPass(m_commandBuffer->handle());
21243 m_commandBuffer->EndCommandBuffer();
21244 QueueCommandBuffer(false);
21245 m_errorMonitor->VerifyNotFound();
21246
21247 // Cleanup
21248 vkDestroyImageView(m_device->device(), view, NULL);
21249 vkDestroyRenderPass(m_device->device(), rp, NULL);
21250 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21251}
21252
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021253TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021254 TEST_DESCRIPTION(
21255 "Test that pipeline validation accepts matrices passed "
21256 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021257 m_errorMonitor->ExpectSuccess();
21258
21259 ASSERT_NO_FATAL_FAILURE(InitState());
21260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21261
21262 VkVertexInputBindingDescription input_binding;
21263 memset(&input_binding, 0, sizeof(input_binding));
21264
21265 VkVertexInputAttributeDescription input_attribs[2];
21266 memset(input_attribs, 0, sizeof(input_attribs));
21267
21268 for (int i = 0; i < 2; i++) {
21269 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21270 input_attribs[i].location = i;
21271 }
21272
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021273 char const *vsSource =
21274 "#version 450\n"
21275 "\n"
21276 "layout(location=0) in mat2x4 x;\n"
21277 "out gl_PerVertex {\n"
21278 " vec4 gl_Position;\n"
21279 "};\n"
21280 "void main(){\n"
21281 " gl_Position = x[0] + x[1];\n"
21282 "}\n";
21283 char const *fsSource =
21284 "#version 450\n"
21285 "\n"
21286 "layout(location=0) out vec4 color;\n"
21287 "void main(){\n"
21288 " color = vec4(1);\n"
21289 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021290
21291 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21292 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21293
21294 VkPipelineObj pipe(m_device);
21295 pipe.AddColorAttachment();
21296 pipe.AddShader(&vs);
21297 pipe.AddShader(&fs);
21298
21299 pipe.AddVertexInputBindings(&input_binding, 1);
21300 pipe.AddVertexInputAttribs(input_attribs, 2);
21301
21302 VkDescriptorSetObj descriptorSet(m_device);
21303 descriptorSet.AppendDummy();
21304 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21305
21306 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21307
21308 /* expect success */
21309 m_errorMonitor->VerifyNotFound();
21310}
21311
21312TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21313 m_errorMonitor->ExpectSuccess();
21314
21315 ASSERT_NO_FATAL_FAILURE(InitState());
21316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21317
21318 VkVertexInputBindingDescription input_binding;
21319 memset(&input_binding, 0, sizeof(input_binding));
21320
21321 VkVertexInputAttributeDescription input_attribs[2];
21322 memset(input_attribs, 0, sizeof(input_attribs));
21323
21324 for (int i = 0; i < 2; i++) {
21325 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21326 input_attribs[i].location = i;
21327 }
21328
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021329 char const *vsSource =
21330 "#version 450\n"
21331 "\n"
21332 "layout(location=0) in vec4 x[2];\n"
21333 "out gl_PerVertex {\n"
21334 " vec4 gl_Position;\n"
21335 "};\n"
21336 "void main(){\n"
21337 " gl_Position = x[0] + x[1];\n"
21338 "}\n";
21339 char const *fsSource =
21340 "#version 450\n"
21341 "\n"
21342 "layout(location=0) out vec4 color;\n"
21343 "void main(){\n"
21344 " color = vec4(1);\n"
21345 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021346
21347 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21348 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21349
21350 VkPipelineObj pipe(m_device);
21351 pipe.AddColorAttachment();
21352 pipe.AddShader(&vs);
21353 pipe.AddShader(&fs);
21354
21355 pipe.AddVertexInputBindings(&input_binding, 1);
21356 pipe.AddVertexInputAttribs(input_attribs, 2);
21357
21358 VkDescriptorSetObj descriptorSet(m_device);
21359 descriptorSet.AppendDummy();
21360 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21361
21362 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21363
21364 m_errorMonitor->VerifyNotFound();
21365}
21366
21367TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021368 TEST_DESCRIPTION(
21369 "Test that pipeline validation accepts consuming a vertex attribute "
21370 "through multiple vertex shader inputs, each consuming a different "
21371 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021372 m_errorMonitor->ExpectSuccess();
21373
21374 ASSERT_NO_FATAL_FAILURE(InitState());
21375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21376
21377 VkVertexInputBindingDescription input_binding;
21378 memset(&input_binding, 0, sizeof(input_binding));
21379
21380 VkVertexInputAttributeDescription input_attribs[3];
21381 memset(input_attribs, 0, sizeof(input_attribs));
21382
21383 for (int i = 0; i < 3; i++) {
21384 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21385 input_attribs[i].location = i;
21386 }
21387
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021388 char const *vsSource =
21389 "#version 450\n"
21390 "\n"
21391 "layout(location=0) in vec4 x;\n"
21392 "layout(location=1) in vec3 y1;\n"
21393 "layout(location=1, component=3) in float y2;\n"
21394 "layout(location=2) in vec4 z;\n"
21395 "out gl_PerVertex {\n"
21396 " vec4 gl_Position;\n"
21397 "};\n"
21398 "void main(){\n"
21399 " gl_Position = x + vec4(y1, y2) + z;\n"
21400 "}\n";
21401 char const *fsSource =
21402 "#version 450\n"
21403 "\n"
21404 "layout(location=0) out vec4 color;\n"
21405 "void main(){\n"
21406 " color = vec4(1);\n"
21407 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021408
21409 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21410 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21411
21412 VkPipelineObj pipe(m_device);
21413 pipe.AddColorAttachment();
21414 pipe.AddShader(&vs);
21415 pipe.AddShader(&fs);
21416
21417 pipe.AddVertexInputBindings(&input_binding, 1);
21418 pipe.AddVertexInputAttribs(input_attribs, 3);
21419
21420 VkDescriptorSetObj descriptorSet(m_device);
21421 descriptorSet.AppendDummy();
21422 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21423
21424 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21425
21426 m_errorMonitor->VerifyNotFound();
21427}
21428
21429TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21430 m_errorMonitor->ExpectSuccess();
21431
21432 ASSERT_NO_FATAL_FAILURE(InitState());
21433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21434
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021435 char const *vsSource =
21436 "#version 450\n"
21437 "out gl_PerVertex {\n"
21438 " vec4 gl_Position;\n"
21439 "};\n"
21440 "void main(){\n"
21441 " gl_Position = vec4(0);\n"
21442 "}\n";
21443 char const *fsSource =
21444 "#version 450\n"
21445 "\n"
21446 "layout(location=0) out vec4 color;\n"
21447 "void main(){\n"
21448 " color = vec4(1);\n"
21449 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021450
21451 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21452 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21453
21454 VkPipelineObj pipe(m_device);
21455 pipe.AddColorAttachment();
21456 pipe.AddShader(&vs);
21457 pipe.AddShader(&fs);
21458
21459 VkDescriptorSetObj descriptorSet(m_device);
21460 descriptorSet.AppendDummy();
21461 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21462
21463 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21464
21465 m_errorMonitor->VerifyNotFound();
21466}
21467
21468TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021469 TEST_DESCRIPTION(
21470 "Test that pipeline validation accepts the relaxed type matching rules "
21471 "set out in 14.1.3: fundamental type must match, and producer side must "
21472 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021473 m_errorMonitor->ExpectSuccess();
21474
21475 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21476
21477 ASSERT_NO_FATAL_FAILURE(InitState());
21478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21479
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021480 char const *vsSource =
21481 "#version 450\n"
21482 "out gl_PerVertex {\n"
21483 " vec4 gl_Position;\n"
21484 "};\n"
21485 "layout(location=0) out vec3 x;\n"
21486 "layout(location=1) out ivec3 y;\n"
21487 "layout(location=2) out vec3 z;\n"
21488 "void main(){\n"
21489 " gl_Position = vec4(0);\n"
21490 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21491 "}\n";
21492 char const *fsSource =
21493 "#version 450\n"
21494 "\n"
21495 "layout(location=0) out vec4 color;\n"
21496 "layout(location=0) in float x;\n"
21497 "layout(location=1) flat in int y;\n"
21498 "layout(location=2) in vec2 z;\n"
21499 "void main(){\n"
21500 " color = vec4(1 + x + y + z.x);\n"
21501 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021502
21503 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21504 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21505
21506 VkPipelineObj pipe(m_device);
21507 pipe.AddColorAttachment();
21508 pipe.AddShader(&vs);
21509 pipe.AddShader(&fs);
21510
21511 VkDescriptorSetObj descriptorSet(m_device);
21512 descriptorSet.AppendDummy();
21513 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21514
21515 VkResult err = VK_SUCCESS;
21516 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21517 ASSERT_VK_SUCCESS(err);
21518
21519 m_errorMonitor->VerifyNotFound();
21520}
21521
21522TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021523 TEST_DESCRIPTION(
21524 "Test that pipeline validation accepts per-vertex variables "
21525 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021526 m_errorMonitor->ExpectSuccess();
21527
21528 ASSERT_NO_FATAL_FAILURE(InitState());
21529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21530
21531 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021532 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021533 return;
21534 }
21535
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021536 char const *vsSource =
21537 "#version 450\n"
21538 "void main(){}\n";
21539 char const *tcsSource =
21540 "#version 450\n"
21541 "layout(location=0) out int x[];\n"
21542 "layout(vertices=3) out;\n"
21543 "void main(){\n"
21544 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21545 " gl_TessLevelInner[0] = 1;\n"
21546 " x[gl_InvocationID] = gl_InvocationID;\n"
21547 "}\n";
21548 char const *tesSource =
21549 "#version 450\n"
21550 "layout(triangles, equal_spacing, cw) in;\n"
21551 "layout(location=0) in int x[];\n"
21552 "out gl_PerVertex { vec4 gl_Position; };\n"
21553 "void main(){\n"
21554 " gl_Position.xyz = gl_TessCoord;\n"
21555 " gl_Position.w = x[0] + x[1] + x[2];\n"
21556 "}\n";
21557 char const *fsSource =
21558 "#version 450\n"
21559 "layout(location=0) out vec4 color;\n"
21560 "void main(){\n"
21561 " color = vec4(1);\n"
21562 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021563
21564 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21565 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21566 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21567 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21568
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021569 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21570 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021571
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021572 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021573
21574 VkPipelineObj pipe(m_device);
21575 pipe.SetInputAssembly(&iasci);
21576 pipe.SetTessellation(&tsci);
21577 pipe.AddColorAttachment();
21578 pipe.AddShader(&vs);
21579 pipe.AddShader(&tcs);
21580 pipe.AddShader(&tes);
21581 pipe.AddShader(&fs);
21582
21583 VkDescriptorSetObj descriptorSet(m_device);
21584 descriptorSet.AppendDummy();
21585 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21586
21587 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21588
21589 m_errorMonitor->VerifyNotFound();
21590}
21591
21592TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021593 TEST_DESCRIPTION(
21594 "Test that pipeline validation accepts a user-defined "
21595 "interface block passed into the geometry shader. This "
21596 "is interesting because the 'extra' array level is not "
21597 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021598 m_errorMonitor->ExpectSuccess();
21599
21600 ASSERT_NO_FATAL_FAILURE(InitState());
21601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21602
21603 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021604 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021605 return;
21606 }
21607
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021608 char const *vsSource =
21609 "#version 450\n"
21610 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21611 "void main(){\n"
21612 " vs_out.x = vec4(1);\n"
21613 "}\n";
21614 char const *gsSource =
21615 "#version 450\n"
21616 "layout(triangles) in;\n"
21617 "layout(triangle_strip, max_vertices=3) out;\n"
21618 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21619 "out gl_PerVertex { vec4 gl_Position; };\n"
21620 "void main() {\n"
21621 " gl_Position = gs_in[0].x;\n"
21622 " EmitVertex();\n"
21623 "}\n";
21624 char const *fsSource =
21625 "#version 450\n"
21626 "layout(location=0) out vec4 color;\n"
21627 "void main(){\n"
21628 " color = vec4(1);\n"
21629 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021630
21631 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21632 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21633 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21634
21635 VkPipelineObj pipe(m_device);
21636 pipe.AddColorAttachment();
21637 pipe.AddShader(&vs);
21638 pipe.AddShader(&gs);
21639 pipe.AddShader(&fs);
21640
21641 VkDescriptorSetObj descriptorSet(m_device);
21642 descriptorSet.AppendDummy();
21643 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21644
21645 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21646
21647 m_errorMonitor->VerifyNotFound();
21648}
21649
21650TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021651 TEST_DESCRIPTION(
21652 "Test that pipeline validation accepts basic use of 64bit vertex "
21653 "attributes. This is interesting because they consume multiple "
21654 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021655 m_errorMonitor->ExpectSuccess();
21656
21657 ASSERT_NO_FATAL_FAILURE(InitState());
21658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21659
21660 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021661 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021662 return;
21663 }
21664
21665 VkVertexInputBindingDescription input_bindings[1];
21666 memset(input_bindings, 0, sizeof(input_bindings));
21667
21668 VkVertexInputAttributeDescription input_attribs[4];
21669 memset(input_attribs, 0, sizeof(input_attribs));
21670 input_attribs[0].location = 0;
21671 input_attribs[0].offset = 0;
21672 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21673 input_attribs[1].location = 2;
21674 input_attribs[1].offset = 32;
21675 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21676 input_attribs[2].location = 4;
21677 input_attribs[2].offset = 64;
21678 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21679 input_attribs[3].location = 6;
21680 input_attribs[3].offset = 96;
21681 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21682
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021683 char const *vsSource =
21684 "#version 450\n"
21685 "\n"
21686 "layout(location=0) in dmat4 x;\n"
21687 "out gl_PerVertex {\n"
21688 " vec4 gl_Position;\n"
21689 "};\n"
21690 "void main(){\n"
21691 " gl_Position = vec4(x[0][0]);\n"
21692 "}\n";
21693 char const *fsSource =
21694 "#version 450\n"
21695 "\n"
21696 "layout(location=0) out vec4 color;\n"
21697 "void main(){\n"
21698 " color = vec4(1);\n"
21699 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021700
21701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21703
21704 VkPipelineObj pipe(m_device);
21705 pipe.AddColorAttachment();
21706 pipe.AddShader(&vs);
21707 pipe.AddShader(&fs);
21708
21709 pipe.AddVertexInputBindings(input_bindings, 1);
21710 pipe.AddVertexInputAttribs(input_attribs, 4);
21711
21712 VkDescriptorSetObj descriptorSet(m_device);
21713 descriptorSet.AppendDummy();
21714 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21715
21716 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21717
21718 m_errorMonitor->VerifyNotFound();
21719}
21720
21721TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21722 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21723 m_errorMonitor->ExpectSuccess();
21724
21725 ASSERT_NO_FATAL_FAILURE(InitState());
21726
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021727 char const *vsSource =
21728 "#version 450\n"
21729 "\n"
21730 "out gl_PerVertex {\n"
21731 " vec4 gl_Position;\n"
21732 "};\n"
21733 "void main(){\n"
21734 " gl_Position = vec4(1);\n"
21735 "}\n";
21736 char const *fsSource =
21737 "#version 450\n"
21738 "\n"
21739 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21740 "layout(location=0) out vec4 color;\n"
21741 "void main() {\n"
21742 " color = subpassLoad(x);\n"
21743 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021744
21745 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21746 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21747
21748 VkPipelineObj pipe(m_device);
21749 pipe.AddShader(&vs);
21750 pipe.AddShader(&fs);
21751 pipe.AddColorAttachment();
21752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21753
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021754 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21755 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021756 VkDescriptorSetLayout dsl;
21757 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21758 ASSERT_VK_SUCCESS(err);
21759
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021760 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021761 VkPipelineLayout pl;
21762 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21763 ASSERT_VK_SUCCESS(err);
21764
21765 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021766 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21767 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21768 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21769 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21770 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 -060021771 };
21772 VkAttachmentReference color = {
21773 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21774 };
21775 VkAttachmentReference input = {
21776 1, VK_IMAGE_LAYOUT_GENERAL,
21777 };
21778
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021779 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021780
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021781 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021782 VkRenderPass rp;
21783 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21784 ASSERT_VK_SUCCESS(err);
21785
21786 // should be OK. would go wrong here if it's going to...
21787 pipe.CreateVKPipeline(pl, rp);
21788
21789 m_errorMonitor->VerifyNotFound();
21790
21791 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21792 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21793 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21794}
21795
21796TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021797 TEST_DESCRIPTION(
21798 "Test that pipeline validation accepts a compute pipeline which declares a "
21799 "descriptor-backed resource which is not provided, but the shader does not "
21800 "statically use it. This is interesting because it requires compute pipelines "
21801 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021802 m_errorMonitor->ExpectSuccess();
21803
21804 ASSERT_NO_FATAL_FAILURE(InitState());
21805
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021806 char const *csSource =
21807 "#version 450\n"
21808 "\n"
21809 "layout(local_size_x=1) in;\n"
21810 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21811 "void main(){\n"
21812 " // x is not used.\n"
21813 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021814
21815 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21816
21817 VkDescriptorSetObj descriptorSet(m_device);
21818 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21819
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021820 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21821 nullptr,
21822 0,
21823 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21824 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21825 descriptorSet.GetPipelineLayout(),
21826 VK_NULL_HANDLE,
21827 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021828
21829 VkPipeline pipe;
21830 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21831
21832 m_errorMonitor->VerifyNotFound();
21833
21834 if (err == VK_SUCCESS) {
21835 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21836 }
21837}
21838
21839TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021840 TEST_DESCRIPTION(
21841 "Test that pipeline validation accepts a shader consuming only the "
21842 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021843 m_errorMonitor->ExpectSuccess();
21844
21845 ASSERT_NO_FATAL_FAILURE(InitState());
21846
21847 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021848 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21849 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21850 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021851 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021852 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021853 VkDescriptorSetLayout dsl;
21854 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21855 ASSERT_VK_SUCCESS(err);
21856
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021857 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021858 VkPipelineLayout pl;
21859 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21860 ASSERT_VK_SUCCESS(err);
21861
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021862 char const *csSource =
21863 "#version 450\n"
21864 "\n"
21865 "layout(local_size_x=1) in;\n"
21866 "layout(set=0, binding=0) uniform sampler s;\n"
21867 "layout(set=0, binding=1) uniform texture2D t;\n"
21868 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21869 "void main() {\n"
21870 " x = texture(sampler2D(t, s), vec2(0));\n"
21871 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021872 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21873
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021874 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21875 nullptr,
21876 0,
21877 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21878 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21879 pl,
21880 VK_NULL_HANDLE,
21881 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021882
21883 VkPipeline pipe;
21884 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21885
21886 m_errorMonitor->VerifyNotFound();
21887
21888 if (err == VK_SUCCESS) {
21889 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21890 }
21891
21892 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21893 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21894}
21895
21896TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021897 TEST_DESCRIPTION(
21898 "Test that pipeline validation accepts a shader consuming only the "
21899 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021900 m_errorMonitor->ExpectSuccess();
21901
21902 ASSERT_NO_FATAL_FAILURE(InitState());
21903
21904 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021905 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21906 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21907 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021908 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021909 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021910 VkDescriptorSetLayout dsl;
21911 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21912 ASSERT_VK_SUCCESS(err);
21913
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021914 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021915 VkPipelineLayout pl;
21916 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21917 ASSERT_VK_SUCCESS(err);
21918
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021919 char const *csSource =
21920 "#version 450\n"
21921 "\n"
21922 "layout(local_size_x=1) in;\n"
21923 "layout(set=0, binding=0) uniform texture2D t;\n"
21924 "layout(set=0, binding=1) uniform sampler s;\n"
21925 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21926 "void main() {\n"
21927 " x = texture(sampler2D(t, s), vec2(0));\n"
21928 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021929 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21930
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021931 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21932 nullptr,
21933 0,
21934 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21935 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21936 pl,
21937 VK_NULL_HANDLE,
21938 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021939
21940 VkPipeline pipe;
21941 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21942
21943 m_errorMonitor->VerifyNotFound();
21944
21945 if (err == VK_SUCCESS) {
21946 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21947 }
21948
21949 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21950 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21951}
21952
21953TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021954 TEST_DESCRIPTION(
21955 "Test that pipeline validation accepts a shader consuming "
21956 "both the sampler and the image of a combined image+sampler "
21957 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021958 m_errorMonitor->ExpectSuccess();
21959
21960 ASSERT_NO_FATAL_FAILURE(InitState());
21961
21962 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021963 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21964 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021965 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021966 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021967 VkDescriptorSetLayout dsl;
21968 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21969 ASSERT_VK_SUCCESS(err);
21970
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021971 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021972 VkPipelineLayout pl;
21973 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21974 ASSERT_VK_SUCCESS(err);
21975
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021976 char const *csSource =
21977 "#version 450\n"
21978 "\n"
21979 "layout(local_size_x=1) in;\n"
21980 "layout(set=0, binding=0) uniform texture2D t;\n"
21981 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
21982 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
21983 "void main() {\n"
21984 " x = texture(sampler2D(t, s), vec2(0));\n"
21985 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021986 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21987
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021988 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21989 nullptr,
21990 0,
21991 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21992 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21993 pl,
21994 VK_NULL_HANDLE,
21995 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021996
21997 VkPipeline pipe;
21998 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21999
22000 m_errorMonitor->VerifyNotFound();
22001
22002 if (err == VK_SUCCESS) {
22003 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22004 }
22005
22006 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22007 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22008}
22009
22010TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22011 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22012
22013 ASSERT_NO_FATAL_FAILURE(InitState());
22014
22015 // Positive test to check parameter_validation and unique_objects support
22016 // for NV_dedicated_allocation
22017 uint32_t extension_count = 0;
22018 bool supports_nv_dedicated_allocation = false;
22019 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22020 ASSERT_VK_SUCCESS(err);
22021
22022 if (extension_count > 0) {
22023 std::vector<VkExtensionProperties> available_extensions(extension_count);
22024
22025 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22026 ASSERT_VK_SUCCESS(err);
22027
22028 for (const auto &extension_props : available_extensions) {
22029 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22030 supports_nv_dedicated_allocation = true;
22031 }
22032 }
22033 }
22034
22035 if (supports_nv_dedicated_allocation) {
22036 m_errorMonitor->ExpectSuccess();
22037
22038 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22039 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22040 dedicated_buffer_create_info.pNext = nullptr;
22041 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22042
22043 uint32_t queue_family_index = 0;
22044 VkBufferCreateInfo buffer_create_info = {};
22045 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22046 buffer_create_info.pNext = &dedicated_buffer_create_info;
22047 buffer_create_info.size = 1024;
22048 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22049 buffer_create_info.queueFamilyIndexCount = 1;
22050 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22051
22052 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022053 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022054 ASSERT_VK_SUCCESS(err);
22055
22056 VkMemoryRequirements memory_reqs;
22057 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22058
22059 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22060 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22061 dedicated_memory_info.pNext = nullptr;
22062 dedicated_memory_info.buffer = buffer;
22063 dedicated_memory_info.image = VK_NULL_HANDLE;
22064
22065 VkMemoryAllocateInfo memory_info = {};
22066 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22067 memory_info.pNext = &dedicated_memory_info;
22068 memory_info.allocationSize = memory_reqs.size;
22069
22070 bool pass;
22071 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22072 ASSERT_TRUE(pass);
22073
22074 VkDeviceMemory buffer_memory;
22075 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22076 ASSERT_VK_SUCCESS(err);
22077
22078 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22079 ASSERT_VK_SUCCESS(err);
22080
22081 vkDestroyBuffer(m_device->device(), buffer, NULL);
22082 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22083
22084 m_errorMonitor->VerifyNotFound();
22085 }
22086}
22087
22088TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22089 VkResult err;
22090
22091 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22092
22093 ASSERT_NO_FATAL_FAILURE(InitState());
22094 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22095
22096 std::vector<const char *> device_extension_names;
22097 auto features = m_device->phy().features();
22098 // Artificially disable support for non-solid fill modes
22099 features.fillModeNonSolid = false;
22100 // The sacrificial device object
22101 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22102
22103 VkRenderpassObj render_pass(&test_device);
22104
22105 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22106 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22107 pipeline_layout_ci.setLayoutCount = 0;
22108 pipeline_layout_ci.pSetLayouts = NULL;
22109
22110 VkPipelineLayout pipeline_layout;
22111 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22112 ASSERT_VK_SUCCESS(err);
22113
22114 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22115 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22116 rs_ci.pNext = nullptr;
22117 rs_ci.lineWidth = 1.0f;
22118 rs_ci.rasterizerDiscardEnable = true;
22119
22120 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22121 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22122
22123 // Set polygonMode=FILL. No error is expected
22124 m_errorMonitor->ExpectSuccess();
22125 {
22126 VkPipelineObj pipe(&test_device);
22127 pipe.AddShader(&vs);
22128 pipe.AddShader(&fs);
22129 pipe.AddColorAttachment();
22130 // Set polygonMode to a good value
22131 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22132 pipe.SetRasterization(&rs_ci);
22133 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22134 }
22135 m_errorMonitor->VerifyNotFound();
22136
22137 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22138}
22139
22140TEST_F(VkPositiveLayerTest, ValidPushConstants) {
22141 VkResult err;
22142 ASSERT_NO_FATAL_FAILURE(InitState());
22143 ASSERT_NO_FATAL_FAILURE(InitViewport());
22144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22145
22146 VkPipelineLayout pipeline_layout;
22147 VkPushConstantRange pc_range = {};
22148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22150 pipeline_layout_ci.pushConstantRangeCount = 1;
22151 pipeline_layout_ci.pPushConstantRanges = &pc_range;
22152
22153 //
22154 // Check for invalid push constant ranges in pipeline layouts.
22155 //
22156 struct PipelineLayoutTestCase {
22157 VkPushConstantRange const range;
22158 char const *msg;
22159 };
22160
22161 // Check for overlapping ranges
22162 const uint32_t ranges_per_test = 5;
22163 struct OverlappingRangeTestCase {
22164 VkPushConstantRange const ranges[ranges_per_test];
22165 char const *msg;
22166 };
22167
22168 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022169 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
22170 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
22171 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
22172 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
22173 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
22174 ""},
22175 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
22176 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
22177 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
22178 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
22179 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
22180 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022181 for (const auto &iter : overlapping_range_tests_pos) {
22182 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
22183 m_errorMonitor->ExpectSuccess();
22184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22185 m_errorMonitor->VerifyNotFound();
22186 if (VK_SUCCESS == err) {
22187 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22188 }
22189 }
22190
22191 //
22192 // CmdPushConstants tests
22193 //
22194 const uint8_t dummy_values[100] = {};
22195
Tony Barbour552f6c02016-12-21 14:34:07 -070022196 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022197
22198 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022199 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
22200 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
22201 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
22202 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
22203 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
22204 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022205
22206 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
22207 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022208 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
22209 {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 -060022210 };
22211
22212 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
22213 pipeline_layout_ci.pPushConstantRanges = pc_range4;
22214 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22215 ASSERT_VK_SUCCESS(err);
22216 for (const auto &iter : cmd_overlap_tests_pos) {
22217 m_errorMonitor->ExpectSuccess();
22218 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022219 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022220 m_errorMonitor->VerifyNotFound();
22221 }
22222 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22223
Tony Barbour552f6c02016-12-21 14:34:07 -070022224 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022225}
22226
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022227#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022228TEST_F(VkPositiveLayerTest, LongFenceChain)
22229{
22230 m_errorMonitor->ExpectSuccess();
22231
22232 ASSERT_NO_FATAL_FAILURE(InitState());
22233 VkResult err;
22234
22235 std::vector<VkFence> fences;
22236
22237 const int chainLength = 32768;
22238
22239 for (int i = 0; i < chainLength; i++) {
22240 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22241 VkFence fence;
22242 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22243 ASSERT_VK_SUCCESS(err);
22244
22245 fences.push_back(fence);
22246
22247 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22248 0, nullptr, 0, nullptr };
22249 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22250 ASSERT_VK_SUCCESS(err);
22251
22252 }
22253
22254 // BOOM, stack overflow.
22255 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22256
22257 for (auto fence : fences)
22258 vkDestroyFence(m_device->device(), fence, nullptr);
22259
22260 m_errorMonitor->VerifyNotFound();
22261}
22262#endif
22263
Cody Northrop1242dfd2016-07-13 17:24:59 -060022264#if defined(ANDROID) && defined(VALIDATION_APK)
22265static bool initialized = false;
22266static bool active = false;
22267
22268// Convert Intents to argv
22269// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022270std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022271 std::vector<std::string> args;
22272 JavaVM &vm = *app.activity->vm;
22273 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022274 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022275
22276 JNIEnv &env = *p_env;
22277 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022278 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022279 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022280 jmethodID get_string_extra_method =
22281 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022282 jvalue get_string_extra_args;
22283 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022284 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022285
22286 std::string args_str;
22287 if (extra_str) {
22288 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22289 args_str = extra_utf;
22290 env.ReleaseStringUTFChars(extra_str, extra_utf);
22291 env.DeleteLocalRef(extra_str);
22292 }
22293
22294 env.DeleteLocalRef(get_string_extra_args.l);
22295 env.DeleteLocalRef(intent);
22296 vm.DetachCurrentThread();
22297
22298 // split args_str
22299 std::stringstream ss(args_str);
22300 std::string arg;
22301 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022302 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022303 }
22304
22305 return args;
22306}
22307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022308static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022310static void processCommand(struct android_app *app, int32_t cmd) {
22311 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022312 case APP_CMD_INIT_WINDOW: {
22313 if (app->window) {
22314 initialized = true;
22315 }
22316 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022317 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022318 case APP_CMD_GAINED_FOCUS: {
22319 active = true;
22320 break;
22321 }
22322 case APP_CMD_LOST_FOCUS: {
22323 active = false;
22324 break;
22325 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022326 }
22327}
22328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022329void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022330 app_dummy();
22331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022332 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022333
22334 int vulkanSupport = InitVulkan();
22335 if (vulkanSupport == 0) {
22336 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22337 return;
22338 }
22339
22340 app->onAppCmd = processCommand;
22341 app->onInputEvent = processInput;
22342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022343 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022344 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022345 struct android_poll_source *source;
22346 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022347 if (source) {
22348 source->process(app, source);
22349 }
22350
22351 if (app->destroyRequested != 0) {
22352 VkTestFramework::Finish();
22353 return;
22354 }
22355 }
22356
22357 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022358 // Use the following key to send arguments to gtest, i.e.
22359 // --es args "--gtest_filter=-VkLayerTest.foo"
22360 const char key[] = "args";
22361 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022362
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022363 std::string filter = "";
22364 if (args.size() > 0) {
22365 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22366 filter += args[0];
22367 } else {
22368 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22369 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022371 int argc = 2;
22372 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22373 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022375 // Route output to files until we can override the gtest output
22376 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22377 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022379 ::testing::InitGoogleTest(&argc, argv);
22380 VkTestFramework::InitArgs(&argc, argv);
22381 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022383 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022385 if (result != 0) {
22386 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22387 } else {
22388 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22389 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022391 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022393 fclose(stdout);
22394 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022396 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022397 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022398 }
22399 }
22400}
22401#endif
22402
Tony Barbour300a6082015-04-07 13:44:53 -060022403int main(int argc, char **argv) {
22404 int result;
22405
Cody Northrop8e54a402016-03-08 22:25:52 -070022406#ifdef ANDROID
22407 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022408 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022409#endif
22410
Tony Barbour300a6082015-04-07 13:44:53 -060022411 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022412 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022413
22414 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22415
22416 result = RUN_ALL_TESTS();
22417
Tony Barbour6918cd52015-04-09 12:58:51 -060022418 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022419 return result;
22420}